Treesitter
Fold treesitters node in neovim
local fold_named_arg_func = function ()
local ts_utils = require('nvim-treesitter.ts_utils')
local winid = vim.fn.bufwinid(1)
local nuc = ts_utils.get_node_at_cursor(winid)
local cn = nuc
while cn ~= nil and cn:type() ~= "named_argument"
do
cn = cn:parent()
end
local start_row
local end_row
if cn ~=nil then
start_row, _, end_row, _ = cn:range()
vim.cmd(start_row + 1 .. "," .. end_row + 1 .. "fold")
end
end
vim.keymap.set('n', '<M-n>', function()
local fold_level = vim.fn.foldlevel('.')
local fold_closed = vim.fn.foldclosed('.')
if fold_level > 0 then
if fold_closed == -1 then
fold_named_arg_func()
else
vim.cmd("foldopen")
end
else
fold_named_arg_func()
end
end)
Highlight dart function calls in neovim
https://github.com/UserNobody14/tree-sitter-dart/commit/c689944d21957290e36d1cd2adfde59277524fb6
Made the following edit to highlights.scm file
and pasted in ~/.config/nvim/queries/dart/highlights.scm
:
Test that it works by opening this file
Building grammar files
After mods to the grammar.js
files, do:
Or if you want to try the result in neovim:
tree-sitter generate
tree-sitter build
nvim
:lua vim.treesitter.language.add('dart', { path = '/home/vector/development/tree-sitter-dart/dart.so' })
tree-sitter build
will generate .so
file that neovim needs.