nvim-treesitter / nvim-treesitter

Nvim Treesitter configurations and abstraction layer
Apache License 2.0
10.83k stars 900 forks source link

`:TSBufEnable highlight` doesn't work #2754

Closed TornaxO7 closed 2 years ago

TornaxO7 commented 2 years ago

Describe the highlighting problem

I've disabled the highlight module per default since neovim needs a lot of time for loading very big files which can get a little bit annoying, so I wanted to start treesitter with the :TSBufEnable highlight command. However this the highlighting colors don't change after calling this command.

Example snippet that causes the problem

#include <stdio.h>
#include <stdlib.h>

int main() {
    printf("Hello there!\n");
    return 0;
}

Tree-sitter parsing result

preproc_include [0, 0] - [1, 0]
  "#include" [0, 0] - [0, 8]
  path: system_lib_string [0, 9] - [0, 18]
  "\n" [0, 18] - [1, 0]
preproc_include [1, 0] - [3, 0]
  "#include" [1, 0] - [1, 8]
  path: system_lib_string [1, 9] - [1, 19]
  "\n" [1, 19] - [3, 0]
function_definition [3, 0] - [6, 1]
  type: primitive_type [3, 0] - [3, 3]
  declarator: function_declarator [3, 4] - [3, 10]
    declarator: identifier [3, 4] - [3, 8]
    parameters: parameter_list [3, 8] - [3, 10]
      "(" [3, 8] - [3, 9]
      ")" [3, 9] - [3, 10]
  body: compound_statement [3, 11] - [6, 1]
    "{" [3, 11] - [3, 12]
    expression_statement [4, 4] - [4, 29]
      call_expression [4, 4] - [4, 28]
        function: identifier [4, 4] - [4, 10]
        arguments: argument_list [4, 10] - [4, 28]
          "(" [4, 10] - [4, 11]
          string_literal [4, 11] - [4, 27]
            """ [4, 11] - [4, 12]
            escape_sequence [4, 24] - [4, 26]
            """ [4, 26] - [4, 27]
          ")" [4, 27] - [4, 28]
      ";" [4, 28] - [4, 29]
    return_statement [5, 4] - [5, 13]
      "return" [5, 4] - [5, 10]
      number_literal [5, 11] - [5, 12]
      ";" [5, 12] - [5, 13]
    "}" [6, 0] - [6, 1]

Example screenshot

https://user-images.githubusercontent.com/50843046/162347026-05ebb176-6193-43d9-8a50-2b8cda5323f8.mp4

As you can see, nothing happens after calling the :TSBufEnable highlight command.

Expected behavior

Screenshot

I expected to get this highlighting after calling the :TSBufEnable highlight command.

Output of :checkhealth nvim-treesitter

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

