Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect indentation for javascript/typescript single-line if statement bodies #5898

Open
realSaltyFish opened this issue Jan 15, 2024 · 0 comments
Labels
bug Something isn't working indent Issues or PRs about indentation queries or module

Comments

@realSaltyFish
Copy link

realSaltyFish commented Jan 15, 2024

Describe the bug

nvim-treesitter incorrectly indents the body of if statements (and also else, for, while, etc.) if it is not wrapped in curly braces.

To Reproduce

  1. Create a typescript file.
  2. Paste the following code
function foo() {
  if (true)
    return 0;
}
  1. Re-indent the 3rd line (return) with ==. Code becomes
function foo() {
  if (true)
  return 0;
}

Expected behavior

Code stays unchanged.

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.5.0 (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.2.1 20230801
- 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.6.11-1-lts",
  sysname = "Linux",
  version = "#1 SMP PREEMPT_DYNAMIC Wed, 10 Jan 2024 16:41:56 +0000"
} ~

Parser/Features         H L F I J
  - bash                ✓ ✓ ✓ . ✓
  - c                   ✓ ✓ ✓ ✓ ✓
  - cpp                 ✓ ✓ ✓ ✓ ✓
  - go                  ✓ ✓ ✓ ✓ ✓
  - javascript          ✓ ✓ ✓ ✓ ✓
  - lua                 ✓ ✓ ✓ ✓ ✓
  - markdown            ✓ . ✓ ✓ ✓
  - markdown_inline     ✓ . . . ✓
  - python              ✓ ✓ ✓ ✓ ✓
  - query               ✓ ✓ ✓ ✓ ✓
  - rust                ✓ ✓ ✓ ✓ ✓
  - tsx                 ✓ ✓ ✓ ✓ ✓
  - typescript          ✓ ✓ ✓ ✓ ✓
  - vim                 ✓ ✓ ✓ . ✓
  - vimdoc              ✓ . . . ✓

  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-2086+g965dbd0e0
Build type: RelWithDebInfo
LuaJIT 2.1.1703358377
Run "nvim -V1 -v" for more info

Additional context

No response

@realSaltyFish realSaltyFish added the bug Something isn't working label Jan 15, 2024
@clason clason added the indent Issues or PRs about indentation queries or module label Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working indent Issues or PRs about indentation queries or module
Projects
None yet
Development

No branches or pull requests

2 participants