diff --git a/nvim/lua/user/plugins/editor/treesitter.lua b/nvim/lua/user/plugins/editor/treesitter.lua index ec94b2b..4802c09 100644 --- a/nvim/lua/user/plugins/editor/treesitter.lua +++ b/nvim/lua/user/plugins/editor/treesitter.lua @@ -1,27 +1,23 @@ return { - "nvim-treesitter/nvim-treesitter", - commit = "4916d6592ede8c07973490d9322f187e07dfefac", - pin = true, + "romus204/tree-sitter-manager.nvim", dependencies = { 'windwp/nvim-ts-autotag', 'nvim-treesitter/nvim-treesitter-textobjects' }, - build = function() - require("nvim-treesitter.install").update({ with_sync = true }) - end, - opts_extend = { "install", "alias" }, + opts_extend = { "ensure_installed", "alias" }, opts = { -- Default parsers. - install = { + ensure_installed = { -- VIM stuff "vim", "vimdoc", "query", - -- Common config languages + -- Common data formats "json", "yaml", "toml", + "dtd", "xml", "kdl", @@ -37,45 +33,26 @@ return { "re2c", "xresources", "sql", + "tsv", "csv", "ssh_config", "printf", "nginx", }, - alias = { - dotenv = "env" - } - }, - config = function(_, opts) - local ts = require("nvim-treesitter") - vim.api.nvim_create_autocmd('User', { pattern = 'TSUpdate', callback = function () - require("nvim-treesitter.parsers").dotenv = { + languages = { + dotenv = { install_info = { url = "https://github.com/pnx/tree-sitter-dotenv", branch = "main", - files = { "src/parser.c", "src/scanner.c" }, + files = { "src/parser.c", "src/scanner.c" } } } - end}) - - for _, value in pairs(opts.install) do - vim.treesitter.language.register(value, value) - end - - for k, v in pairs(opts.alias) do + }, + }, + config = function(_, opts) + for k, v in pairs(opts.alias or {}) do vim.treesitter.language.register(v, k) end - - vim.api.nvim_create_autocmd('FileType', { - callback = function(ev) - local lang = vim.treesitter.language.get_lang(ev.match) - if vim.list_contains(ts.get_installed(), lang) then - vim.treesitter.start(ev.buf) - end - end, - }) - - ts.install(opts.install) - ts.setup(opts) + require("tree-sitter-manager").setup(opts) end } diff --git a/nvim/lua/user/plugins/lang/bash.lua b/nvim/lua/user/plugins/lang/bash.lua index d884be6..c176168 100644 --- a/nvim/lua/user/plugins/lang/bash.lua +++ b/nvim/lua/user/plugins/lang/bash.lua @@ -1,10 +1,7 @@ +local spec = require('user.utils.lang_spec') + return { - { - "nvim-treesitter/nvim-treesitter", - opts = { - install = { "bash" } - } - }, + spec.treesitter("bash"), { "neovim/nvim-lspconfig", opts = { diff --git a/nvim/lua/user/plugins/lang/c.lua b/nvim/lua/user/plugins/lang/c.lua index 17ff1f9..0fcead0 100644 --- a/nvim/lua/user/plugins/lang/c.lua +++ b/nvim/lua/user/plugins/lang/c.lua @@ -1,10 +1,7 @@ +local spec = require('user.utils.lang_spec') + return { - { - "nvim-treesitter/nvim-treesitter", - opts = { - install = { "c", "cpp" } - } - }, + spec.treesitter("c", "cpp"), { "neovim/nvim-lspconfig", opts = { diff --git a/nvim/lua/user/plugins/lang/cmake.lua b/nvim/lua/user/plugins/lang/cmake.lua index a3379e2..12200cb 100644 --- a/nvim/lua/user/plugins/lang/cmake.lua +++ b/nvim/lua/user/plugins/lang/cmake.lua @@ -1,8 +1,5 @@ +local spec = require('user.utils.lang_spec') + return { - { - "nvim-treesitter/nvim-treesitter", - opts = { - install = { "cmake" } - } - }, + spec.treesitter("cmake"), } diff --git a/nvim/lua/user/plugins/lang/css.lua b/nvim/lua/user/plugins/lang/css.lua index d1c9995..a96eb1f 100644 --- a/nvim/lua/user/plugins/lang/css.lua +++ b/nvim/lua/user/plugins/lang/css.lua @@ -1,10 +1,7 @@ +local spec = require('user.utils.lang_spec') + return { - { - "nvim-treesitter/nvim-treesitter", - opts = { - install = { "css", "scss" } - } - }, + spec.treesitter("css", "scss"), { "neovim/nvim-lspconfig", opts = { diff --git a/nvim/lua/user/plugins/lang/docker.lua b/nvim/lua/user/plugins/lang/docker.lua index 3e4678b..3969920 100644 --- a/nvim/lua/user/plugins/lang/docker.lua +++ b/nvim/lua/user/plugins/lang/docker.lua @@ -1,8 +1,5 @@ +local spec = require('user.utils.lang_spec') + return { - { - "nvim-treesitter/nvim-treesitter", - opts = { - install = { "dockerfile" } - } - }, + spec.treesitter("dockerfile"), } diff --git a/nvim/lua/user/plugins/lang/go.lua b/nvim/lua/user/plugins/lang/go.lua index 7ee9acc..802d922 100644 --- a/nvim/lua/user/plugins/lang/go.lua +++ b/nvim/lua/user/plugins/lang/go.lua @@ -1,3 +1,5 @@ +local spec = require('user.utils.lang_spec') + local lspservers = { gopls = { codelens = { @@ -49,12 +51,7 @@ local lspservers = { } return { - { - "nvim-treesitter/nvim-treesitter", - opts = { - install = { "go", "gomod", "gowork", "gosum", "gotmpl" } - } - }, + spec.treesitter("go", "gomod", "gowork", "gosum", "gotmpl"), { "neovim/nvim-lspconfig", opts = { diff --git a/nvim/lua/user/plugins/lang/html.lua b/nvim/lua/user/plugins/lang/html.lua index caa055c..f925572 100644 --- a/nvim/lua/user/plugins/lang/html.lua +++ b/nvim/lua/user/plugins/lang/html.lua @@ -1,10 +1,7 @@ +local spec = require('user.utils.lang_spec') + return { - { - "nvim-treesitter/nvim-treesitter", - opts = { - install = { "html" } - } - }, + spec.treesitter("html"), { "neovim/nvim-lspconfig", opts = { diff --git a/nvim/lua/user/plugins/lang/javascript.lua b/nvim/lua/user/plugins/lang/javascript.lua index 1241e12..9dac209 100644 --- a/nvim/lua/user/plugins/lang/javascript.lua +++ b/nvim/lua/user/plugins/lang/javascript.lua @@ -1,8 +1,5 @@ +local spec = require('user.utils.lang_spec') + return { - { - "nvim-treesitter/nvim-treesitter", - opts = { - install = { "javascript", "javadoc" } - } - } + spec.treesitter("javascript", "javadoc"), } diff --git a/nvim/lua/user/plugins/lang/lua.lua b/nvim/lua/user/plugins/lang/lua.lua index c3c8ab7..ee5dd0c 100644 --- a/nvim/lua/user/plugins/lang/lua.lua +++ b/nvim/lua/user/plugins/lang/lua.lua @@ -1,3 +1,5 @@ +local spec = require('user.utils.lang_spec') + local lspservers = { lua_ls = { settings = { @@ -18,12 +20,7 @@ local lspservers = { } return { - { - "nvim-treesitter/nvim-treesitter", - opts = { - install = { "lua" } - } - }, + spec.treesitter("lua"), { "neovim/nvim-lspconfig", opts = { diff --git a/nvim/lua/user/plugins/lang/markdown.lua b/nvim/lua/user/plugins/lang/markdown.lua index e26322d..75a3c7d 100644 --- a/nvim/lua/user/plugins/lang/markdown.lua +++ b/nvim/lua/user/plugins/lang/markdown.lua @@ -1,14 +1,11 @@ +local spec = require('user.utils.lang_spec') + return { 'MeanderingProgrammer/render-markdown.nvim', ft = { "markdown" }, dependencies = { 'nvim-tree/nvim-web-devicons', - { - "nvim-treesitter/nvim-treesitter", - opts = { - install = { "markdown" } - } - }, + spec.treesitter("markdown"), { "windwp/nvim-ts-autotag", optional = true, diff --git a/nvim/lua/user/plugins/lang/ninja.lua b/nvim/lua/user/plugins/lang/ninja.lua index cacc9ce..e282bca 100644 --- a/nvim/lua/user/plugins/lang/ninja.lua +++ b/nvim/lua/user/plugins/lang/ninja.lua @@ -1,8 +1,5 @@ +local spec = require('user.utils.lang_spec') + return { - { - "nvim-treesitter/nvim-treesitter", - opts = { - install = { "ninja" } - } - }, + spec.treesitter("ninja"), } diff --git a/nvim/lua/user/plugins/lang/php.lua b/nvim/lua/user/plugins/lang/php.lua index 97fb8c8..f82e7b2 100644 --- a/nvim/lua/user/plugins/lang/php.lua +++ b/nvim/lua/user/plugins/lang/php.lua @@ -1,11 +1,8 @@ +local spec = require('user.utils.lang_spec') + return { - { - "nvim-treesitter/nvim-treesitter", - opts = { - install = { "php", "blade", "php_only", "phpdoc", "sql", "csv" }, - alias = { phpx = "php_only" } - } - }, + spec.treesitter("php", "blade", "php_only", "phpdoc", "sql", "csv"), + spec.treesitter_alias({ phpx = "php_only" }), { "windwp/nvim-ts-autotag", optional = true, diff --git a/nvim/lua/user/plugins/lang/qml.lua b/nvim/lua/user/plugins/lang/qml.lua index 423abfa..0e81945 100644 --- a/nvim/lua/user/plugins/lang/qml.lua +++ b/nvim/lua/user/plugins/lang/qml.lua @@ -1,14 +1,11 @@ +local spec = require('user.utils.lang_spec') + local lspservers = { qmlls = {} } return { - { - "nvim-treesitter/nvim-treesitter", - opts = { - install = { "qmljs" } - } - }, + spec.treesitter("qmljs"), { "neovim/nvim-lspconfig", opts = { diff --git a/nvim/lua/user/plugins/lang/rust.lua b/nvim/lua/user/plugins/lang/rust.lua index 962185f..fe7106f 100644 --- a/nvim/lua/user/plugins/lang/rust.lua +++ b/nvim/lua/user/plugins/lang/rust.lua @@ -1,3 +1,5 @@ +local spec = require('user.utils.lang_spec') + local lspservers = { rust_analyzer = { -- settings = { @@ -22,12 +24,7 @@ local lspservers = { } return { - { - "nvim-treesitter/nvim-treesitter", - opts = { - install = { "rust", "toml" } - } - }, + spec.treesitter("rust", "toml"), { "neovim/nvim-lspconfig", opts = { diff --git a/nvim/lua/user/plugins/lang/sql.lua b/nvim/lua/user/plugins/lang/sql.lua index ff45f61..2e77b25 100644 --- a/nvim/lua/user/plugins/lang/sql.lua +++ b/nvim/lua/user/plugins/lang/sql.lua @@ -1,14 +1,11 @@ +local spec = require('user.utils.lang_spec') + local lspservers = { sqlls = {} } return { - { - "nvim-treesitter/nvim-treesitter", - opts = { - install = { "sql" } - } - }, + spec.treesitter("sql"), { "neovim/nvim-lspconfig", opts = { diff --git a/nvim/lua/user/plugins/lang/typescript.lua b/nvim/lua/user/plugins/lang/typescript.lua index 9cfef38..5d217c4 100644 --- a/nvim/lua/user/plugins/lang/typescript.lua +++ b/nvim/lua/user/plugins/lang/typescript.lua @@ -1,3 +1,5 @@ +local spec = require('user.utils.lang_spec') + local lspservers = { ts_ls = function() local vue_language_server_path = vim.fn.expand '$MASON/packages' .. '/vue-language-server' .. '/node_modules/@vue/language-server' @@ -20,12 +22,7 @@ local lspservers = { } return { - { - "nvim-treesitter/nvim-treesitter", - opts = { - install = { "typescript", "tsx" } - } - }, + spec.treesitter("typescript", "tsx"), { "windwp/nvim-ts-autotag", optional = true, diff --git a/nvim/lua/user/plugins/lang/vue.lua b/nvim/lua/user/plugins/lang/vue.lua index 70f4457..9a8009d 100644 --- a/nvim/lua/user/plugins/lang/vue.lua +++ b/nvim/lua/user/plugins/lang/vue.lua @@ -1,3 +1,5 @@ +local spec = require('user.utils.lang_spec') + local lspservers = { vue_ls = { init_options = { @@ -10,16 +12,11 @@ local lspservers = { return { + spec.treesitter("vue"), -- Vue needs typescript { import = "user.plugins.lang.typescript" }, -- And most likely css/scss aswell. { import = "user.plugins.lang.css" }, - { - "nvim-treesitter/nvim-treesitter", - opts = { - install = { "vue" } - } - }, { "windwp/nvim-ts-autotag", optional = true, diff --git a/nvim/lua/user/utils/lang_spec.lua b/nvim/lua/user/utils/lang_spec.lua new file mode 100644 index 0000000..f198ea9 --- /dev/null +++ b/nvim/lua/user/utils/lang_spec.lua @@ -0,0 +1,22 @@ +local M = {} + +M.treesitter = function (...) + return { + "romus204/tree-sitter-manager.nvim", + opts = { + ensure_installed = {...}, + } + } +end + +M.treesitter_alias = function (value) + return { + "romus204/tree-sitter-manager.nvim", + opts = { + alias = value, + } + } +end + +return M +