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

Duplicate captures #6167

Closed
alexmozaidze opened this issue Feb 21, 2024 · 1 comment
Closed

Duplicate captures #6167

alexmozaidze opened this issue Feb 21, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@alexmozaidze
Copy link
Contributor

alexmozaidze commented Feb 21, 2024

Describe the bug

Some queries can cause duplicate captures. The strange part is that the amount of duplicate captures depends on the contents of the query (see reproduction steps).

This issue is both on latest Nightly (at the time of writing) and Stable (v0.9.5).

To Reproduce

  1. Open a Fennel file (*.fnl)
  2. Run :TSEditQuery highlights and remove every single query (for cleaner output)
  3. Add the following query to the now empty highlights.scm:
(list
  .
  (symbol) @function.macro
  (#eq? @function.macro "augroup!")
  (sequence
    .
    (sequence
      (symbol) @constant)
    .
    [
      (sequence
        (symbol) @string)
      ((symbol) @string)
      (multi_symbol
        _ @string)
    ]
    .
    (_)))
  1. Put the following contents into the Fennel file:
Fennel file
(import-macros {: setlocal! : set! : augroup!} :hibiscus.vim)

(augroup! :ft-indent
  [[FileType]
   [vim
    html
    tex
    htmx
    php
    vue
    json
    jsonc
    json5
    hjson
    yaml
    yml
    toml
    css
    scss
    sass]
   #(setlocal! tabstop 2)]
  ;; 3 space indentation lines up nicely with `if` statements
  [[FileType] [lua go] #(setlocal! tabstop 3)]
  [[FileType] [lisp markdown] #(setlocal! expandtab)])

(augroup! :ft-opt
  [[FileType]
   [markdown norg]
   (λ []
     (setlocal! wrap)
     (setlocal! colorcolumn :0))]
  [[FileType]
   [fennel lisp]
   #(set! commentstring ";;%s")]
  [[FileType] janet #(set! lisp)]
  [[FileType] snippets #(setlocal! nofoldenable)])

(augroup! :adaptive-cmd-height
  [[VimEnter VimResized] *
   #(set! cmdheight (if (< 80 vim.o.columns) 1 2))])

(augroup! :highlight-yanked-text
  [[TextYankPost] *
   #(vim.highlight.on_yank {:higroup "Visual"
                            :timeout 350})])

(let [template (require :template)
      {: buffer-empty?} (require :utils)]
  (augroup! :cmp-file-templates
    [[BufNewFile BufRead] * #(if (buffer-empty?)
                                 (template.expand))]))

(augroup! :term-stuff
  [[TermOpen] *
   (λ []
     (setlocal! nonumber)
     (setlocal! norelativenumber))])
  1. Run :e
  2. Move the cursor over to augroup! or FileType and run :Inspect
  3. Observe the duplicate highlight captures

You can also comment out the complex portion of the query and see that there are no more duplicate captures:

(list
  .
  (symbol) @function.macro
  (#eq? @function.macro "augroup!")
  ; (sequence
  ;   .
  ;   (sequence
  ;     (symbol) @constant)
  ;   .
  ;   [
  ;     (sequence
  ;       (symbol) @string)
  ;     ((symbol) @string)
  ;     (multi_symbol
  ;       _ @string)
  ;   ]
  ;   .
  ;   (_))
  )

Expected behavior

There are no duplicate captures.

Output of :checkhealth nvim-treesitter

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

Installation ~
- OK `tree-sitter` found 0.20.8 (parser generator, only needed for :TSInstallFromGrammar)
- OK `node` found v20.11.1 (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 = "5.15.0-94-generic",
  sysname = "Linux",
  version = "#104-Ubuntu SMP Tue Jan 9 15:25:40 UTC 2024"
} ~

Parser/Features         H L F I J
  - bash                ✓ ✓ ✓ . ✓
  - c                   ✓ ✓ ✓ ✓ ✓
  - comment             ✓ . . . .
  - fennel              ✓ ✓ ✓ . ✓
  - html                ✓ ✓ ✓ ✓ ✓
  - javascript          ✓ ✓ ✓ ✓ ✓
  - lua                 ✓ ✓ ✓ ✓ ✓
  - luap                ✓ . . . .
  - markdown            ✓ . ✓ ✓ ✓
  - markdown_inline     ✓ . . . ✓
  - printf              ✓ . . . .
  - python              ✓ ✓ ✓ ✓ ✓
  - query               ✓ ✓ ✓ ✓ ✓
  - 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

Nightly
=======

NVIM v0.10.0-dev-2407+g9bb046d1b
Build type: RelWithDebInfo
LuaJIT 2.1.1707061634
Run "nvim -V1 -v" for more info

Stable
======

NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1692716794

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/__w/neovim/neovim/build/nvim.AppDir/usr/share/nvim"

Run :checkhealth for more info

Additional context

When the query from the "reproduction steps" is used along with all the other queries, there is flickering similar to what happens in #871.

There's a chance that there is an incorrect handling of anchors (.) in the queries on core Neovim side, but I am not sure.

@alexmozaidze alexmozaidze added the bug Something isn't working label Feb 21, 2024
@clason
Copy link
Contributor

clason commented Feb 21, 2024

Please open this issue at neovim/neovim (or possibly tree-sitter/tree-sitter, if you can reproduce it with their playground).

Also note that the playground is deprecated; use :InspectTree and :EditQuery instead.

@clason clason closed this as not planned Won't fix, can't repro, duplicate, stale Feb 21, 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
Projects
None yet
Development

No branches or pull requests

2 participants