Skip to content

Commit a6dcf68

Browse files
committed
Attach treesitter using language name instead of filetype
1 parent 966d5e9 commit a6dcf68

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

init.lua

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -879,12 +879,21 @@ require('lazy').setup({
879879

880880
{ -- Highlight, edit, and navigate code
881881
'nvim-treesitter/nvim-treesitter',
882+
lazy = false,
883+
build = ':TSUpdate',
884+
branch = 'main',
882885
config = function()
883-
local filetypes = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' }
884-
require('nvim-treesitter').install(filetypes)
886+
local parsers = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' }
887+
require('nvim-treesitter').install(parsers)
885888
vim.api.nvim_create_autocmd('FileType', {
886-
pattern = filetypes,
887-
callback = function() vim.treesitter.start() end,
889+
callback = function(args)
890+
local buf, filetype = args.buf, args.match
891+
892+
local language = vim.treesitter.language.get_lang(filetype)
893+
if not vim.tbl_contains(parsers, language) then return end
894+
895+
vim.treesitter.start()
896+
end,
888897
})
889898
end,
890899
},

0 commit comments

Comments
 (0)