diff --git a/NEWS.md b/NEWS.md index 9fc3f95a..37221e79 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,6 +11,8 @@ Going forward, **LazyVim** requires **Neovim** `>= 0.11.0`, and drops support fo - removed compatibility code for Neovim `< 0.11` - updated all LSP code to use the new LSP implementation - migrated **mason.nvim** and **mason-lspconfig.nvim** to `v2.x` +- added new `treesitter-main` extra to test the new `main` branch of `nvim-treesitter` + - after enabling, you will get errors. Update with `:Lazy` and restart Neovim ## 14.x @@ -122,7 +124,6 @@ vim.g.snacks_animate = false ## 11.x - **Keymaps:** - - `gB` to open the current repo in the browser - `gco` and `gcO` to add a comment below or above the current line - `wm` to toggle window maximize @@ -135,7 +136,6 @@ vim.g.snacks_animate = false It's a great plugin that enhances the native text objects. - `:LazyExtras` now has multiple new sections: - - **Enabled**: extras that are currently enabled - **Recommended Languages**: language extras recommended for the current buffer / directory - **Recommended Plugins**: extras that are recommended for most users @@ -173,7 +173,6 @@ Additionally, some core plugins have been moved to extras. ``` - plugins moved to extras: - - `mini.surround` - `mini.indentscope` scopes are now also highlighted with `indent-blankline` - `nvim-treesitter-context` @@ -191,7 +190,6 @@ Additionally, some core plugins have been moved to extras. You can find the updated docs [here](https://github.com/folke/trouble.nvim/tree/dev) - The **lazygit** integration now configures: - - the theme based on the colorscheme - nerd font icons (v3) - editor preset is set to `nvim-remote` for better interop with Neovim @@ -232,9 +230,7 @@ Additionally, some core plugins have been moved to extras. - New `:LazyExtras` command for managing **LazyVim** extras - Improved **formatting**: - - **LazyVim** can now work with multiple formatters. Types: - - **primary**: only one primary formatter can be active at a time. _(conform, none-ls, LSP)_ - **secondary**: multiple secondary formatters can be active _(eslint, ...)_ @@ -253,18 +249,15 @@ Additionally, some core plugins have been moved to extras. ``` - `none-ls.nvim` is no longer installed by default - - `conform.nvim` is now the default formatter - `nvim-lint` is now the default linter - If you want to keep using `none-ls.nvim`, you can enable the **lsp.none-ls** extra - `dashboard.nvim` is the new default dashboard plugin - - If you want to keep using `alpha.nvim`, you can enable the **ui.alpha** extra - Improved **root detection**: - - New `:LazyRoot` command that shows info about the root dir detection - Configurable with `vim.g.root_spec` diff --git a/lua/lazyvim/plugins/extras/ui/treesitter-main.lua b/lua/lazyvim/plugins/extras/ui/treesitter-main.lua new file mode 100644 index 00000000..934d311a --- /dev/null +++ b/lua/lazyvim/plugins/extras/ui/treesitter-main.lua @@ -0,0 +1,87 @@ +return { + { + "nvim-treesitter/nvim-treesitter", + version = false, -- last release is way too old and doesn't work on Windows + branch = "main", + build = ":TSUpdate", + lazy = true, + cmd = { "TSUpdate", "TSInstall", "TSLog", "TSUninstall" }, + enabled = function() + if vim.fn.executable("tree-sitter") == 0 then + LazyVim.error("**treesitter-main** requires the `tree-sitter` executable to be installed") + return false + end + return true + end, + init = function() end, + ---@param opts TSConfig + config = function(_, opts) + if type(opts.ensure_installed) ~= "table" then + error("opts.ensure_installed must be a table") + end + + local TS = require("nvim-treesitter") + TS.setup(opts) + + local needed = LazyVim.dedup(opts.ensure_installed --[[@as string[] ]]) + local installed = TS.get_installed("parsers") + local install = vim.tbl_filter(function(lang) + return not vim.tbl_contains(installed, lang) + end, needed) + + if #install > 0 then + TS.install(install, { summary = true }) + end + + -- backwards compatibility with the old treesitter config for indent + if vim.tbl_get(opts, "indent", "enable") then + vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" + end + + -- backwards compatibility with the old treesitter config for highlight + if vim.tbl_get(opts, "highlight", "enable") then + vim.api.nvim_create_autocmd("FileType", { + callback = function() + pcall(vim.treesitter.start) + end, + }) + end + end, + }, + { + "nvim-treesitter/nvim-treesitter-textobjects", + branch = "main", + event = "VeryLazy", + opts = {}, + keys = function() + local moves = { + goto_next_start = { ["]f"] = "@function.outer", ["]c"] = "@class.outer", ["]a"] = "@parameter.inner" }, + goto_next_end = { ["]F"] = "@function.outer", ["]C"] = "@class.outer", ["]A"] = "@parameter.inner" }, + goto_previous_start = { ["[f"] = "@function.outer", ["[c"] = "@class.outer", ["[a"] = "@parameter.inner" }, + goto_previous_end = { ["[F"] = "@function.outer", ["[C"] = "@class.outer", ["[A"] = "@parameter.inner" }, + } + local ret = {} ---@type LazyKeysSpec[] + for method, keymaps in pairs(moves) do + for key, query in pairs(keymaps) do + local desc = query:gsub("@", ""):gsub("%..*", "") + desc = desc:sub(1, 1):upper() .. desc:sub(2) + desc = (key:sub(1, 1) == "[" and "Prev " or "Next ") .. desc + desc = desc .. (key:sub(2, 2) == key:sub(2, 2):upper() and " End" or " Start") + ret[#ret + 1] = { + key, + function() + require("nvim-treesitter-textobjects.move")[method](query, "textobjects") + end, + desc = desc, + mode = { "n", "x", "o" }, + silent = true, + } + end + end + return ret + end, + config = function(_, opts) + require("nvim-treesitter-textobjects").setup(opts) + end, + }, +}