vigoux / tree-sitter-viml

Tree-sitter parser for VimL
MIT License
74 stars 22 forks source link

Problem when highlighting syntax in the VimScript file. #140

Open tranmanhlt7a4 opened 1 year ago

tranmanhlt7a4 commented 1 year ago

Describe the highlighting problem

In my init.vim file, I recognized some weird problems: Firstly, in some places, especially after an open bracket (like {, ...), strings will not be highlighted unless I have a space between them. And it's so weird because other strings are not affected.

As you can see below, the string branch and do do not be highlighted image But when I add a space between them, it works correctly image And this bracket is not affected image

Secondly, like the problem above, comments are not highlighted in some places. This problem only happens with comments in the rest of a line (comment in one line) and after it (in the new line and have a same indentation) have another code (all other lines are fine). image As you see above, comments in the whole line like Theme, Status bar; comments don't have any code in the same indent after them like Better theme for barbar and comments followed by the line of code with different indent like Show information of the last commit is not affected, but comments in rest of the line and have a code with the same indent after them like Git information, Git show changes are not highlighted.

Example snippet that causes the problem

    Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}  " the string 'do' have a problem
    Plug 'nvim-treesitter/nvim-treesitter', { 'do': ':TSUpdate'}  " when I add a space between '{' and 'do', it works well.

Tree-sitter parsing result

user_command [0, 0] - [0, 59] vim
  command_name [0, 0] - [0, 4] vim
  arguments [0, 5] - [0, 59] vim
    command_argument [0, 5] - [0, 38] vim
      string_literal [0, 5] - [0, 38] vim
    command_argument [0, 38] - [0, 39] vim
    command_argument [0, 40] - [0, 46] vim
    command_argument [0, 47] - [0, 58] vim
      string_literal [0, 47] - [0, 58] vim
    command_argument [0, 58] - [0, 59] vim

Example screenshot

My colorscheme is oxocarbon (here is the link: https://github.com/nyoom-engineering/oxocarbon.nvim) I installed that theme with vim-plug (here is the link: https://github.com/junegunn/vim-plug)

When I use :TSHighlightCapturesUnderCursor for parts that have the problem, it showed a message (the same with comments) No highlight groups found image

Expected behavior

All comments and strings will be highlighted correctly.

Output of :checkhealth nvim-treesitter

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

Installation ~
- OK `tree-sitter` found 0.20.7 (b268e412ad4848380166af153300464e5a1cf83f) (parser generator, only needed for :TSInstallFromGrammar)
- OK `node` found v18.12.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.3.0-1ubuntu1~22.04) 11.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 = "5.15.83.1-microsoft-standard-WSL2",
  sysname = "Linux",
  version = "#1 SMP Wed Dec 14 23:16:32 UTC 2022"
} ~

Parser/Features         H L F I J
  - c                   ✓ ✓ ✓ ✓ ✓
  - regex               ✓ . . . .
  - markdown_inline     ✓ . . . ✓
  - help                ✓ . . . ✓
  - query               ✓ ✓ ✓ ✓ ✓
  - diff                ✓ . . . .
  - vim                 ✓ ✓ ✓ . ✓
  - gitignore           ✓ . . . .
  - lua                 ✓ ✓ ✓ ✓ ✓
  - java                ✓ ✓ . ✓ ✓
  - html                ✓ ✓ ✓ ✓ ✓
  - markdown            ✓ . ✓ . ✓
  - cpp                 ✓ ✓ ✓ ✓ ✓
  - bash                ✓ ✓ ✓ . ✓
  - python              ✓ ✓ ✓ ✓ ✓

  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.8.2
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by runner@fv-az190-151

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

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

Run :checkhealth for more info
clason commented 1 year ago

The second problem is a duplicate of #97, please keep issues to one single problem!