sainnhe / sonokai

High Contrast & Vivid Color Scheme based on Monokai Pro
MIT License
1.65k stars 119 forks source link

Question: Better highlighter command support for Dockerfile with treesitter #92

Closed huyhoang8398 closed 1 year ago

huyhoang8398 commented 1 year ago

image

Is this possible to highlight these cmd for Dockerfile? Bellow is an example with another colorscheme

image

antoineco commented 1 year ago

Yes, you simply need to enable Tree-sitter for the "Dockerfile" filetype with :TSInstall dockerfile.

Here is how it looks for me:

image

huyhoang8398 commented 1 year ago
Screenshot 2023-07-17 at 20 01 34

It's strange, after i open nvim, i did see the highlight, but after 1 sec, it looks like this then

huyhoang8398 commented 1 year ago

https://github.com/sainnhe/sonokai/assets/25379882/1d6ebfed-ecf0-4a5d-9362-e75b3dfd4e68

Here is the video, you could see wget is highlighted as green and then becoming white

antoineco commented 1 year ago

Oh, you have the LSP server for Dockerfile active apparently, and that LSP server has semantic tokens enabled. LSP semantic token are providing extra highlighting in addition to Tree-sitter.

Support for LSP semantic tokens was added in Sonokai in #86.

In https://github.com/sainnhe/everforest/issues/119, I tried to determine whether we could customize those color schemes ever further to improve the experience with LSP semantic tokens, but my conclusion was that LSP semantic tokens highlights sometimes conflict with Tree-sitter pretty badly. From my experience, this feature degrades the highlights more than it improves them. For instance, I wasn't able to enhance highlights for the Go language due to the priority that the LSP semantic token highlights were given over Tree-sitter's.

Thanks a lot for the video 👍 I will check whether we can improve the Dockerfile file type specifically for LSP semantic tokens. In case that's not possible, it's probably best to disable that feature.

antoineco commented 1 year ago

I just investigated the issue, and unfortunately LSP semantic highlights override Tree-sitter entirely in this case.

Tree-sitter has smart queries which allows detecting and highlighting sh/bash inside Dockerfiles. You can see it in the screenshot below as:

Treesitter
  - @variable.bash links to @variable bash    <!-- bash detected -->
  - @constant.bash links to @constant bash

Unfortunately, as soon as LSP semantic tokens are enabled, everything becomes a "parameter" instead, and the embedded highlights are overridden:

Semantic Tokens
  - @lsp.type.parameter.dockerfile links to @parameter priority: 125  <!-- higher priority than Tree-sitter -->

Screenshot:

image

That's why all the colors disappear in your video. I see the exact same behavior in my Neovim with the dockerls LSP server enabled.


I was able to disable this feature in dockerls with the following lspconfig:

local lspconfig = require "lspconfig"

lspconfig.dockerls.setup {
  on_attach = function(client, bufnr)
    client.server_capabilities.semanticTokensProvider = nil
  end,
}

image

huyhoang8398 commented 1 year ago
Screenshot 2023-07-17 at 23 42 32

I was able to disable this feature in dockerls with the following lspconfig:

After disable tthat feature, it's working well now, thanks