nvim-treesitter / nvim-treesitter

Nvim Treesitter configurations and abstraction layer
Apache License 2.0
10.47k stars 878 forks source link

[fennel locals] quoted symbols should not be taken into account as locals #2038

Open p00f opened 2 years ago

p00f commented 2 years ago

Before reporting

Describe the bug

image quoted symbol n is highlighted by the refactor.highlight_defintions module

To Reproduce

N/A

Expected behavior

quoted symbols and not-unquoted symbols in quoted lists should not be taken into account for locals

Output of :checkhealth nvim-treesitter

nvim-treesitter: require("nvim-treesitter.health").check()
========================================================================
## Installation
  - OK: `tree-sitter` found  0.20.0 (parser generator, only needed for :TSInstallFromGrammar)
  - OK: `node` found v17.1.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) 11.1.0
  - OK: Neovim was compiled with tree-sitter runtime ABI version 13 (required >=13). Parsers must be compatible with runtime ABI.

## Parser/Features H L F I J
  - ocaml_interface✓ ✓ ✓ . ✓ 
  - beancount      ✓ . ✓ . . 
  - python         ✓ ✓ ✓ ✓ ✓ 
  - sparql         ✓ ✓ ✓ ✓ ✓ 
  - comment        ✓ . . . . 
  - lua            ✓ ✓ ✓ ✓ ✓ 
  - ocaml          ✓ ✓ ✓ . ✓ 
  - go             ✓ ✓ ✓ ✓ ✓ 
  - ql             ✓ ✓ . ✓ ✓ 
  - glsl           ✓ ✓ ✓ ✓ ✓ 
  - json           ✓ ✓ ✓ ✓ . 
  - jsdoc          ✓ . . . . 
  - ledger         ✓ . ✓ ✓ ✓ 
  - php            ✓ ✓ ✓ ✓ ✓ 
  - clojure        ✓ ✓ ✓ . ✓ 
  - supercollider  ✓ ✓ ✓ ✓ ✓ 
  - heex           ✓ . ✓ ✓ ✓ 
  - typescript     ✓ ✓ ✓ ✓ ✓ 
  - fennel         ✓ ✓ . . ✓ 
  - query          ✓ ✓ ✓ ✓ ✓ 
  - cpp            ✓ ✓ ✓ ✓ ✓ 
  - vue            ✓ . ✓ ✓ ✓ 
  - latex          ✓ . ✓ . ✓ 
  - rst            ✓ ✓ . . ✓ 
  - css            ✓ . ✓ ✓ ✓ 
  - glimmer        ✓ . . . . 
  - erlang         . . . . . 
  - regex          ✓ . . . . 
  - svelte         ✓ . ✓ ✓ ✓ 
  - c              ✓ ✓ ✓ ✓ ✓ 
  - teal           ✓ ✓ ✓ ✓ ✓ 
  - java           ✓ ✓ . ✓ ✓ 
  - hjson          ✓ ✓ ✓ ✓ ✓ 
  - gomod          ✓ . . . . 
  - dart           ✓ ✓ . ✓ ✓ 
  - bash           ✓ ✓ ✓ . ✓ 
  - http           ✓ . . . ✓ 
  - yaml           ✓ ✓ ✓ ✓ ✓ 
  - llvm           ✓ . . . . 
  - pioasm         ✓ . . . ✓ 
  - json5          ✓ . . . ✓ 
  - vim            ✓ ✓ . . ✓ 
  - julia          ✓ ✓ ✓ ✓ ✓ 
  - cmake          ✓ . ✓ . . 
  - zig            ✓ . ✓ ✓ ✓ 
  - bibtex         ✓ . ✓ ✓ . 
  - turtle         ✓ ✓ ✓ ✓ ✓ 
  - r              ✓ ✓ . . . 
  - toml           ✓ ✓ ✓ ✓ ✓ 
  - devicetree     ✓ ✓ ✓ ✓ ✓ 
  - godotResource  ✓ ✓ ✓ . . 
  - gdscript       ✓ ✓ . . ✓ 
  - yang           ✓ . ✓ . . 
  - tsx            ✓ ✓ ✓ ✓ ✓ 
  - surface        ✓ . ✓ ✓ ✓ 
  - swift          . . . . . 
  - javascript     ✓ ✓ ✓ ✓ ✓ 
  - nix            ✓ ✓ ✓ . ✓ 
  - dot            ✓ . . . ✓ 
  - elixir         ✓ ✓ ✓ ✓ ✓ 
  - cuda           ✓ ✓ ✓ ✓ ✓ 
  - c_sharp        ✓ ✓ ✓ . ✓ 
  - commonlisp     ✓ ✓ ✓ . . 
  - kotlin         ✓ . . . ✓ 
  - ruby           ✓ ✓ ✓ ✓ ✓ 
  - fish           ✓ ✓ ✓ ✓ ✓ 
  - ocamllex       ✓ . . . ✓ 
  - scala          ✓ . ✓ . ✓ 
  - dockerfile     ✓ . . . ✓ 
  - rust           ✓ ✓ ✓ ✓ ✓ 
  - haskell        ✓ . . . ✓ 
  - perl           ✓ . . . . 
  - tlaplus        ✓ . ✓ . ✓ 
  - jsonc          ✓ ✓ ✓ ✓ ✓ 
  - html           ✓ ✓ ✓ ✓ ✓ 
  - graphql        ✓ . . ✓ ✓ 
  - elm            . . . . . 
  - scss           ✓ . . ✓ . 
  - hcl            ✓ . ✓ ✓ ✓ 

  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.6.0-dev+616-ge05db65d2a
Build type: RelWithDebInfo
LuaJIT 2.0.5
Compilation: /usr/sbin/cc -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions     -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security     -fstack-clash-protection -fcf-protection -Wp,-U_FORTIFY_SOURCE -Wp,-D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/home/main-builder/pkgwork/src/build/config -I/home/main-builder/pkgwork/src/neovim-git/src -I/usr/include -I/home/main-builder/pkgwork/src/build/src/nvim/auto -I/home/main-builder/pkgwork/src/build/include
Compiled by main-builder

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

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

Run :checkhealth for more info

Additional context

No response

stsewd commented 2 years ago

Currently all symbols are taken as references https://github.com/nvim-treesitter/nvim-treesitter/blob/1d66657e6d0f1f8f79ddc48ff1dac9788694cc2d/queries/fennel/locals.scm#L24-L24

Is a quoted symbol nothing related to a variable/reference? or is it just a like a different subset? I'm not familiar with fennel, so not sure the correct solution here.

p00f commented 2 years ago

Quoted symbols are inserted as-it-is at the time of macro expansion For example compare the expansion of p1 and p2

image p1 expands to (print n) because n is inside the quoted form

`(print n)

image

p2 expands to (print 1) because n is unquoted and gets replaced by the actual argument given (n=1)

`(print ,n)

i.e. a quoted variable is not the same as the argument

From https://fennel-lang.org/macros

Symbols inside a quoted form remain as symbols. Symbols in an unquoted form (like ,condition and ,body above) are evaluated meaning they are replaced with whatever value they have in the code at that point.