nvim-treesitter
nvim-treesitter copied to clipboard
Incorrect restoration of `indentexpr` when setting `filetype`
Describe the bug
When Treesitter indentation is enabled and filetype is set manually, indentexpr gets set to the appropriate value for the old filetype, not the new one, provided:
- The old filetype has Treesitter indentation support and Treesitter indentation is enabled.
- The new filetype does not have Treesitter indentation support.
- The old filetype does have an
indentexprset in itsrtp/indent/*script.
To Reproduce
- Install the
luaparser and enable Treesitter indent. - Run
:set ft=lua - Observe that
:set indeprintsindentexpr=nvim_treesitter#indent(). - Run
:set ft= - Observe that
:set indeprintsindentexpr=GetLuaIndent().
Expected behavior
indentexpr should be set according to the current filetype's indent plugin unless Treesitter indent is enabled for the current filetype. Treesitter indent status for previous filetypes should be irrelevant.
Output of :checkhealth nvim-treesitter
Installation ~
- OK `tree-sitter` found 0.20.8 (parser generator, only needed for :TSInstallFromGrammar)
- OK `node` found v20.3.1 (only needed for :TSInstallFromGrammar)
- OK `git` executable found.
- OK `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
Version: cc (GCC) 13.1.1 20230429
- OK Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI.
OS Info:
{
machine = "x86_64",
release = "6.3.9-arch1-1",
sysname = "Linux",
version = "#1 SMP PREEMPT_DYNAMIC Wed, 21 Jun 2023 20:46:20 +0000"
} ~
Parser/Features H L F I J
- bash ✓ ✓ ✓ . ✓
- c ✓ ✓ ✓ ✓ ✓
- cpp ✓ ✓ ✓ ✓ ✓
- json ✓ ✓ ✓ ✓ .
- lua ✓ ✓ ✓ ✓ ✓
- luadoc ✓ . . . .
- python ✓ ✓ ✓ ✓ ✓
- query ✓ ✓ ✓ ✓ ✓
- rust ✓ ✓ ✓ ✓ ✓
- vim ✓ ✓ ✓ . ✓
- vimdoc ✓ . . . ✓
- yaml ✓ ✓ ✓ ✓ ✓
Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
+) multiple parsers found, only one will be used
x) errors found in the query, try to run :TSUpdate {lang} ~
Output of nvim --version
NVIM v0.10.0-dev-596+g7d0a23973
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/gcc-10 -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wvla -Wdouble-promotion -Wmissing-noreturn -Wmissing-format-attribute -Wmissing-prototypes -fno-common -Wno-unused-result -Wimplicit-fallthrough -fdiagnostics-color=always -fstack-protector-strong -DUNIT_TESTING -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_TS_HAS_SET_MAX_START_DEPTH -I/__w/neovim/neovim/.deps/usr/include/luajit-2.1 -I/usr/include -I/__w/neovim/neovim/.deps/usr/include -I/__w/neovim/neovim/build/src/nvim/auto -I/__w/neovim/neovim/build/include -I/__w/neovim/neovim/build/cmake.config -I/__w/neovim/neovim/src -I/usr/include -I/__w/neovim/neovim/.deps/usr/include -I/__w/neovim/neovim/.deps/usr/include -I/__w/neovim/neovim/.deps/usr/include -I/__w/neovim/neovim/.deps/usr/include -I/__w/neovim/neovim/.deps/usr/include -I/__w/neovim/neovim/.deps/usr/include
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/__w/neovim/neovim/build/nvim.AppDir/usr/share/nvim"
Additional context
My guess is that when nvim-treesitter sets indentexpr in the function below, this occurs after the rtp/indent/* script has run for the newly set filetype, overwriting the value set by the script.
https://github.com/nvim-treesitter/nvim-treesitter/blob/99a7e8d268a052e0e90211a2ab9c1c89e9db038c/lua/nvim-treesitter/indent.lua#L355-L357