Compare commits
2 Commits
d7721829b2
...
bd739b0092
| Author | SHA1 | Date | |
|---|---|---|---|
|
bd739b0092
|
|||
|
e0eb3179fa
|
@@ -7,13 +7,10 @@ return {
|
|||||||
lazy = false,
|
lazy = false,
|
||||||
branch = "main",
|
branch = "main",
|
||||||
build = ":TSUpdate",
|
build = ":TSUpdate",
|
||||||
-- main = "nvim-treesitter.configs",
|
-- Taken from kickstart.nvim
|
||||||
init = function()
|
config = function()
|
||||||
vim.wo.foldmethod = "expr"
|
-- ensure basic parser are installed
|
||||||
vim.wo.foldexpr = "v:lua.vim.treesitter.foldexpr()"
|
local parsers = {
|
||||||
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
|
|
||||||
|
|
||||||
require("nvim-treesitter").install({
|
|
||||||
"c",
|
"c",
|
||||||
"cpp",
|
"cpp",
|
||||||
"go",
|
"go",
|
||||||
@@ -32,6 +29,56 @@ return {
|
|||||||
"cmake",
|
"cmake",
|
||||||
"json",
|
"json",
|
||||||
"yaml",
|
"yaml",
|
||||||
|
}
|
||||||
|
require("nvim-treesitter").install(parsers)
|
||||||
|
|
||||||
|
---@param buf integer
|
||||||
|
---@param language string
|
||||||
|
local function treesitter_try_attach(buf, language)
|
||||||
|
-- Check if the parser exists
|
||||||
|
if not vim.treesitter.language.add(language) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
vim.treesitter.start(buf, language)
|
||||||
|
|
||||||
|
-- TODO: Does this work properly?
|
||||||
|
local has_fold_query = vim.treesitter.query.get(language, "folds") ~= nil
|
||||||
|
if has_fold_query then
|
||||||
|
vim.wo.foldmethod = "expr"
|
||||||
|
vim.wo.foldexpr = "v:lua.vim.treesitter.foldexpr()"
|
||||||
|
end
|
||||||
|
|
||||||
|
local has_indent_query = vim.treesitter.query.get(language, "indents") ~= nil
|
||||||
|
if has_indent_query then
|
||||||
|
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local available_parsers = require("nvim-treesitter").get_available()
|
||||||
|
vim.api.nvim_create_autocmd("FileType", {
|
||||||
|
callback = function(args)
|
||||||
|
local buf, filetype = args.buf, args.match
|
||||||
|
|
||||||
|
local language = vim.treesitter.language.get_lang(filetype)
|
||||||
|
if not language then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local installed_parsers = require("nvim-treesitter").get_installed("parsers")
|
||||||
|
|
||||||
|
if vim.tbl_contains(installed_parsers, language) then
|
||||||
|
-- enable the parser if it is installed
|
||||||
|
treesitter_try_attach(buf, language)
|
||||||
|
elseif vim.tbl_contains(available_parsers, language) then
|
||||||
|
-- if a parser is available in `nvim-treesitter` auto install it, and enable it after the installation is done
|
||||||
|
require("nvim-treesitter").install(language):await(function()
|
||||||
|
treesitter_try_attach(buf, language)
|
||||||
|
end)
|
||||||
|
else
|
||||||
|
-- try to enable treesitter features in case the parser exists but is not available from `nvim-treesitter`
|
||||||
|
treesitter_try_attach(buf, language)
|
||||||
|
end
|
||||||
|
end,
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ plugins=(
|
|||||||
zoxide
|
zoxide
|
||||||
mise
|
mise
|
||||||
gpg-agent
|
gpg-agent
|
||||||
|
vagrant
|
||||||
)
|
)
|
||||||
|
|
||||||
bindkey -M vicmd "k" up-line-or-beginning-search
|
bindkey -M vicmd "k" up-line-or-beginning-search
|
||||||
|
|||||||
Reference in New Issue
Block a user