fix(treesitter): Make Treesitter install on start
Recent changes to treesitter have made it so that it cannot automatically install the languages you want. As such I have cobbled together this script to make it work right for me.
This commit is contained in:
parent
0a076ae9f8
commit
8d30935771
|
|
@ -8,6 +8,7 @@ M.setup = function()
|
||||||
|
|
||||||
-- Load this after loading plugins to ensure default lspconfig is there
|
-- Load this after loading plugins to ensure default lspconfig is there
|
||||||
require("core.lspconfig")
|
require("core.lspconfig")
|
||||||
|
require("core.treesitter")
|
||||||
|
|
||||||
vim.cmd.colorscheme("gruvbox")
|
vim.cmd.colorscheme("gruvbox")
|
||||||
end
|
end
|
||||||
|
|
|
||||||
71
lua/core/treesitter.lua
Normal file
71
lua/core/treesitter.lua
Normal file
|
|
@ -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,
|
||||||
|
})
|
||||||
|
|
@ -3,6 +3,13 @@ return {
|
||||||
"nvim-treesitter/nvim-treesitter",
|
"nvim-treesitter/nvim-treesitter",
|
||||||
lazy = false,
|
lazy = false,
|
||||||
branch = "main",
|
branch = "main",
|
||||||
build = "TSUpdate",
|
build = ":TSUpdate",
|
||||||
|
setup = true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"nvim-treesitter/nvim-treesitter-context",
|
||||||
|
dependencies = {
|
||||||
|
"nvim-treesitter/nvim-treesitter",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user