diff options
| author | Stephan Seitz <stephan.seitz@fau.de> | 2022-01-23 15:52:03 +0100 |
|---|---|---|
| committer | Stephan Seitz <stephan.seitz@fau.de> | 2022-02-05 18:54:55 +0100 |
| commit | aa035cdf2ae60eeedee76c59490d5bcce569af2a (patch) | |
| tree | 7ecc341564939205d85bd9f2be85a08c9afa4511 /lua | |
| parent | indents(python): remove branches.py from expected failures (diff) | |
| download | nvim-treesitter-aa035cdf2ae60eeedee76c59490d5bcce569af2a.tar nvim-treesitter-aa035cdf2ae60eeedee76c59490d5bcce569af2a.tar.gz nvim-treesitter-aa035cdf2ae60eeedee76c59490d5bcce569af2a.tar.bz2 nvim-treesitter-aa035cdf2ae60eeedee76c59490d5bcce569af2a.tar.lz nvim-treesitter-aa035cdf2ae60eeedee76c59490d5bcce569af2a.tar.xz nvim-treesitter-aa035cdf2ae60eeedee76c59490d5bcce569af2a.tar.zst nvim-treesitter-aa035cdf2ae60eeedee76c59490d5bcce569af2a.zip | |
workaround(indents): avoid reparsing for indent sensitive yaml/python
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/nvim-treesitter/indent.lua | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/lua/nvim-treesitter/indent.lua b/lua/nvim-treesitter/indent.lua index 6230d11bd..6430a603c 100644 --- a/lua/nvim-treesitter/indent.lua +++ b/lua/nvim-treesitter/indent.lua @@ -2,6 +2,13 @@ local parsers = require "nvim-treesitter.parsers" local queries = require "nvim-treesitter.query" local tsutils = require "nvim-treesitter.ts_utils" +local M = {} + +M.avoid_force_reparsing = { + python = true, + yaml = 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) @@ -23,8 +30,6 @@ local function find_delimiter(bufnr, node, delimiter) end end -local M = {} - local get_indents = tsutils.memoize_by_buf_tick(function(bufnr, root, lang) local map = { auto = {}, @@ -51,15 +56,19 @@ end, { ---@param lnum number (1-indexed) function M.get_indent(lnum) - local parser = parsers.get_parser() + local bufnr = vim.api.nvim_get_current_buf() + local parser = parsers.get_parser(bufnr) if not parser or not lnum then return -1 end - -- Reparse in case we got triggered by ":h indentkeys" - parser:parse() + local root_lang = parsers.get_buf_lang(bufnr) - local bufnr = vim.api.nvim_get_current_buf() + -- some languages like Python will actually have worse results when re-parsing at opened new line + if not M.avoid_force_reparsing[root_lang] then + -- Reparse in case we got triggered by ":h indentkeys" + parser:parse() + end -- get_root_for_position is 0-based. local root, _, lang_tree = tsutils.get_root_for_position(lnum - 1, 0, parser) |
