Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't highlight TSError in insert mode #1016

Closed
khaveesh opened this issue Mar 11, 2021 · 7 comments
Closed

Don't highlight TSError in insert mode #1016

khaveesh opened this issue Mar 11, 2021 · 7 comments
Labels
enhancement New feature or request

Comments

@khaveesh
Copy link

Is your feature request related to a problem? Please describe.
Since treesitter highlights all errors even while typing an incomplete expression, it is very irritating. Previously, it was suggested to link TSError to the Normal hlgroup, so that the errors are never highlighted.

Describe the solution you'd like
But a better solution for those who want to be informed about syntax/parsing errors in their code, would be to highlight these errors but just not in insert mode. In a nutshell, I want TSError linked to Normal when in insert mode and Error otherwise.

Describe alternatives you've considered
Alternatives is to put up with the constant annoyance when typing or to completely silence the error highlighting. Both are IMO inferior options.

Additional context
Previous discussions on this topic that I found were: #78 & #119.

@khaveesh khaveesh added the enhancement New feature or request label Mar 11, 2021
@stsewd
Copy link
Member

stsewd commented Mar 11, 2021

I think you can achieve this with an auto command, maybe? :h InsertEnter and :h InsertLeave

@khaveesh
Copy link
Author

@stsewd That works, but still would prefer an option to toggle that behaviour built into the plugin. Closing for now.

@theHamsta
Copy link
Member

@khaveesh nvim-treesitter does not define TSError. Maybe you color theme defines it?

arcticicestudio pushed a commit to nordtheme/vim that referenced this issue Sep 12, 2021
The `TSError` group is used to highlight syntax/parser errors [1] which
caused an aggressive styling where the background color of many syntax
elements was rendered with `nord11` during typing. This was caused due
to the fast processing of `tree-sitter` which also resulted in highlight
flickering.
This is a known problem and was fixed by many other themes (e.g. Dracula
[2]) by removing the group again. One of the core maintainers of
`nvim-treesitter` provided a solution by remapping groups [3] and also
mentioned that the group is styled by the `nvim-treesitter` plugin but
the active theme [4].

Syntax errors can still be highlighted through linters and parsers like
Neovim's LSP [5] can still be used instead to highlight errors with the
correct style (e.g. only change the foreground color of a single word).

[1]: https://github.com/nvim-treesitter/nvim-treesitter/blob/fb5d6e04/doc/nvim-treesitter.txt#L493-L495
[2]: dracula/vim#232
[3]: nvim-treesitter/nvim-treesitter#78 (comment)
[4]: nvim-treesitter/nvim-treesitter#1016 (comment)
[5]: https://github.com/neovim/nvim-lspconfig

Fixes GH-269
arcticicestudio pushed a commit to nordtheme/vim that referenced this issue Sep 12, 2021
The `TSError` group is used to highlight syntax/parser errors [1] which
caused an aggressive styling where the background color of many syntax
elements was rendered with `nord11` during typing. This was caused due
to the fast processing of `tree-sitter` which also resulted in highlight
flickering.
This is a known problem and was fixed by many other themes (e.g. Dracula
[2]) by removing the group again. One of the core maintainers of
`nvim-treesitter` provided a solution by remapping groups [3] and also
mentioned that the group is styled by the `nvim-treesitter` plugin but
the active theme [4].

Syntax errors can still be highlighted through linters and parsers like
Neovim's LSP [5] can still be used instead to highlight errors with the
correct style (e.g. only change the foreground color of a single word).

[1]: https://github.com/nvim-treesitter/nvim-treesitter/blob/fb5d6e04/doc/nvim-treesitter.txt#L493-L495
[2]: dracula/vim#232
[3]: nvim-treesitter/nvim-treesitter#78 (comment)
[4]: nvim-treesitter/nvim-treesitter#1016 (comment)
[5]: https://github.com/neovim/nvim-lspconfig

Fixes GH-269
@tompreston
Copy link

tompreston commented Nov 24, 2022

That works, but still would prefer an option to toggle that behaviour built into the plugin. Closing for now.

@khaveesh what did you do? I have the same problem

Screenshot 2022-11-24 at 18 37 08

@theHamsta I use Tango Light in iterm2 on macOS, I wonder if this can be changed there? Looking at the nord-vim fix, it looks like this is a feature of the colour theme itself. So I'd need to turn it off somehow

Edit: this comment helped 🎉 It's a bit out of date though. I added this to my vim config to turn off error highlighting:

-- Turn off error highlighting, because it highlights in insert mode
vim.treesitter.highlighter.hl_map.error = nil

@theHamsta
Copy link
Member

@tompreston the mapping of captures is now handled by upstream nvim. Unmap the @error highlighting group. Errors are highlighted with @error . Your colorscheme probably links @error to something.

@clason
Copy link
Contributor

clason commented Nov 24, 2022

...which upstream Neovim deliberately doesn't do, so this is a colorscheme issue.

@rodhash
Copy link

rodhash commented Dec 12, 2022

Is this working, @tompreston ?

-- Turn off error highlighting, because it highlights in insert mode
vim.treesitter.highlighter.hl_map.error = nil

It seems it can't find hl_map when I add to my config.

ps:

I tried Unmapping @error as mentioned above, helped a little bit but somehow it still changes the color a little so I was trying the snippet above

I also tried couple different colorschemes but I still get weird colors while in insert mode

Anyway this is the error I get:

E5113: Error while calling lua chunk: ~/.config/nvim/lua/plug/treesitter.lua:111: attempt to index field 'TSHighlighter' (
a nil value)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants