diff --git a/.config/nvim/lua/config/lazy.lua b/.config/nvim/lua/config/lazy.lua index 3b445fad..aa743d3d 100644 --- a/.config/nvim/lua/config/lazy.lua +++ b/.config/nvim/lua/config/lazy.lua @@ -24,6 +24,7 @@ require("lazy").setup({ { import = "lazyvim.plugins.extras.linting.eslint" }, { import = "lazyvim.plugins.extras.formatting.prettier" }, -- { import = "lazyvim.plugins.extras.coding.copilot" }, + { import = "lazyvim.plugins.extras.util.dot" }, { import = "lazyvim.plugins.extras.lang.yaml" }, { import = "lazyvim.plugins.extras.coding.yanky" }, { import = "lazyvim.plugins.extras.util.project" }, diff --git a/.config/nvim/lua/plugins/treesitter.lua b/.config/nvim/lua/plugins/treesitter.lua index 7642a668..89645ee5 100644 --- a/.config/nvim/lua/plugins/treesitter.lua +++ b/.config/nvim/lua/plugins/treesitter.lua @@ -1,52 +1,141 @@ return { - { - "nvim-treesitter/nvim-treesitter", - opts = function(_, opts) - opts.autotag = { - enable = true, - } - - opts.endwise = { - enable = true, - } - - vim.list_extend(opts.ensure_installed, { - "arduino", - "diff", - "dart", - "css", - "c_sharp", - "comment", - "fish", - "git_config", - "git_rebase", - "gitattributes", - "gitcommit", - "gitignore", - "groovy", - "hjson", - "http", - "ini", - "luadoc", - "make", - "kotlin", - "julia", - "meson", - "perl", - "php", - "prisma", - "r", - "rasi", - "regex", - "ruby", - "sql", - "scss", - "slint", - "svelte", - "todotxt", - "vim", - "vue", - }) + { + "nvim-treesitter/nvim-treesitter", + version = false, -- last release is way too old and doesn't work on Windows + build = ":TSUpdate", + event = { "LazyFile", "VeryLazy" }, + dependencies = { + { + "nvim-treesitter/nvim-treesitter-textobjects", + config = function() + -- When in diff mode, we want to use the default + -- vim text objects c & C instead of the treesitter ones. + local move = require("nvim-treesitter.textobjects.move") ---@type table + local configs = require("nvim-treesitter.configs") + for name, fn in pairs(move) do + if name:find("goto") == 1 then + move[name] = function(q, ...) + if vim.wo.diff then + local config = configs.get_module("textobjects.move")[name] ---@type table + for key, query in pairs(config or {}) do + if q == query and key:find("[%]%[][cC]") then + vim.cmd("normal! " .. key) + return + end + end + end + return fn(q, ...) + end + end + end end, + }, }, + cmd = { "TSUpdateSync" }, + keys = { + { "", desc = "Increment selection" }, + { "", desc = "Decrement selection", mode = "x" }, + }, + ---@type TSConfig + ---@diagnostic disable-next-line: missing-fields + opts = { + autotag = { enable = true }, + endwise = { enable = true }, + highlight = { enable = true }, + indent = { enable = true }, + ensure_installed = { + "bash", + "c", + "diff", + "html", + "javascript", + "jsdoc", + "json", + "jsonc", + "lua", + "luadoc", + "luap", + "markdown", + "markdown_inline", + "python", + "query", + "regex", + "toml", + "tsx", + "typescript", + "vim", + "vimdoc", + "yaml", + "arduino", + "diff", + "dart", + "css", + "c_sharp", + "comment", + "fish", + "git_config", + "git_rebase", + "gitattributes", + "gitcommit", + "gitignore", + "groovy", + "hjson", + "http", + "ini", + "luadoc", + "make", + "kotlin", + "julia", + "meson", + "perl", + "php", + "prisma", + "r", + "rasi", + "regex", + "ruby", + "sql", + "scss", + "slint", + "svelte", + "todotxt", + "vim", + "vue", + "hypr", + }, + incremental_selection = { + enable = true, + keymaps = { + init_selection = "", + node_incremental = "", + scope_incremental = false, + node_decremental = "", + }, + }, + textobjects = { + move = { + enable = true, + goto_next_start = { ["]f"] = "@function.outer", ["]c"] = "@class.outer" }, + goto_next_end = { ["]F"] = "@function.outer", ["]C"] = "@class.outer" }, + goto_previous_start = { ["[f"] = "@function.outer", ["[c"] = "@class.outer" }, + goto_previous_end = { ["[F"] = "@function.outer", ["[C"] = "@class.outer" }, + }, + }, + }, + ---@param opts TSConfig + config = function(_, opts) + if type(opts.ensure_installed) == "table" then + ---@type table + local added = {} + opts.ensure_installed = vim.tbl_filter(function(lang) + if added[lang] then + return false + end + added[lang] = true + return true + end, opts.ensure_installed) + end + require("nvim-treesitter.configs").setup(opts) + end, + }, }