elisp-tree-sitter icon indicating copy to clipboard operation
elisp-tree-sitter copied to clipboard

Highlighting is incorrect when using hook

Open jacksonludwig opened this issue 3 years ago • 4 comments

In js-mode in a file with jsx, this is how the highlighting appears when manually activating tree-sitter-hl-mode: image

And this is how it appears when using the hook from the usage guide: image

Things are highlighted differently. For example, the comment seems to be highlighted incorrectly when using the hook.

There is no errors or stacktraces.

I am using the most recent treesitter and treesitter-langs version.

Emacs version: GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.27, cairo version 1.16.0)

jacksonludwig avatar Apr 23 '21 18:04 jacksonludwig

Please provide more details for debugging:

  • The file with the issue.
  • Major and minor modes used in the buffer.
  • Steps to trigger the behavior. For example, any navigation/editing after opening the file.
  • Minimal config to reproduce the issue, if possible.

ubolonton avatar Jul 24 '21 10:07 ubolonton

Having the same problem with C code here.

  • File: a C file containing a single line of define
    #define RHR 0            // receive holding register (for input bytes)
    
  • OS: Arch Linux
  • A fresh installation of Emacs 28.1, default config

To reproduce the error: install tree-sitter (20220212.1632) and tree-sitter-langs (20220508.636) from MELPA. In .emacs, only call global-tree-sitter-mode

(require 'tree-sitter)
(require 'tree-sitter-langs)
(global-tree-sitter-mode)

Then open the C file, M-x tree-sitter-hl-mode, the highlighting is correct 2022-07-10_13-18-35

However, when using hook to turn on tree-sitter-hl-mode

(require 'tree-sitter)
(require 'tree-sitter-langs)
(global-tree-sitter-mode)
(add-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode)

Open the C file, the highliting is wrong 2022-07-10_13-06-15 Although register and for are in comments, they are highlighted. Macro name RHR is in a different color. Manually turning tree-sitter-hl-mode off and on will give the correct highlighting.

thebesttv avatar Jul 10 '22 05:07 thebesttv

I also had that problem. Im not sure what happens exactly but setting tree-sitter-hl-use-font-lock-keywords (introduced in #46) to nil fixes this. Can anybody else confirm that this fixes this problem for them ?

Since it probably is relevant, this is my list of enabled modes: Abbrev Auto-Composition Auto-Compression Auto-Encryption Auto-Revert Blink-Cursor Column-Number Counsel-Projectile Display-Fill-Column-Indicator Display-Line-Numbers Doom-Modeline Electric-Indent File-Name-Shadow Font-Lock Global-Eldoc Global-Font-Lock Global-Git-Commit Global-Semantic-Idle-Scheduler Global-Semanticdb Indent-Tabs Ivy Ivy-Rich Ligature Line-Number Magit-Auto-Revert Mouse-Wheel Override-Global Projectile Semantic Semantic-Idle-Scheduler Shell-Dirtrack Show-Paren Smartparens Smartparens-Global Transient-Mark Tree-Sitter Tree-Sitter-Hl Which-Key Winum Ws-Butler

I do not think any of them install custom highlighting except for smartparens but even without smartparens it seems to happen.

Xeroth95 avatar Sep 05 '22 18:09 Xeroth95

Steps to trigger the behavior. For example, any navigation/editing after opening the file.

Please provide more details for debugging:

* The file with the issue.

* Major and minor modes used in the buffer.

* Steps to trigger the behavior. For example, any navigation/editing after opening the file.

* Minimal config to reproduce the issue, if possible.

Here is something that should be pretty minimal: init.el:

(require 'package)
(package-initialize)
(require 'tree-sitter)
(require 'tree-sitter-langs)

(add-hook 'c-mode-hook #'tree-sitter-hl-mode)

test.c

#include <stdlib.h>

int main(int, char **)
{
	return 0;
}

modes: Abbrev Auto-Composition Auto-Compression Auto-Encryption Blink-Cursor Electric-Indent File-Name-Shadow Font-Lock Global-Eldoc Global-Font-Lock Indent-Tabs Line-Number Menu-Bar Mouse-Wheel Show-Paren Tool-Bar Tooltip Transient-Mark Tree-Sitter Tree-Sitter-Hl

version: GNU Emacs 28.1.91 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.30, cairo version 1.16.0)

With this setup, if you open test.c, and use describe-face on the #include it will say font-lock-preprocessor-face. The expected face, which will be shown if you instead enable tree-sitter-hl-mode manually, is tree-sitter-hl-face:function.macro

Note: Every line that does not start with # uses the correct tree sitter faces. Every line that starts with # uses no tree sitter faces.

Xeroth95 avatar Sep 05 '22 18:09 Xeroth95