nvim-treesitter / nvim-treesitter

Nvim Treesitter configurations and abstraction layer
Apache License 2.0
10.63k stars 889 forks source link

Export macro causes incorrect syntax highlighting in C++ #1387

Closed Shatur closed 3 years ago

Shatur commented 3 years ago

Describe the bug

The following code will have wrong colors:

class EXPORT_API MyClass
{
    MyClass();
};

Where EXPORT_API is a macro that is used to export class functions to DLLs on Windows on Windows and expands to nothing on Linux.

Expected behavior

It would be awesome to handle this case and highlight EXPORT_API as a macro and MyClass as a class in this case.

Output of :checkhealth nvim_treesitter

health#nvim_treesitter#check ======================================================================== ## Installation - OK: `tree-sitter` found 0.19.4 (parser generator, only needed for :TSInstallFromGrammar) - OK: `node` found v16.3.0 (only needed for :TSInstallFromGrammar) - OK: `git` executable found. - OK: `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl" } - 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 - latex ✓ . ✓ . . - c_sharp ✓ . ✓ . ✓ - zig ✓ ✓ ✓ ✓ ✓ - svelte ✓ . ✓ ✓ ✓ - beancount ✓ . ✓ . . - bibtex ✓ . ✓ ✓ . - c ✓ ✓ ✓ ✓ ✓ - teal ✓ ✓ ✓ ✓ ✓ - java ✓ ✓ . ✓ ✓ - python ✓ ✓ ✓ ✓ ✓ - r ✓ ✓ . . . - sparql ✓ ✓ ✓ ✓ ✓ - comment ✓ . . . . - gomod ✓ . . . . - dart ✓ ✓ . ✓ ✓ - lua ✓ ✓ ✓ ✓ ✓ - devicetree ✓ ✓ ✓ ✓ ✓ - ocaml ✓ ✓ ✓ . ✓ - go ✓ ✓ ✓ ✓ ✓ - regex ✓ . . . . - scss ✓ . . ✓ . - yaml ✓ ✓ ✓ ✓ ✓ - json ✓ ✓ ✓ ✓ . - jsdoc ✓ . . . . - ledger ✓ . ✓ ✓ ✓ - php ✓ ✓ ✓ ✓ ✓ - julia ✓ ✓ ✓ . ✓ - supercollider ✓ ✓ ✓ ✓ ✓ - gdscript ✓ ✓ . . ✓ - query ✓ ✓ ✓ ✓ ✓ - turtle ✓ ✓ ✓ ✓ ✓ - verilog ✓ ✓ ✓ . ✓ - html ✓ ✓ ✓ ✓ ✓ - typescript ✓ ✓ ✓ ✓ ✓ - ql ✓ ✓ . ✓ ✓ - fennel ✓ ✓ . . ✓ - jsonc ✓ ✓ ✓ ✓ ✓ - rst ✓ ✓ . . ✓ - nix ✓ ✓ ✓ . ✓ - vue ✓ . ✓ . ✓ - graphql ✓ . . ✓ ✓ - elixir ✓ ✓ . ✓ ✓ - toml ✓ ✓ ✓ ✓ ✓ - cpp ✓ ✓ ✓ ✓ ✓ - kotlin ✓ . . . ✓ - ruby ✓ ✓ ✓ ✓ ✓ - fish ✓ ✓ ✓ ✓ ✓ - ocamllex ✓ . . . ✓ - dockerfile ✓ . . . ✓ - rust ✓ ✓ ✓ ✓ ✓ - ocaml_interface✓ ✓ ✓ . ✓ - bash ✓ ✓ ✓ . ✓ - javascript ✓ ✓ ✓ ✓ ✓ - css ✓ . ✓ ✓ ✓ - glimmer ✓ . . . . - erlang . . . . . - clojure ✓ ✓ ✓ . ✓ - commonlisp ✓ ✓ ✓ . . - tsx ✓ ✓ ✓ ✓ ✓ Legend: H[ighlight], L[ocals], F[olds], I[ndents] +) multiple parsers found, only one will be used x) errors found in the query, try to run :TSUpdate {lang} Paste the output here

Output of nvim --version

NVIM v0.5.0-dev+1401-g12d8ff7cc Build type: RelWithDebInfo LuaJIT 2.0.5 Compilation: /usr/bin/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 -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/gena/.cache/paru/clone/neovim-git/src/build/config -I/home/gena/.cache/paru/clone/neovim-git/src/neovim-git/src -I/usr/include -I/home/gena/.cache/paru/clone/neovim-git/src/build/src/nvim/auto -I/home/gena/.cache/paru/clone/neovim-git/src/build/include Скомпилирован gena@AcerAspire5 Features: +acl +iconv +tui See ":help feature-compile" общесистемный файл vimrc: "$VIM/sysinit.vim" значение $VIM по умолчанию: "/usr/share/nvim" Run :checkhealth for more info
theHamsta commented 3 years ago

Please open this bug at tree-sitter-cpp! I guess it is already reported.

As a side-note: for tree-sitter-cuda a similar problem arose with device annotation in front of functions when using tree-sitter-cpp. This was one of the reasons apart from the kernel call syntax <<< why i created this parser extension. It might also be an opportunity for you to apply a work around locally in the grammar.js of tree-sitter-cpp

Shatur commented 3 years ago

Please open this bug at tree-sitter-cpp! I guess it is already reported.

Did non know, thank you! The issue https://github.com/tree-sitter/tree-sitter-cpp/issues/85 looks similar, but it for a macro before class. Should I create a separate issue?