home: vim: migrate to new 'nvim-treesitter'

This commit is contained in:
Bruno BELANYI 2026-01-20 12:26:37 +00:00
parent 526f8bb6e2
commit d7d8f40a8f
2 changed files with 32 additions and 14 deletions

View file

@ -60,8 +60,8 @@ in
nvim-lspconfig # Easy LSP configuration
lsp-format-nvim # Simplified formatting configuration
none-ls-nvim # LSP integration for linters and formatters
nvim-treesitter-legacy.withAllGrammars # Better highlighting
nvim-treesitter-textobjects-legacy # More textobjects
nvim-treesitter.withAllGrammars # Better highlighting
nvim-treesitter-textobjects # More textobjects
plenary-nvim # 'null-ls', 'telescope' dependency
# Completion

View file

@ -1,4 +1,4 @@
local ts_config = require("nvim-treesitter.configs")
local treesitter = require("nvim-treesitter")
local ts_select = require("nvim-treesitter-textobjects.select")
local ts_move = require("nvim-treesitter-textobjects.move")
local utils = require("ambroisie.utils")
@ -52,17 +52,6 @@ local moves = {
{ "[]", goto_previous_end("@class.outer"), desc = "Previous class end" },
}
ts_config.setup({
highlight = {
enable = true,
-- Avoid duplicate highlighting
additional_vim_regex_highlighting = false,
},
indent = {
enable = true,
},
})
require("nvim-treesitter-textobjects").setup({
select = {
-- Jump to matching text objects
@ -73,3 +62,32 @@ require("nvim-treesitter-textobjects").setup({
set_jumps = true,
},
})
-- Automatically setup treesitter for supported filetypes
local function treesitter_try_attach(buf, language)
-- Try to load language
-- NOTE: the best way I found to check if a filetype has a grammar
if not vim.treesitter.language.add(language) then
return false
end
-- Syntax highlighting
vim.treesitter.start(buf, language)
-- Indentation
vim.bo.indentexpr = "v:lua.require('nvim-treesitter').indentexpr()"
return true
end
vim.api.nvim_create_autocmd("FileType", {
pattern = "*",
group = vim.api.nvim_create_augroup("treesitter_attach", { clear = true }),
callback = function(args)
local buf, filetype = args.buf, args.match
local language = vim.treesitter.language.get_lang(filetype)
if not language then
return
end
treesitter_try_attach(buf, language)
end,
})