## Parser/Features H L F I J
  - scala          ✓ . ✓ . ✓ 
  - surface        ✓ . ✓ ✓ ✓ 
  - pioasm         ✓ . . . ✓ 
  - eex            ✓ . . . ✓ 
  - scss           ✓ . . ✓ . 
  - heex           ✓ ✓ ✓ ✓ ✓ 
  - graphql        ✓ . . ✓ ✓ 
  - vue            ✓ . ✓ ✓ ✓ 
  - ocaml_interface✓ ✓ ✓ . ✓ 
  - ocamllex       ✓ . . . ✓ 
  - query          ✓ ✓ ✓ ✓ ✓ 
  - yaml           ✓ ✓ ✓ ✓ ✓ 
  - zig            ✓ . ✓ ✓ ✓ 
  - supercollider  ✓ ✓ ✓ ✓ ✓ 
  - toml           ✓ ✓ ✓ ✓ ✓ 
  - typescript     ✓ ✓ ✓ ✓ ✓ 
  - tsx            ✓ ✓ ✓ ✓ ✓ 
  - vala           ✓ . . . . 
  - tlaplus        ✓ ✓ ✓ . ✓ 
  - lalrpop        ✓ ✓ . . . 
  - ruby           ✓ ✓ ✓ ✓ ✓ 
  - javascript     ✓ ✓ ✓ ✓ ✓ 
  - cooklang       ✓ . . . . 
  - norg           . . . . . 
  - pug            ✓ . . . ✓ 
  - elvish         ✓ . . . ✓ 
  - solidity       ✓ . . . . 
  - astro          ✓ ✓ ✓ ✓ ✓ 
  - jsonc          ✓ ✓ ✓ ✓ ✓ 
  - kotlin         ✓ ✓ ✓ . ✓ 
  - rasi           ✓ ✓ ✓ ✓ . 
  - rego           ✓ . . . ✓ 
  - make           ✓ . . . ✓ 
  - yang           ✓ . ✓ . . 
  - prisma         ✓ . . . . 
  - http           ✓ . . . ✓ 
  - ninja          ✓ . ✓ ✓ . 
  - llvm           ✓ . . . . 
  - commonlisp     ✓ ✓ ✓ . . 
  - hocon          ✓ . . . ✓ 
  - hjson          ✓ ✓ ✓ ✓ ✓ 
  - json5          ✓ . . . ✓ 
  - regex          ✓ . . . . 
  - cuda           ✓ ✓ ✓ ✓ ✓ 
  - glsl           ✓ ✓ ✓ ✓ ✓ 
  - python         ✓ ✓ ✓ ✓ ✓ 
  - go             ✓ ✓ ✓ ✓ ✓ 
  - julia          ✓ ✓ ✓ ✓ ✓ 
  - dockerfile     ✓ . . . ✓ 
  - nix            ✓ ✓ ✓ . ✓ 
  - gomod          ✓ . . . ✓ 
  - clojure        ✓ ✓ ✓ . ✓ 
  - latex          ✓ . ✓ . ✓ 
  - hcl            ✓ . ✓ ✓ ✓ 
  - fusion         ✓ ✓ ✓ ✓ . 
  - r              ✓ ✓ . ✓ ✓ 
  - svelte         ✓ . ✓ ✓ ✓ 
  - ledger         ✓ . ✓ ✓ ✓ 
  - jsdoc          ✓ . . . . 
  - java           ✓ ✓ . ✓ ✓ 
  - ql             ✓ ✓ . ✓ ✓ 
  - cpp            ✓ ✓ ✓ ✓ ✓ 
  - php            ✓ ✓ ✓ ✓ ✓ 
  - sparql         ✓ ✓ ✓ ✓ ✓ 
  - glimmer        ✓ . . . . 
  - gdscript       ✓ ✓ . ✓ ✓ 
  - perl           ✓ . ✓ . . 
  - css            ✓ . ✓ ✓ ✓ 
  - gowork         ✓ . . . ✓ 
  - godot_resource ✓ ✓ ✓ . . 
  - comment        ✓ . . . . 
  - dart           ✓ ✓ . ✓ ✓ 
  - pascal         ✓ ✓ ✓ ✓ ✓ 
  - turtle         ✓ ✓ ✓ ✓ ✓ 
  - teal           ✓ ✓ ✓ ✓ ✓ 
  - devicetree     ✓ ✓ ✓ ✓ ✓ 
  - rst            ✓ ✓ . . ✓ 
  - json           ✓ ✓ ✓ ✓ . 
  - vim            ✓ ✓ . . ✓ 
  - c              ✓ ✓ ✓ ✓ ✓ 
  - beancount      ✓ . ✓ . . 
  - elixir         ✓ ✓ ✓ ✓ ✓ 
  - bash           ✓ ✓ ✓ . ✓ 
  - erlang         . . . . . 
  - dot            ✓ . . . ✓ 
  - bibtex         ✓ . ✓ ✓ . 
  - fish           ✓ ✓ ✓ ✓ ✓ 
  - ocaml          ✓ ✓ ✓ . ✓ 
  - c_sharp        ✓ ✓ ✓ . ✓ 
  - fennel         ✓ ✓ . . ✓ 
  - cmake          ✓ . ✓ . . 
  - lua            ✓ ✓ ✓ ✓ ✓ 
  - rust           ✓ ✓ ✓ ✓ ✓ 
  - html           ✓ ✓ ✓ ✓ ✓ 
  - gleam          ✓ ✓ ✓ ✓ ✓ 

  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.7.0-dev+1406-g8c25dbff4
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
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 -DNVIM_TS_HAS_SET_MATCH_LIMIT -DNVIM_TS_HAS_SET_ALLOCATOR -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wdouble-promotion -Wmissing-noreturn -Wmissing-format-attribute -Wmissing-prototypes -Wimplicit-fallthrough -Wsuggest-attribute=pure -Wsuggest-attribute=const -Wsuggest-attribute=malloc -Wsuggest-attribute=cold -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/tornax/.cache/yay/neovim-git/src/build/config -I/home/tornax/.cache/yay/neovim-git/src/neovim-git/src -I/usr/include -I/home/tornax/.cache/yay/neovim-git/src/build/src/nvim/auto -I/home/tornax/.cache/yay/neovim-git/src/build/include
Compiled by tornax

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

None

TornaxO7 commented 2 years ago

Ok, I found another thing out:

If you run :TSEnableAll highlight and then :e, the highlighting shows up as expected but calling :e after invoking :TSBufEnable highlight doesn't work.