1
0
Fork 0
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:
Henrik Hautakoski 2026-05-17 22:36:13 +02:00
parent 5c9e937fbb
commit f64fddee32

View file

@ -9,7 +9,7 @@ return {
build = function() build = function()
require("nvim-treesitter.install").update({ with_sync = true }) require("nvim-treesitter.install").update({ with_sync = true })
end, end,
opts_extend = { "install" }, opts_extend = { "install", "alias" },
opts = { opts = {
-- Default parsers. -- Default parsers.
install = { install = {
@ -42,6 +42,9 @@ return {
"printf", "printf",
"nginx", "nginx",
}, },
alias = {
dotenv = "env"
}
}, },
config = function(_, opts) config = function(_, opts)
local ts = require("nvim-treesitter") local ts = require("nvim-treesitter")
@ -61,24 +64,22 @@ return {
-- ['%.env%..+'] = 'dotenv', -- ['%.env%..+'] = 'dotenv',
-- } -- }
-- }) -- })
vim.treesitter.language.register('dotenv', { 'env' }) -- vim.treesitter.language.register('dotenv', { 'env' })
for _, value in pairs(opts.install) do for _, value in pairs(opts.install) do
vim.treesitter.language.register(value, value) vim.treesitter.language.register(value, value)
end end
for k, v in pairs(opts.alias) do
vim.treesitter.language.register(v, k)
end
vim.api.nvim_create_autocmd('FileType', { vim.api.nvim_create_autocmd('FileType', {
callback = function(ev) callback = function(ev)
local lang = vim.treesitter.language.get_lang(ev.match) local lang = vim.treesitter.language.get_lang(ev.match)
if vim.list_contains(ts.get_installed(), lang) then if vim.list_contains(ts.get_installed(), lang) then
vim.treesitter.start(ev.buf) vim.treesitter.start(ev.buf)
end 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, end,
}) })