nvim-treesitter / nvim-treesitter-context

Show code context
MIT License
2.5k stars 201 forks source link

C++ multiline Lambda use as context - similar to if? #466

Closed CapSel closed 4 months ago

CapSel commented 4 months ago

Description

C++ since 2011 has support for lambdas and I make heavy use of these. It would be nice if a line, or function where lambda was passed, was shown as a context - similar to if. Here is an example of lambda use with for_each: https://stackoverflow.com/questions/11502523/how-to-use-lambda-in-for-each

Lambdas have a list what and how they capture in [] then template specifier <> then parameters almost like normal function (...) then -> return type and then code block {...}.

examples of captures: [], [&], [=], [&var1,=var2]

Neovim version

0.10.0

Expected behavior

a line with for_each(... [](...) { is shown on top as another context node

Actual behavior

nothing is shown on top

Minimal config

local plugins = {
  ts         = 'https://github.com/nvim-treesitter/nvim-treesitter',
  ts_context = 'https://github.com/nvim-treesitter/nvim-treesitter-context',
  -- ADD ADDITIONAL PLUGINS THAT ARE _NECESSARY_ TO REPRODUCE THE ISSUE
}

for name, url in pairs(plugins) do
  local install_path = '/tmp/nvim/site/'..name
  if vim.fn.isdirectory(install_path) == 0 then
    vim.fn.system { 'git', 'clone', '--depth=1', url, install_path }
  end
  vim.o.runtimepath = install_path..','..vim.o.runtimepath
end

-- ADD INIT.LUA SETTINGS THAT IS _NECESSARY_ FOR REPRODUCING THE ISSUE

Steps to reproduce

  1. edit C++ file with long contents in lambda
lewis6991 commented 4 months ago

Changes for specific languages are community maintained. A PR will be accepted.