From 7d973dafdb1331aaf9fb8f5826231fa77aef35a8 Mon Sep 17 00:00:00 2001 From: Rustum Zia Date: Sat, 8 Mar 2025 09:13:27 -0500 Subject: [PATCH] feat(indent): use proper shiftwidth for injected languages --- lua/nvim-treesitter/indent.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lua/nvim-treesitter/indent.lua b/lua/nvim-treesitter/indent.lua index 19e7ef1ee..863f8659b 100644 --- a/lua/nvim-treesitter/indent.lua +++ b/lua/nvim-treesitter/indent.lua @@ -189,6 +189,10 @@ function M.get_indent(lnum) if root_start ~= 0 then -- injected tree indent = vim.fn.indent(root:start() + 1) + -- With an injected tree, we have a different language than the filetype of the current buffer, + -- so it doesn't make sense to use the value of 'shiftwidth' for the current buffer. Instead, we + -- get the default 'shiftwidth' for this filetype! + indent_size = vim.api.nvim_get_option_value("shiftwidth", { filetype = lang_tree:lang() }) end -- tracks to ensure multiple indent levels are not applied for same line