mirror of
https://github.com/pnx/dotfiles
synced 2026-06-16 03:14:55 +02:00
nvim/lua/user/plugins/editor/treesitter.lua: add treesitter alias mapping
This commit is contained in:
parent
5c9e937fbb
commit
f64fddee32
1 changed files with 9 additions and 8 deletions
|
|
@ -9,7 +9,7 @@ return {
|
|||
build = function()
|
||||
require("nvim-treesitter.install").update({ with_sync = true })
|
||||
end,
|
||||
opts_extend = { "install" },
|
||||
opts_extend = { "install", "alias" },
|
||||
opts = {
|
||||
-- Default parsers.
|
||||
install = {
|
||||
|
|
@ -42,6 +42,9 @@ return {
|
|||
"printf",
|
||||
"nginx",
|
||||
},
|
||||
alias = {
|
||||
dotenv = "env"
|
||||
}
|
||||
},
|
||||
config = function(_, opts)
|
||||
local ts = require("nvim-treesitter")
|
||||
|
|
@ -61,24 +64,22 @@ return {
|
|||
-- ['%.env%..+'] = 'dotenv',
|
||||
-- }
|
||||
-- })
|
||||
vim.treesitter.language.register('dotenv', { 'env' })
|
||||
-- vim.treesitter.language.register('dotenv', { 'env' })
|
||||
|
||||
for _, value in pairs(opts.install) do
|
||||
vim.treesitter.language.register(value, value)
|
||||
end
|
||||
|
||||
for k, v in pairs(opts.alias) 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
|
||||
-- local all_langs = vim.treesitter.language._complete()
|
||||
-- local lang = vim.treesitter.language.get_lang(ev.match)
|
||||
-- vim.print(ev.match, all_langs, vim.tbl_contains(all_langs, lang))
|
||||
-- if vim.tbl_contains(all_langs, lang) then
|
||||
-- vim.treesitter.start(ev.buf)
|
||||
-- end
|
||||
end,
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue