nvim-treesitter / nvim-treesitter

Nvim Treesitter configurations and abstraction layer
Apache License 2.0
10.81k stars 900 forks source link

Indentation module breaks auto indent in JS files #7062

Open JonoLF opened 2 months ago

JonoLF commented 2 months ago

Describe the bug

While using the indentation module, to fix the comment indentation problem mentioned in #3830, other indentation then breaks. I've seen a few other similar issue, but haven't found any that match my problem exactly. Disabling the indentation module makes it work as expected. I have tested this with other file types and it seems to only be a JS problem (not sure if effects JSX, TS, or TSX, I don't have files to test with)

To Reproduce

  1. treesitter config:
    require'nvim-treesitter.configs'.setup {
    ensure_installed = {"c", "lua", "cpp", "bash", "matlab"},
    sync_install = false,
    auto_install = true,
    highlight = {
        enable = true,
        additional_vim_regex_highlighting = false,
    },
    indent = {
        enable = true,
    },
    }
  2. create a function:
    function foo() {
    }
  3. hitting either o in normal mode or enter in insert mode places the cursor as so:
    function foo() {
    |
    }
  4. formatting with = also applies no change
  5. The same issue is seen with other blocks (tested for, while, if, etc)

Expected behavior

Normal indentation is expected:

function foo() {
    |
}

with whatever tabstop is defined

Output of :checkhealth nvim-treesitter

==============================================================================
nvim-treesitter: require("nvim-treesitter.health").check()

Installation ~
- WARNING `tree-sitter` executable not found (parser generator, only needed for :TSInstallFromGrammar, not required for :TSInstall)
- OK `node` found v21.7.3 (only needed for :TSInstallFromGrammar)
- OK `git` executable found.
- OK `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
  Version: cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
- 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.9.3-76060903-generic",
  sysname = "Linux",
  version = "#202405300957~1718348209~22.04~7817b67 SMP PREEMPT_DYNAMIC Mon J"
} ~

Parser/Features         H L F I J
  - arduino             ✓ ✓ ✓ ✓ ✓
  - bash                ✓ ✓ ✓ . ✓
  - c                   ✓ ✓ ✓ ✓ ✓
  - cmake               ✓ . ✓ ✓ ✓
  - cpp                 ✓ ✓ ✓ ✓ ✓
  - css                 ✓ . ✓ ✓ ✓
  - csv                 ✓ . . . .
  - cuda                ✓ ✓ ✓ ✓ ✓
  - diff                ✓ . . . ✓
  - dockerfile          x . . . x
  - git_config          ✓ . ✓ . ✓
  - git_rebase          ✓ . . . ✓
  - gitcommit           ✓ . . . ✓
  - gitignore           ✓ . . . ✓
  - go                  ✓ ✓ ✓ ✓ ✓
  - html                ✓ ✓ ✓ ✓ ✓
  - ini                 ✓ . ✓ . ✓
  - javascript          ✓ ✓ ✓ ✓ ✓
  - json                ✓ ✓ ✓ ✓ .
  - jsonc               ✓ ✓ ✓ ✓ ✓
  - lua                 ✓ ✓ ✓ ✓ ✓
  - make                ✓ . ✓ . ✓
  - markdown            ✓ . ✓ ✓ ✓
  - markdown_inline     ✓ . . . ✓
  - matlab              ✓ ✓ ✓ ✓ ✓
  - python              ✓ ✓ ✓ ✓ ✓
  - query               ✓ ✓ ✓ ✓ ✓
  - ssh_config          ✓ ✓ ✓ ✓ ✓
  - tmux                ✓ . . . ✓
  - typescript          ✓ ✓ ✓ ✓ ✓
  - udev                ✓ ✓ . . ✓
  - 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} ~

The following errors have been detected: ~
- ERROR dockerfile(highlights): ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:112: Failed to load parser for language 'dockerfile': uv_dlopen: no error
  dockerfile(highlights) is concatenated from the following files:
  | [ERROR]:"/home/jono/.local/share/nvim/site/pack/packer/start/nvim-treesitter/queries/dockerfile/highlights.scm", failed to load: ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:112: Failed to load parser for language 'dockerfile': uv_dlopen: no error
- ERROR dockerfile(injections): ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:112: Failed to load parser for language 'dockerfile': uv_dlopen: no error
  dockerfile(injections) is concatenated from the following files:
  | [ERROR]:"/home/jono/.local/share/nvim/site/pack/packer/start/nvim-treesitter/queries/dockerfile/injections.scm", failed to load: ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:112: Failed to load parser for language 'dockerfile': uv_dlopen: no error

Output of nvim --version

NVIM v0.11.0-dev-637+gac53996eb
Build type: RelWithDebInfo
LuaJIT 2.1.1724090421
Compilation: /usr/bin/cc -O2 -g -Og -g -flto=auto -fno-fat-lto-objects -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wvla -Wdouble-promotion -Wmissing-noreturn -Wmissing-format-attribute -Wmissing-prototypes -fsigned-char -fstack-protector-strong -Wno-conversion -fno-common -Wno-unused-result -Wimplicit-fallthrough -fdiagnostics-color=always  -DUNIT_TESTING -DHAVE_UNIBILIUM -D_GNU_SOURCE -DINCLUDE_GENERATED_DECLARATIONS -DUTF8PROC_STATIC -I/home/jono/neovim/.deps/usr/include/luajit-2.1 -I/home/jono/neovim/.deps/usr/include -I/home/jono/neovim/build/src/nvim/auto -I/home/jono/neovim/build/include -I/home/jono/neovim/build/cmake.config -I/home/jono/neovim/src -I/usr/include 

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/share/nvim"

Run :checkhealth for more info

Additional context

I have tested the behaviour with both smartindent and autoindent off and on, no change. nvim-treesitter has been updated to the latest version. List of additional plugins in case of a clash between them:

GitMurf commented 2 months ago

Confirming here that I am experiencing this problem with several other file types. Seems like every file I have tested since updating yesterday. Lua, JavaScript and TypeScript is what I primarily use and indentations are all broke.

GitMurf commented 2 months ago

Here is a short repro video just to confirm / show with Lua files (since title of the issue is specific to JS).

https://github.com/user-attachments/assets/70b6649b-85f9-4675-a8ed-509e2a585859