nvim-treesitter / nvim-treesitter

Nvim Treesitter configurations and abstraction layer
Apache License 2.0
10.82k stars 899 forks source link

Incorrect indentation of multiline comments (indent on or off) #3830

Closed everett1992 closed 1 year ago

everett1992 commented 1 year ago

Describe the bug

Tree sitter causes bad indentation in typescript multi line comments. The behavior is inconsistent with neovim's out of the box behavior and incorrect whether indent module is enabled or disabled, tho the behavior is different depending on the indent module.

With an empty init.vim and no plugins typing i/*<enter><enter>/<esc> yields an expected value

/*
 *
 */

Typing o in the middle line has correct indentation as well

/*
 * <- o here
 *
 */

However with treesitter installed and the highlight module enabled the same keystrokes indent the second two lines (i/*<enter><enter>/<esc>)

require('nvim-treesitter.configs').setup {
  ensure_installed = 'all',
  highlight = { enable = true},
}

return require('packer').startup(function()
  use 'wbthomason/packer.nvim'
  use { 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate' }
end)
/* <- enter enter here
    *
    */

With the indent module enabled the initial comment is correct but new lines with o are indented wrong

require('nvim-treesitter.configs').setup {
  ensure_installed = 'all',
  highlight = { enable = true},
  indent = { enable = true },
}

return require('packer').startup(function()
  use 'wbthomason/packer.nvim'
  use { 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate' }
end)

Initial comment

/* 
 *
 */

See that the third line has no space padding.

/*
 * <- o here
*
 */

To Reproduce

See above

Expected behavior

The *s should be vertically aligned, matching the neovim's out of the box behavior.

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 v18.12.0 (only needed for :TSInstallFromGrammar)
  - OK: `git` executable found.
  - OK: `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
    Version: cc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
  - OK: Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI.

## Parser/Features H L F I J
  - http           ✓ . . . ✓
  - prisma         ✓ . . . .
  - make           ✓ . ✓ . ✓
  - rasi           ✓ ✓ ✓ ✓ .
  - regex          ✓ . . . .
  - hack           ✓ . . . .
  - norg           . . . . .
  - proto          ✓ . ✓ . .
  - vala           ✓ . ✓ . .
  - lalrpop        ✓ ✓ . . .
  - html           ✓ ✓ ✓ ✓ ✓
  - solidity       ✓ . . . .
  - hcl            ✓ . ✓ ✓ ✓
  - diff           ✓ . . . .
  - cooklang       ✓ . . . .
  - verilog        ✓ ✓ ✓ . ✓
  - elvish         ✓ . . . ✓
  - latex          ✓ . ✓ . ✓
  - astro          ✓ ✓ ✓ ✓ ✓
  - foam           ✓ ✓ ✓ ✓ ✓
  - wgsl           ✓ . ✓ ✓ .
  - m68k           ✓ ✓ ✓ . ✓
  - vhs            ✓ . . . .
  - json           ✓ ✓ ✓ ✓ .
  - vim            ✓ ✓ ✓ . ✓
  - tiger          ✓ ✓ ✓ ✓ ✓
  - sxhkdrc        ✓ . ✓ . ✓
  - nickel         ✓ . . . .
  - gitattributes  ✓ . . . ✓
  - meson          ✓ . ✓ . ✓
  - git_rebase     ✓ . . . ✓
  - qmljs          ✓ . ✓ . .
  - blueprint      ✓ . . . .
  - racket         ✓ . ✓ . ✓
  - twig           ✓ . . . ✓
  - scheme         ✓ . ✓ . ✓
  - rego           ✓ . . . ✓
  - awk            ✓ . . . ✓
  - arduino        ✓ ✓ ✓ ✓ ✓
  - embedded_template✓ . . . ✓
  - clojure        ✓ ✓ ✓ . ✓
  - commonlisp     ✓ ✓ ✓ . .
  - go             ✓ ✓ ✓ ✓ ✓
  - cpp            ✓ ✓ ✓ ✓ ✓
  - cuda           ✓ ✓ ✓ ✓ ✓
  - glsl           ✓ ✓ ✓ ✓ ✓
  - hlsl           ✓ ✓ ✓ ✓ ✓
  - dockerfile     ✓ . . . ✓
  - v              ✓ ✓ ✓ ✓ ✓
  - dot            ✓ . . . ✓
  - rust           ✓ ✓ ✓ ✓ ✓
  - fusion         ✓ ✓ ✓ ✓ .
  - ledger         ✓ . ✓ ✓ ✓
  - python         ✓ ✓ ✓ ✓ ✓
  - gomod          ✓ . . . ✓
  - gowork         ✓ . . . ✓
  - javascript     ✓ ✓ ✓ ✓ ✓
  - graphql        ✓ . . ✓ ✓
  - bash           ✓ ✓ ✓ . ✓
  - ruby           ✓ ✓ ✓ ✓ ✓
  - perl           ✓ . ✓ . .
  - fish           ✓ ✓ ✓ ✓ ✓
  - php            ✓ ✓ ✓ ✓ ✓
  - java           ✓ ✓ . ✓ ✓
  - yaml           ✓ ✓ ✓ ✓ ✓
  - kotlin         ✓ ✓ ✓ . ✓
  - yang           ✓ . ✓ ✓ .
  - ninja          ✓ . ✓ ✓ .
  - nix            ✓ ✓ ✓ . ✓
  - jsonnet        ✓ . . . .
  - css            ✓ . ✓ ✓ ✓
  - scss           ✓ . . ✓ .
  - rst            ✓ ✓ . . ✓
  - fennel         ✓ ✓ . . ✓
  - elixir         ✓ ✓ ✓ ✓ ✓
  - ql             ✓ ✓ ✓ ✓ ✓
  - gleam          ✓ ✓ ✓ ✓ ✓
  - surface        ✓ . ✓ ✓ ✓
  - pascal         ✓ ✓ ✓ ✓ ✓
  - eex            ✓ . . . ✓
  - lua            ✓ ✓ ✓ ✓ ✓
  - heex           ✓ ✓ ✓ ✓ ✓
  - ocaml          ✓ ✓ ✓ . ✓
  - comment        ✓ . . . .
  - jsdoc          ✓ . . . .
  - ocaml_interface✓ ✓ ✓ . ✓
  - menhir         ✓ . . . ✓
  - sql            ✓ . . . ✓
  - org            . . . . .
  - gdscript       ✓ ✓ . ✓ ✓
  - todotxt        ✓ . . . .
  - typescript     ✓ ✓ ✓ ✓ ✓
  - r              ✓ ✓ . ✓ ✓
  - svelte         ✓ . ✓ ✓ ✓
  - slint          ✓ . . ✓ .
  - beancount      ✓ . ✓ . .
  - haskell        ✓ . ✓ . ✓
  - rnoweb         ✓ . ✓ . ✓
  - jq             ✓ . . . ✓
  - markdown       ✓ . ✓ . ✓
  - phpdoc         ✓ . . . .
  - c              ✓ ✓ ✓ ✓ ✓
  - julia          ✓ ✓ ✓ ✓ ✓
  - bibtex         ✓ . ✓ ✓ .
  - sparql         ✓ ✓ ✓ ✓ ✓
  - pug            ✓ . . . ✓
  - zig            ✓ . ✓ ✓ ✓
  - erlang         ✓ . ✓ . .
  - elm            ✓ . . . ✓
  - fortran        ✓ . ✓ ✓ .
  - jsonc          ✓ ✓ ✓ ✓ ✓
  - cmake          ✓ . ✓ . .
  - vue            ✓ . ✓ ✓ ✓
  - tlaplus        ✓ ✓ ✓ . ✓
  - toml           ✓ ✓ ✓ ✓ ✓
  - help           ✓ . . . .
  - markdown_inline✓ . . . ✓
  - json5          ✓ . . . ✓
  - dart           ✓ ✓ . ✓ ✓
  - supercollider  ✓ ✓ ✓ ✓ ✓
  - pioasm         ✓ . . . ✓
  - query          ✓ ✓ ✓ ✓ ✓
  - hjson          ✓ ✓ ✓ ✓ ✓
  - turtle         ✓ ✓ ✓ ✓ ✓
  - scala          ✓ . ✓ . ✓
  - hocon          ✓ . . . ✓
  - agda           ✓ . ✓ . .
  - c_sharp        ✓ ✓ ✓ . ✓
  - llvm           ✓ . . . .
  - glimmer        ✓ . . . .
  - tsx            ✓ ✓ ✓ ✓ ✓

  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 --version
NVIM v0.8.0-1210-gd367ed9b2
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by runner@fv-az505-656

Features: +acl +iconv +tui
See ":help feature-compile"

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

Run :checkhealth for more info

Additional context

The issue affects both typescript and javascript but not java.

everett1992 commented 1 year ago

Somehow I missed #2544 in my initial search