aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorStephan Seitz <stephan.seitz@fau.de>2022-02-05 13:40:41 +0100
committerStephan Seitz <stephan.seitz@fau.de>2022-02-05 18:54:55 +0100
commit07e07cf303b9a91391af550b2f8c29cc25aab07b (patch)
tree678e18cf91e2d7c541a31152074d510924d287c0 /lua
parentUpdate lua/nvim-treesitter/indent.lua (diff)
downloadnvim-treesitter-07e07cf303b9a91391af550b2f8c29cc25aab07b.tar
nvim-treesitter-07e07cf303b9a91391af550b2f8c29cc25aab07b.tar.gz
nvim-treesitter-07e07cf303b9a91391af550b2f8c29cc25aab07b.tar.bz2
nvim-treesitter-07e07cf303b9a91391af550b2f8c29cc25aab07b.tar.lz
nvim-treesitter-07e07cf303b9a91391af550b2f8c29cc25aab07b.tar.xz
nvim-treesitter-07e07cf303b9a91391af550b2f8c29cc25aab07b.tar.zst
nvim-treesitter-07e07cf303b9a91391af550b2f8c29cc25aab07b.zip
fix(indents): ignore comment_parsers for indentation
Diffstat (limited to 'lua')
-rw-r--r--lua/nvim-treesitter/indent.lua22
1 files changed, 20 insertions, 2 deletions
diff --git a/lua/nvim-treesitter/indent.lua b/lua/nvim-treesitter/indent.lua
index 9d7a68ee4..db6832098 100644
--- a/lua/nvim-treesitter/indent.lua
+++ b/lua/nvim-treesitter/indent.lua
@@ -9,6 +9,12 @@ M.avoid_force_reparsing = {
yaml = true,
}
+M.comment_parsers = {
+ comment = true,
+ jsdoc = true,
+ phpdoc = true,
+}
+
local function get_first_node_at_line(root, lnum)
local col = vim.fn.indent(lnum)
return root:descendant_for_range(lnum - 1, col, lnum - 1, col)
@@ -70,8 +76,20 @@ function M.get_indent(lnum)
parser:parse()
end
- -- get_root_for_position is 0-based.
- local root, _, lang_tree = tsutils.get_root_for_position(lnum - 1, 0, parser)
+ -- Get language tree with smallest range around node that's not a comment parser
+ local root, lang_tree
+ parser:for_each_tree(function(tstree, tree)
+ if not tstree or M.comment_parsers[tree:lang()] then
+ return
+ end
+ local local_root = tstree:root()
+ if tsutils.is_in_node_range(local_root, lnum - 1, 0) then
+ if not root or tsutils.node_length(root) >= tsutils.node_length(local_root) then
+ root = local_root
+ lang_tree = tree
+ end
+ end
+ end)
-- Not likely, but just in case...
if not root then