nvim-solarized-lua icon indicating copy to clipboard operation
nvim-solarized-lua copied to clipboard

How to have multiple colours for the same Treesitter value?

Open ogirginc opened this issue 4 years ago • 1 comments

I am not sure, if this is the place to ask for this but; is it possible to have different colours depending not only on Treesitter, but on both Treesitter & Syntax?

Here is a sample code from Ruby on Rails project:

scope :ok_world, -> { where(ok_world: true) }

def hello
  puts "Hello world!"
end
Treesitter Enabled Treesitter Disabled
Screenshot 2022-01-21 at 23 28 03 Screenshot 2022-01-21 at 23 28 17
Playground data
call [266, 2] - [266, 41]
  method: identifier [266, 2] - [266, 7]
  arguments: argument_list [266, 8] - [266, 41]
    simple_symbol [266, 8] - [266, 14]
    lambda [266, 16] - [266, 41]
      body: block [266, 19] - [266, 41]
        call [266, 21] - [266, 39]
          method: identifier [266, 21] - [266, 26]
          arguments: argument_list [266, 26] - [266, 39]
            pair [266, 27] - [266, 38]
              key: hash_key_symbol [266, 27] - [266, 32]
              value: true [266, 34] - [266, 38]
method [268, 2] - [270, 5]
  name: identifier [268, 6] - [268, 11]
  call [269, 4] - [269, 23]
    method: identifier [269, 4] - [269, 8]
    arguments: argument_list [269, 9] - [269, 23]
      string [269, 9] - [269, 23]
        string_content [269, 10] - [269, 22]
scope hello
Screenshot 2022-01-21 at 23 29 50 Screenshot 2022-01-21 at 23 30 23

As shown above, Treesitter thinks both scope and hello is a TSFunction –which is technically true–, but they are not only a TSFunction:

  • scope is a TSFunction and rubyMacro.
  • hello is a TSFunction and rubyMethodName.

I hoped maybe lua/solarized/solarized-normal/highlights.lua file is similar to how CSS works and assigning Ruby specific colours after TSFunction like

syntax['TSFunction'] = syntax['Function']
syntax['rubyClassBlock'] = {fg=colors.red}
syntax['rubyMacro'] = {fg=colors.red}

can change how words are highlighted, but that did not work.

So, is it possible to override Treesitter highlighting with the Syntax one, whenever it is needed?

ogirginc avatar Jan 21 '22 20:01 ogirginc

This is even an issue for me when highlighting some c code. It most likely can be configured with the treesitter setup but I have no idea as I don't use lsp and treesitter.

ishan9299 avatar Jan 22 '22 04:01 ishan9299