mirror of
https://github.com/pratiktri/dotfiles.git
synced 2026-05-06 19:43:40 +05:30
fix(neovim): nvim-treesitter updates for neovim 0.12 & remove
nvim-ts-context-commentstring plugin
This commit is contained in:
@@ -210,18 +210,19 @@ return {
|
|||||||
-- Treesitter
|
-- Treesitter
|
||||||
{
|
{
|
||||||
"nvim-treesitter/nvim-treesitter",
|
"nvim-treesitter/nvim-treesitter",
|
||||||
|
branch = "main",
|
||||||
lazy = false,
|
lazy = false,
|
||||||
build = ":TSUpdate",
|
build = ":TSUpdate",
|
||||||
init = function(plugin)
|
init = function()
|
||||||
require("lazy.core.loader").add_to_rtp(plugin)
|
-- Disable the plugin's own vimscript runtime
|
||||||
require("nvim-treesitter.query_predicates")
|
vim.g.loaded_nvim_treesitter = 1
|
||||||
end,
|
end,
|
||||||
dependencies = { "nvim-treesitter/nvim-treesitter-textobjects" },
|
|
||||||
|
|
||||||
config = function()
|
config = function()
|
||||||
vim.defer_fn(function()
|
require("nvim-treesitter").setup({
|
||||||
require("nvim-treesitter.configs").setup({
|
auto_install = true,
|
||||||
ensure_installed = {
|
})
|
||||||
|
|
||||||
|
local parsers = {
|
||||||
"bash",
|
"bash",
|
||||||
"css",
|
"css",
|
||||||
"dockerfile",
|
"dockerfile",
|
||||||
@@ -229,7 +230,6 @@ return {
|
|||||||
"html",
|
"html",
|
||||||
"javascript",
|
"javascript",
|
||||||
"json5",
|
"json5",
|
||||||
"jsonc",
|
|
||||||
"lua",
|
"lua",
|
||||||
"markdown",
|
"markdown",
|
||||||
"markdown_inline",
|
"markdown_inline",
|
||||||
@@ -243,25 +243,65 @@ return {
|
|||||||
"typescript",
|
"typescript",
|
||||||
"vue",
|
"vue",
|
||||||
"yaml",
|
"yaml",
|
||||||
|
}
|
||||||
|
|
||||||
|
local installed = require("nvim-treesitter").get_installed()
|
||||||
|
local to_install = vim.tbl_filter(function(p)
|
||||||
|
return not vim.tbl_contains(installed, p)
|
||||||
|
end, parsers)
|
||||||
|
|
||||||
|
if #to_install > 0 then
|
||||||
|
require("nvim-treesitter.install").install(to_install)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Auto-install when opening a new filetype
|
||||||
|
vim.api.nvim_create_autocmd("FileType", {
|
||||||
|
group = vim.api.nvim_create_augroup("TSAutoInstall", { clear = true }),
|
||||||
|
callback = function(args)
|
||||||
|
local lang = vim.treesitter.language.get_lang(vim.bo[args.buf].filetype)
|
||||||
|
if not lang then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local ok = pcall(vim.treesitter.language.inspect, lang)
|
||||||
|
if not ok then
|
||||||
|
-- Parser not installed yet, install it
|
||||||
|
require("nvim-treesitter.install").install({ lang })
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
-- FileType autocmd: wire up highlight + indent for every treesitter-capable buffer
|
||||||
|
vim.api.nvim_create_autocmd("FileType", {
|
||||||
|
group = vim.api.nvim_create_augroup("TSEnable", { clear = true }),
|
||||||
|
callback = function(args)
|
||||||
|
local buf = args.buf
|
||||||
|
-- start() returns false if no parser is available, pcall catches missing parsers
|
||||||
|
if pcall(vim.treesitter.start, buf) then
|
||||||
|
-- Treesitter-based indentation
|
||||||
|
vim.bo[buf].indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Incremental selection is NATIVE in 0.12 (no plugin config)
|
||||||
|
-- 0.12 defaults: gnn (init), grn (expand node), grm (shrink), grc (scope)
|
||||||
|
-- Remap to your existing keys:
|
||||||
|
vim.keymap.set("n", "<C-space>", "gnn", { remap = true, desc = "Init treesitter selection" })
|
||||||
|
vim.keymap.set("x", "<C-CR>", "grc", { remap = true, desc = "Expand scope selection" })
|
||||||
|
vim.keymap.set("x", "<bs>", "grm", { remap = true, desc = "Shrink node selection" })
|
||||||
|
end,
|
||||||
},
|
},
|
||||||
|
|
||||||
auto_install = true,
|
{
|
||||||
indent = { enable = true },
|
"nvim-treesitter/nvim-treesitter-textobjects",
|
||||||
|
branch = "main",
|
||||||
incremental_selection = {
|
dependencies = { "nvim-treesitter/nvim-treesitter" },
|
||||||
enable = true,
|
config = function()
|
||||||
keymaps = {
|
require("nvim-treesitter-textobjects").setup({
|
||||||
init_selection = "<C-space>",
|
|
||||||
node_incremental = "<C-space>",
|
|
||||||
scope_incremental = "<C-CR>",
|
|
||||||
node_decremental = "<bs>",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
textobjects = {
|
|
||||||
select = {
|
select = {
|
||||||
enable = true,
|
enable = true,
|
||||||
lookahead = true, -- Automatically jump forward to textobj
|
lookahead = true,
|
||||||
keymaps = {
|
keymaps = {
|
||||||
["aa"] = { query = "@parameter.outer", desc = "Select around the parameter" },
|
["aa"] = { query = "@parameter.outer", desc = "Select around the parameter" },
|
||||||
["ia"] = { query = "@parameter.inner", desc = "Select inside the parameter" },
|
["ia"] = { query = "@parameter.inner", desc = "Select inside the parameter" },
|
||||||
@@ -269,48 +309,40 @@ return {
|
|||||||
["if"] = { query = "@function.inner", desc = "Select inside of the function" },
|
["if"] = { query = "@function.inner", desc = "Select inside of the function" },
|
||||||
["ac"] = { query = "@class.outer", desc = "Select around the class" },
|
["ac"] = { query = "@class.outer", desc = "Select around the class" },
|
||||||
["ic"] = { query = "@class.inner", desc = "Select inside of the class" },
|
["ic"] = { query = "@class.inner", desc = "Select inside of the class" },
|
||||||
|
|
||||||
["al"] = { query = "@loop.outer", desc = "Select around the loop" },
|
["al"] = { query = "@loop.outer", desc = "Select around the loop" },
|
||||||
["il"] = { query = "@loop.inner", desc = "Select inside of the loop" },
|
["il"] = { query = "@loop.inner", desc = "Select inside of the loop" },
|
||||||
["as"] = { query = "@scope", query_group = "locals", desc = "Select around the scope" },
|
["as"] = { query = "@scope", query_group = "locals", desc = "Select around the scope" },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
move = {
|
move = {
|
||||||
-- Jump to next and previous text objects
|
|
||||||
-- ]a -> next argument
|
|
||||||
-- ]T -> next test
|
|
||||||
enable = true,
|
enable = true,
|
||||||
goto_next_start = {
|
goto_next_start = {
|
||||||
["]f"] = { query = "@function.outer", desc = "Goto next inner function start" },
|
["]f"] = { query = "@function.outer", desc = "Goto next function start" },
|
||||||
["]o"] = { query = "@loop.*", desc = "Goto next loop start" },
|
["]o"] = { query = "@loop.*", desc = "Goto next loop start" },
|
||||||
["]a"] = { query = "@parameter.inner", desc = "Goto next parameter" },
|
["]a"] = { query = "@parameter.inner", desc = "Goto next parameter" },
|
||||||
},
|
},
|
||||||
goto_next_end = {
|
goto_next_end = {
|
||||||
["]F"] = { query = "@function.outer", desc = "Goto next outer function end" },
|
["]F"] = { query = "@function.outer", desc = "Goto next function end" },
|
||||||
["]C"] = { query = "@class.outer", desc = "Goto next outer class end" },
|
["]C"] = { query = "@class.outer", desc = "Goto next class end" },
|
||||||
["]O"] = { query = "@loop.*", desc = "Goto next loop end" },
|
["]O"] = { query = "@loop.*", desc = "Goto next loop end" },
|
||||||
},
|
},
|
||||||
goto_previous_start = {
|
goto_previous_start = {
|
||||||
["[f"] = { query = "@function.outer", desc = "Goto goto previous inner function start" },
|
["[f"] = { query = "@function.outer", desc = "Goto previous function start" },
|
||||||
["[o"] = { query = "@loop.*", desc = "Goto previous loop start" },
|
["[o"] = { query = "@loop.*", desc = "Goto previous loop start" },
|
||||||
["[a"] = { query = "@parameter.inner", desc = "Goto previous parameter" },
|
["[a"] = { query = "@parameter.inner", desc = "Goto previous parameter" },
|
||||||
},
|
},
|
||||||
goto_previous_end = {
|
goto_previous_end = {
|
||||||
["[F"] = { query = "@function.outer", desc = "Goto goto previous outer function start" },
|
["[F"] = { query = "@function.outer", desc = "Goto previous function end" },
|
||||||
["[C"] = { query = "@class.outer", desc = "Goto previous outer class start" },
|
["[C"] = { query = "@class.outer", desc = "Goto previous class end" },
|
||||||
["[O"] = { query = "@loop.*", desc = "Goto previous loop start" },
|
["[O"] = { query = "@loop.*", desc = "Goto previous loop end" },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
lsp_interop = {
|
lsp_interop = {
|
||||||
enable = true,
|
enable = true,
|
||||||
border = "none",
|
border = "none",
|
||||||
floating_preview_opts = {},
|
floating_preview_opts = {},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
})
|
})
|
||||||
end, 0)
|
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -172,19 +172,6 @@ return {
|
|||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
|
||||||
-- Intelligent commenting on JSX
|
|
||||||
{
|
|
||||||
"JoosepAlviste/nvim-ts-context-commentstring",
|
|
||||||
opts = {
|
|
||||||
options = {
|
|
||||||
enable_autocmd = false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
config = function()
|
|
||||||
vim.g.skip_ts_context_commentstring_module = true
|
|
||||||
end,
|
|
||||||
},
|
|
||||||
|
|
||||||
-- Highlight colors
|
-- Highlight colors
|
||||||
{
|
{
|
||||||
"brenoprata10/nvim-highlight-colors",
|
"brenoprata10/nvim-highlight-colors",
|
||||||
|
|||||||
Reference in New Issue
Block a user