diff options
| author | Stephan Seitz <stephan.seitz@fau.de> | 2022-01-22 19:10:34 +0100 |
|---|---|---|
| committer | Stephan Seitz <stephan.seitz@fau.de> | 2022-02-05 18:54:55 +0100 |
| commit | b06961a519c7494d0d0509a9eadd6bbf72b9bbf5 (patch) | |
| tree | cd5c95e9b2ea4fd2231272a925dd938f7604f031 /lua | |
| parent | indents(c): add zero_indent for #if (diff) | |
| download | nvim-treesitter-b06961a519c7494d0d0509a9eadd6bbf72b9bbf5.tar nvim-treesitter-b06961a519c7494d0d0509a9eadd6bbf72b9bbf5.tar.gz nvim-treesitter-b06961a519c7494d0d0509a9eadd6bbf72b9bbf5.tar.bz2 nvim-treesitter-b06961a519c7494d0d0509a9eadd6bbf72b9bbf5.tar.lz nvim-treesitter-b06961a519c7494d0d0509a9eadd6bbf72b9bbf5.tar.xz nvim-treesitter-b06961a519c7494d0d0509a9eadd6bbf72b9bbf5.tar.zst nvim-treesitter-b06961a519c7494d0d0509a9eadd6bbf72b9bbf5.zip | |
fix(indents): re-parse before each indent
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/nvim-treesitter/indent.lua | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/lua/nvim-treesitter/indent.lua b/lua/nvim-treesitter/indent.lua index 4ec0a3e23..6230d11bd 100644 --- a/lua/nvim-treesitter/indent.lua +++ b/lua/nvim-treesitter/indent.lua @@ -1,7 +1,6 @@ local parsers = require "nvim-treesitter.parsers" local queries = require "nvim-treesitter.query" local tsutils = require "nvim-treesitter.ts_utils" -local highlighter = require "vim.treesitter.highlighter" local function get_first_node_at_line(root, lnum) local col = vim.fn.indent(lnum) @@ -18,7 +17,7 @@ local function find_delimiter(bufnr, node, delimiter) if child:type() == delimiter then local linenr = child:start() local line = vim.api.nvim_buf_get_lines(bufnr, linenr, linenr + 1, false)[1] - local end_char = {child:end_()} + local end_char = { child:end_() } return child, #line == end_char[2] end end @@ -56,6 +55,10 @@ function M.get_indent(lnum) if not parser or not lnum then return -1 end + + -- Reparse in case we got triggered by ":h indentkeys" + parser:parse() + local bufnr = vim.api.nvim_get_current_buf() -- get_root_for_position is 0-based. @@ -81,7 +84,8 @@ function M.get_indent(lnum) local indent_size = vim.fn.shiftwidth() local indent = 0 - if root:start() ~= 0 then + local _, _, root_start = root:start() + if root_start ~= 0 then -- injected tree indent = vim.fn.indent(root:start() + 1) end @@ -119,7 +123,13 @@ function M.get_indent(lnum) end -- do not indent for nodes that starts-and-ends on same line and starts on target line (lnum) - if not is_processed_by_row[srow] and (q.indent[node:id()] and srow ~= erow and ((srow ~= lnum - 1) or q.indent[node:id()].start_at_same_line)) then + if + not is_processed_by_row[srow] + -- Dear stylua, please don't change the semantics of this statement! + -- stylua: ignore start + and (q.indent[node:id()] and srow ~= erow and ((srow ~= lnum - 1) or q.indent[node:id()].start_at_same_line)) + -- stylua: ignore end + then indent = indent + indent_size is_processed = true end |
