diff --git a/lua/core/init.lua b/lua/core/init.lua index 441e75a..5159c9c 100644 --- a/lua/core/init.lua +++ b/lua/core/init.lua @@ -8,6 +8,7 @@ M.setup = function() -- Load this after loading plugins to ensure default lspconfig is there require("core.lspconfig") + require("core.treesitter") vim.cmd.colorscheme("gruvbox") end diff --git a/lua/core/treesitter.lua b/lua/core/treesitter.lua new file mode 100644 index 0000000..0609615 --- /dev/null +++ b/lua/core/treesitter.lua @@ -0,0 +1,71 @@ +-- Due to the complete infrastructure change in nvim-tressiter +-- this file exists to install all the languages I want +-- and then make sure that treesitter support is enabled for them + +--- This is a mapping of parsers to filetypes +--- where the parser name and filetype is the same we leave the filetype blank +--- otherwise the filetype is the filetype(s) that the parser should be used in +local languages = { + ["bash"] = "", + ["c"] = "", + ["cpp"] = "", + ["css"] = "", + ["c_sharp"] = "", + ["diff"] = "", + ["git_config"] = "gitconfig", + ["git_rebase"] = "", + ["gitcommit"] = "", + ["gitignore"] = "", + ["go"] = "", + ["gomod"] = "", + ["html"] = "", + ["ini"] = "", + ["javascript"] = "", + ["jsonnet"] = "", + ["latex"] = "", + ["lua"] = "", + ["luadoc"] = "", + ["luap"] = "", + ["make"] = "", + ["markdown"] = "", + ["markdown_inline"] = "markdown", + ["python"] = "", + ["query"] = "", + ["regex"] = "", + ["rust"] = "", + ["scss"] = "", + ["toml"] = "", + ["vim"] = "", + ["vimdoc"] = "", + ["yuck"] = "", + ["yaml"] = "", + ["zig"] = "", +} + +local parsers = {} +local filetypes = {} +local TS = require("nvim-treesitter") + +for parser, filetype in pairs(languages) do + if filetype == "" then + table.insert(filetypes, parser) + else + table.insert(filetypes, parser) + end + table.insert(parsers, parser) +end +TS.install(parsers, { summary = true }) + +local all_parsers = TS.get_installed() + +local alltype = vim.tbl_extend("force", filetypes, all_parsers) + +vim.api.nvim_create_augroup("ts-augroup", {}) +vim.api.nvim_create_autocmd("FileType", { + pattern = alltype, + callback = function() + vim.treesitter.start() + vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" + require("treesitter-context").enable() + end, +}) diff --git a/lua/plugins/spec/treesitter.lua b/lua/plugins/spec/treesitter.lua index 2804aae..5344a12 100644 --- a/lua/plugins/spec/treesitter.lua +++ b/lua/plugins/spec/treesitter.lua @@ -3,6 +3,13 @@ return { "nvim-treesitter/nvim-treesitter", lazy = false, branch = "main", - build = "TSUpdate", + build = ":TSUpdate", + setup = true, + }, + { + "nvim-treesitter/nvim-treesitter-context", + dependencies = { + "nvim-treesitter/nvim-treesitter", + }, }, }