Skip to content

Commit 4021496

Browse files
committed
Add treesitter indentation
1 parent a6dcf68 commit 4021496

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

init.lua

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,7 @@ require('lazy').setup({
882882
lazy = false,
883883
build = ':TSUpdate',
884884
branch = 'main',
885+
-- [[ Configure Treesitter ]] See `:help nvim-treesitter-intro`
885886
config = function()
886887
local parsers = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' }
887888
require('nvim-treesitter').install(parsers)
@@ -890,9 +891,20 @@ require('lazy').setup({
890891
local buf, filetype = args.buf, args.match
891892

892893
local language = vim.treesitter.language.get_lang(filetype)
893-
if not vim.tbl_contains(parsers, language) then return end
894+
if not language then return end
894895

895-
vim.treesitter.start()
896+
-- check if parser exists and load it
897+
if not vim.treesitter.language.add(language) then return end
898+
-- enables syntax highlighting and other treesitter features
899+
vim.treesitter.start(buf, language)
900+
901+
-- enables treesitter based folds
902+
-- for more info on folds see `:help folds`
903+
-- vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
904+
-- vim.wo.foldmethod = 'expr'
905+
906+
-- enables treesitter based indentation
907+
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
896908
end,
897909
})
898910
end,

0 commit comments

Comments
 (0)