diff --git a/init.lua b/init.lua index 28515d3..3931db7 100644 --- a/init.lua +++ b/init.lua @@ -25,7 +25,7 @@ vim.lsp.enable({ vim.api.nvim_create_autocmd("LspAttach", { callback = function(ev) local client = vim.lsp.get_client_by_id(ev.data.client_id) - if client and client.supports_method('textDocument/inlayHint') then + if client and client:supports_method('textDocument/inlayHint') then vim.lsp.inlay_hint.enable(true, { bufnr = ev.buf }) end diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua index 190a32e..4cde7e8 100644 --- a/lua/plugins/treesitter.lua +++ b/lua/plugins/treesitter.lua @@ -1,14 +1,19 @@ return { 'nvim-treesitter/nvim-treesitter', + branch = 'main', build = ':TSUpdate', - opts = { - ensure_installed = { + config = function() + local ts = require('nvim-treesitter') + + local parsers = { 'lua', 'vim', 'vimdoc', 'rust', 'typescript', + 'tsx', 'javascript', + 'jsx', 'html', 'css', 'scss', @@ -27,9 +32,26 @@ return { 'astro', 'vue', 'java', - }, - auto_install = true, - highlight = { enable = true }, - indent = { enable = true }, - }, + } + + for _, parser in ipairs(parsers) do + ts.install(parser) + end + + -- Filetypes whose name differs from the parser name + local ft_to_parser = { + typescriptreact = 'tsx', + javascriptreact = 'jsx', + } + + vim.api.nvim_create_autocmd('FileType', { + callback = function(ev) + local ft = ev.match + local lang = ft_to_parser[ft] or ft + if pcall(vim.treesitter.start, ev.buf, lang) then + vim.bo[ev.buf].indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" + end + end, + }) + end, }