nvim-treesitter / nvim-treesitter

Nvim Treesitter configurations and abstraction layer
Apache License 2.0
10.43k stars 877 forks source link

Nix language injection breaks commentstring #7013

Open alxdb opened 1 month ago

alxdb commented 1 month ago

Describe the bug

When using the single comment style of language injection, as introduced in #6418, the nix code between two injections has the incorrect commentstring

foo = # lua
  "foo";
-- baz = {}; <-- comment string is for `lua` should be for `nix`
bar = # lua
  "bar";

To Reproduce

use the above example

Expected behavior

The commentstring should be that of nix

Output of :checkhealth nvim-treesitter

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

Installation ~
- OK `tree-sitter` found 0.22.6 (parser generator, only needed for :TSInstallFromGrammar)
- OK `node` found v20.15.1 (only needed for :TSInstallFromGrammar)
- OK `git` executable found.
- OK `gcc` executable found. Selected from { "gcc", "cc", "gcc", "clang", "cl", "zig" }
  Version: gcc (GCC) 13.3.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.6.33",
  sysname = "Linux",
  version = "#1-NixOS SMP PREEMPT_DYNAMIC Wed Jun 12 09:13:03 UTC 2024"
} ~

Parser/Features         H L F I J
  - ada                 ✓ ✓ ✓ . ✓
  - agda                ✓ . ✓ . ✓
  - angular             ✓ ✓ ✓ ✓ ✓
  - apex                ✓ ✓ ✓ . ✓
  - arduino             ✓ ✓ ✓ ✓ ✓
  - asm                 ✓ . . . ✓
  - astro               ✓ ✓ ✓ ✓ ✓
  - authzed             ✓ . . . ✓
  - awk                 ✓ . . . ✓
  - bash                ✓ ✓ ✓ . ✓
  - bass                ✓ ✓ ✓ ✓ ✓
  - beancount           ✓ . ✓ . ✓
  - bibtex              ✓ . ✓ ✓ ✓
  - bicep               ✓ ✓ ✓ ✓ ✓
  - bitbake             ✓ ✓ ✓ ✓ ✓
  - blueprint           ✓ . . . ✓
  - bp                  ✓ ✓ ✓ ✓ ✓
  - c                   ✓ ✓ ✓ ✓ ✓
  - c_sharp             ✓ ✓ ✓ . ✓
  - cairo               ✓ ✓ ✓ ✓ ✓
  - capnp               ✓ ✓ ✓ ✓ ✓
  - chatito             ✓ ✓ ✓ ✓ ✓
  - clojure             ✓ ✓ ✓ . ✓
  - cmake               ✓ . ✓ ✓ ✓
  - comment             ✓ . . . .
  - commonlisp          ✓ ✓ ✓ . ✓
  - cooklang            ✓ . . . ✓
  - corn                ✓ ✓ ✓ ✓ ✓
  - cpon                ✓ ✓ ✓ ✓ ✓
  - cpp                 ✓ ✓ ✓ ✓ ✓
  - css                 ✓ . ✓ ✓ ✓
  - csv                 ✓ . . . .
  - cuda                ✓ ✓ ✓ ✓ ✓
  - cue                 ✓ ✓ ✓ ✓ ✓
  - d                   ✓ ✓ ✓ ✓ ✓
  - dart                ✓ ✓ ✓ ✓ ✓
  - devicetree          ✓ ✓ ✓ ✓ ✓
  - dhall               ✓ . ✓ . ✓
  - diff                ✓ . . . ✓
  - disassembly         ✓ . . . ✓
  - djot                ✓ ✓ ✓ ✓ ✓
  - dockerfile          ✓ . . . ✓
  - dot                 ✓ . . ✓ ✓
  - doxygen             ✓ . . ✓ ✓
  - dtd                 ✓ ✓ ✓ . ✓
  - earthfile           ✓ . . . ✓
  - ebnf                ✓ . . . ✓
  - editorconfig        ✓ . ✓ . ✓
  - eds                 ✓ . ✓ . .
  - eex                 ✓ . . . ✓
  - elixir              ✓ ✓ ✓ ✓ ✓
  - elm                 ✓ ✓ ✓ . ✓
  - elsa                ✓ ✓ ✓ ✓ ✓
  - elvish              ✓ . . . ✓
  - embedded_template   ✓ . . . ✓
  - erlang              ✓ . ✓ . ✓
  - facility            ✓ . ✓ ✓ ✓
  - faust               ✓ ✓ . . ✓
  - fennel              ✓ ✓ ✓ . ✓
  - fidl                ✓ . ✓ . ✓
  - firrtl              ✓ ✓ ✓ ✓ ✓
  - fish                ✓ ✓ ✓ ✓ ✓
  - foam                ✓ ✓ ✓ ✓ ✓
  - forth               ✓ ✓ ✓ ✓ ✓
  - fortran             ✓ . ✓ ✓ ✓
  - fsh                 ✓ . . . ✓
  - func                ✓ . . . ✓
  - fusion              ✓ ✓ ✓ ✓ ✓
  - gdscript            ✓ ✓ ✓ ✓ ✓
  - gdshader            ✓ . . . ✓
  - git_config          ✓ . ✓ . ✓
  - git_rebase          ✓ . . . ✓
  - gitattributes       ✓ ✓ . . ✓
  - gitcommit           ✓ . . . ✓
  - gitignore           ✓ . . . ✓
  - gleam               ✓ ✓ ✓ ✓ ✓
  - glimmer             ✓ ✓ ✓ ✓ ✓
  - glsl                ✓ ✓ ✓ ✓ ✓
  - gn                  ✓ ✓ ✓ ✓ ✓
  - gnuplot             ✓ ✓ . . ✓
  - go                  ✓ ✓ ✓ ✓ ✓
  - goctl               ✓ . ✓ ✓ ✓
  - godot_resource      ✓ ✓ ✓ . ✓
  - gomod               ✓ . . . ✓
  - gosum               ✓ . . . .
  - gotmpl              ✓ ✓ ✓ . ✓
  - gowork              ✓ . . . ✓
  - gpg                 ✓ . . . ✓
  - graphql             ✓ . . ✓ ✓
  - groovy              ✓ ✓ ✓ ✓ ✓
  - gstlaunch           ✓ . . . .
  - hack                ✓ . . . ✓
  - hare                ✓ ✓ ✓ ✓ ✓
  - haskell             ✓ ✓ ✓ . ✓
  - haskell_persistent  ✓ . ✓ . .
  - hcl                 ✓ . ✓ ✓ ✓
  - heex                ✓ ✓ ✓ ✓ ✓
  - helm                ✓ ✓ ✓ . ✓
  - hjson               ✓ ✓ ✓ ✓ ✓
  - hlsl                ✓ ✓ ✓ ✓ ✓
  - hlsplaylist         ✓ . . . ✓
  - hocon               ✓ . ✓ . ✓
  - hoon                ✓ ✓ ✓ . ✓
  - html                ✓ ✓ ✓ ✓ ✓
  - htmldjango          ✓ . ✓ ✓ ✓
  - http                ✓ . . . ✓
  - hurl                ✓ . ✓ ✓ ✓
  - hyprlang            ✓ . ✓ ✓ ✓
  - idl                 ✓ . . ✓ ✓
  - ini                 ✓ . ✓ . ✓
  - inko                ✓ ✓ ✓ ✓ ✓
  - ispc                ✓ ✓ ✓ ✓ ✓
  - janet_simple        ✓ ✓ ✓ . ✓
  - java                ✓ ✓ ✓ ✓ ✓
  - javascript          ✓ ✓ ✓ ✓ ✓
  - jq                  ✓ ✓ . . ✓
  - jsdoc               ✓ . . . .
  - json                ✓ ✓ ✓ ✓ .
  - json5               ✓ . . . ✓
  - jsonc               ✓ ✓ ✓ ✓ ✓
  - jsonnet             ✓ ✓ ✓ . ✓
  - julia               ✓ ✓ ✓ ✓ ✓
  - just                ✓ ✓ ✓ ✓ ✓
  - kconfig             ✓ ✓ ✓ ✓ ✓
  - kdl                 ✓ ✓ ✓ ✓ ✓
  - kotlin              ✓ ✓ ✓ . ✓
  - koto                ✓ ✓ ✓ . ✓
  - kusto               ✓ . . . ✓
  - lalrpop             ✓ ✓ ✓ . ✓
  - latex               ✓ . ✓ . ✓
  - ledger              ✓ . ✓ ✓ ✓
  - leo                 ✓ . . ✓ ✓
  - linkerscript        ✓ ✓ ✓ ✓ ✓
  - liquid              ✓ . . . ✓
  - liquidsoap          ✓ ✓ ✓ ✓ ✓
  - llvm                ✓ . . . ✓
  - lua                 ✓ ✓ ✓ ✓ ✓
  - luadoc              ✓ . . . .
  - luap                ✓ . . . .
  - luau                ✓ ✓ ✓ ✓ ✓
  - m68k                ✓ ✓ ✓ . ✓
  - make                ✓ . ✓ . ✓
  - markdown            ✓ . ✓ ✓ ✓
  - markdown_inline     ✓ . . . ✓
  - matlab              ✓ ✓ ✓ ✓ ✓
  - menhir              ✓ . . . ✓
  - mermaid             ✓ . . . ✓
  - meson               ✓ . ✓ ✓ ✓
  - mlir                ✓ ✓ . . ✓
  - muttrc              ✓ . . . ✓
  - nasm                ✓ . . . ✓
  - nginx               ✓ . ✓ . ✓
  - nickel              ✓ . . ✓ ✓
  - nim                 ✓ ✓ ✓ . ✓
  - nim_format_string   ✓ . . . ✓
  - ninja               ✓ . ✓ ✓ ✓
  - nix                 ✓ ✓ ✓ ✓ ✓
  - norg                . . . . .
  - nqc                 ✓ ✓ ✓ ✓ ✓
  - objc                ✓ ✓ ✓ ✓ ✓
  - objdump             ✓ . . . ✓
  - ocaml               ✓ ✓ ✓ ✓ ✓
  - ocaml_interface     ✓ ✓ ✓ ✓ ✓
  - ocamllex            ✓ . . . ✓
  - odin                ✓ ✓ ✓ ✓ ✓
  - org                 ✓ . . . .
  - pascal              ✓ ✓ ✓ ✓ ✓
  - passwd              ✓ . . . .
  - pem                 ✓ . ✓ . ✓
  - perl                ✓ . ✓ . ✓
  - php                 ✓ ✓ ✓ ✓ ✓
  - php_only            ✓ ✓ ✓ ✓ ✓
  - phpdoc              ✓ . . . .
  - pioasm              ✓ . . . ✓
  - po                  ✓ . ✓ . ✓
  - pod                 ✓ . . . .
  - poe_filter          ✓ . ✓ ✓ ✓
  - pony                ✓ ✓ ✓ ✓ ✓
  - powershell          ✓ ✓ ✓ ✓ ✓
  - printf              ✓ . . . .
  - prisma              ✓ . ✓ . ✓
  - problog             ✓ . ✓ ✓ ✓
  - prolog              ✓ . ✓ ✓ ✓
  - promql              ✓ . . . ✓
  - properties          ✓ ✓ . . ✓
  - proto               ✓ . ✓ . ✓
  - prql                ✓ . . . ✓
  - psv                 ✓ . . . .
  - pug                 ✓ . . . ✓
  - puppet              ✓ ✓ ✓ ✓ ✓
  - purescript          ✓ ✓ . . ✓
  - pymanifest          ✓ . . . ✓
  - python              ✓ ✓ ✓ ✓ ✓
  - ql                  ✓ ✓ ✓ ✓ ✓
  - qmldir              ✓ . . . ✓
  - qmljs               ✓ ✓ ✓ . ✓
  - query               ✓ ✓ ✓ ✓ ✓
  - r                   ✓ ✓ . ✓ ✓
  - racket              ✓ ✓ ✓ . ✓
  - ralph               ✓ . . . ✓
  - rasi                ✓ ✓ ✓ ✓ ✓
  - rbs                 ✓ . ✓ ✓ ✓
  - re2c                ✓ ✓ ✓ ✓ ✓
  - readline            ✓ . ✓ ✓ ✓
  - regex               ✓ . . . .
  - rego                ✓ ✓ . . ✓
  - requirements        ✓ . . . ✓
  - rnoweb              ✓ . ✓ . ✓
  - robot               ✓ . ✓ ✓ ✓
  - robots              ✓ . . . ✓
  - roc                 ✓ ✓ . ✓ ✓
  - ron                 ✓ ✓ ✓ ✓ ✓
  - rst                 ✓ ✓ . . ✓
  - ruby                ✓ ✓ ✓ ✓ ✓
  - rust                ✓ ✓ ✓ ✓ ✓
  - scala               ✓ ✓ ✓ . ✓
  - scfg                ✓ . . . ✓
  - scheme              ✓ . ✓ . ✓
  - scss                ✓ . ✓ ✓ ✓
  - slang               ✓ ✓ ✓ ✓ ✓
  - slint               ✓ ✓ ✓ ✓ ✓
  - smali               ✓ ✓ ✓ ✓ ✓
  - smithy              ✓ . . . ✓
  - snakemake           ✓ ✓ ✓ ✓ ✓
  - solidity            ✓ ✓ ✓ . ✓
  - soql                ✓ . . . .
  - sosl                ✓ . . . .
  - sourcepawn          ✓ ✓ . . ✓
  - sparql              ✓ ✓ ✓ ✓ ✓
  - sql                 ✓ . . ✓ ✓
  - squirrel            ✓ ✓ ✓ ✓ ✓
  - ssh_config          ✓ ✓ ✓ ✓ ✓
  - starlark            ✓ ✓ ✓ ✓ ✓
  - strace              ✓ . . . ✓
  - styled              ✓ . ✓ ✓ ✓
  - supercollider       ✓ ✓ ✓ ✓ ✓
  - surface             ✓ . ✓ ✓ ✓
  - svelte              ✓ ✓ ✓ ✓ ✓
  - swift               ✓ ✓ . ✓ ✓
  - sxhkdrc             ✓ . ✓ . ✓
  - systemtap           ✓ ✓ ✓ . ✓
  - systemverilog       ✓ . ✓ . ✓
  - t32                 ✓ ✓ ✓ ✓ ✓
  - tablegen            ✓ ✓ ✓ ✓ ✓
  - tact                ✓ ✓ ✓ ✓ ✓
  - tcl                 ✓ . ✓ ✓ ✓
  - teal                ✓ ✓ ✓ ✓ ✓
  - templ               ✓ . ✓ . ✓
  - terraform           ✓ . ✓ ✓ ✓
  - textproto           ✓ . ✓ ✓ ✓
  - thrift              ✓ ✓ ✓ ✓ ✓
  - tiger               ✓ ✓ ✓ ✓ ✓
  - tlaplus             ✓ ✓ ✓ . ✓
  - tmux                ✓ . . . ✓
  - todotxt             ✓ . . . .
  - toml                ✓ ✓ ✓ ✓ ✓
  - tsv                 ✓ . . . .
  - tsx                 ✓ ✓ ✓ ✓ ✓
  - turtle              ✓ ✓ ✓ ✓ ✓
  - twig                ✓ . . . ✓
  - typescript          ✓ ✓ ✓ ✓ ✓
  - typespec            ✓ . . ✓ ✓
  - typoscript          ✓ . ✓ ✓ ✓
  - typst               ✓ . ✓ ✓ ✓
  - udev                ✓ ✓ . . ✓
  - ungrammar           ✓ ✓ ✓ ✓ ✓
  - unison              ✓ . . . ✓
  - usd                 ✓ ✓ ✓ ✓ ✓
  - uxntal              ✓ ✓ ✓ ✓ ✓
  - v                   ✓ ✓ ✓ ✓ ✓
  - vala                ✓ ✓ ✓ . ✓
  - vento               ✓ . . . ✓
  - verilog             ✓ ✓ ✓ . ✓
  - vhdl                ✓ . ✓ . ✓
  - vhs                 ✓ . . . ✓
  - vim                 ✓ ✓ ✓ . ✓
  - vimdoc              ✓ . . . ✓
  - vue                 ✓ . ✓ ✓ ✓
  - wgsl                ✓ . ✓ ✓ ✓
  - wgsl_bevy           ✓ . ✓ ✓ .
  - wing                ✓ ✓ ✓ . ✓
  - wit                 ✓ . ✓ . ✓
  - xcompose            ✓ ✓ . . ✓
  - xml                 ✓ ✓ ✓ ✓ ✓
  - yaml                ✓ ✓ ✓ ✓ ✓
  - yang                ✓ . ✓ ✓ ✓
  - yuck                ✓ ✓ ✓ ✓ ✓
  - zathurarc           ✓ . . . ✓
  - zig                 ✓ ✓ ✓ ✓ ✓

  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.1
Build type: Release
LuaJIT 2.1.1713773202
Run "nvim -V1 -v" for more info

Additional context

No response

clason commented 1 month ago

Does it work if you add empty lines between them?

(This is another instance of @injection.combined fixing some things while breaking others...)

alxdb commented 1 month ago

It doesn't make a difference, just tried with the following example:

{
  foo = # lua
    "foo";

  -- bax = { };

  bar = # lua
    "bar";
}
clason commented 1 month ago

If you look at :InspectTree, you see a bunch of parsing(ERROR)` nodes. Can you give an example snippet that parses correctly and has the same issue?

alxdb commented 1 month ago
{
  foo = # lua
    ''require("foo")'';
  baz = { };
  bar = # lua
    ''require("bar")'';
}

^ This has no errors before commenting out baz (using commentstring ofc, not just with #).

ribru17 commented 1 month ago

This will be fixed if https://github.com/neovim/neovim/pull/29601 is ever merged, but it depends on an upstream consensus