home: vim: migrate to new 'nvim-treesitter'
This commit is contained in:
parent
526f8bb6e2
commit
d7d8f40a8f
2 changed files with 32 additions and 14 deletions
|
|
@ -60,8 +60,8 @@ in
|
||||||
nvim-lspconfig # Easy LSP configuration
|
nvim-lspconfig # Easy LSP configuration
|
||||||
lsp-format-nvim # Simplified formatting configuration
|
lsp-format-nvim # Simplified formatting configuration
|
||||||
none-ls-nvim # LSP integration for linters and formatters
|
none-ls-nvim # LSP integration for linters and formatters
|
||||||
nvim-treesitter-legacy.withAllGrammars # Better highlighting
|
nvim-treesitter.withAllGrammars # Better highlighting
|
||||||
nvim-treesitter-textobjects-legacy # More textobjects
|
nvim-treesitter-textobjects # More textobjects
|
||||||
plenary-nvim # 'null-ls', 'telescope' dependency
|
plenary-nvim # 'null-ls', 'telescope' dependency
|
||||||
|
|
||||||
# Completion
|
# Completion
|
||||||
|
|
|
||||||
|
|
@ -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_select = require("nvim-treesitter-textobjects.select")
|
||||||
local ts_move = require("nvim-treesitter-textobjects.move")
|
local ts_move = require("nvim-treesitter-textobjects.move")
|
||||||
local utils = require("ambroisie.utils")
|
local utils = require("ambroisie.utils")
|
||||||
|
|
@ -52,17 +52,6 @@ local moves = {
|
||||||
{ "[]", goto_previous_end("@class.outer"), desc = "Previous class end" },
|
{ "[]", 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({
|
require("nvim-treesitter-textobjects").setup({
|
||||||
select = {
|
select = {
|
||||||
-- Jump to matching text objects
|
-- Jump to matching text objects
|
||||||
|
|
@ -73,3 +62,32 @@ require("nvim-treesitter-textobjects").setup({
|
||||||
set_jumps = true,
|
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,
|
||||||
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue