Nvim-treesitter: Is it possible to achieve different colors for arguments and local variables? Java parser

Created on 3 Aug 2020  路  6Comments  路  Source: nvim-treesitter/nvim-treesitter

Regarding to config, I've pasted what is defined in the readme's setup.

java parser healthcheck

colorscheme sublimemonokai

  • TSBufEnable highlight

image

  • TSBufDisable highlight

image

The differences are:

  1. Class name Main from non-italic to italic.
  2. Return type void from non-italic to italic.
  3. Type variable String from non-italic to italic.
  4. Highlight of function name main.
  5. Highlight of brackets.

colorscheme default

  • TSBufEnable highlight

image

  • TSBufDisable highlight

image

The differences are:

  1. Highlight of class name Main.
  2. Highlight of keyword static.
  3. Highlight of return type void.
  4. Highlight of function name main.
  5. Highlight of type variable String[].
  6. Highlight of argument args.
  7. Highlights of local type variable String and variable name element.
  8. Highlight of brackets.
enhancement question

All 6 comments

The highlights for argument is TSParameter you can configure it freely and locals currently have no highlight.

Some symbols may not be highlighted after enabling the feature on the fly, you can try forcing the buffer to reload :e! or redraw (Ctrl-L), or just give it a try by enabling it by default :) this is how a java file looks like for me

Screenshot from 2020-08-03 17-39-04

You can modify the highlight groups defined in https://github.com/nvim-treesitter/nvim-treesitter/blob/master/plugin/nvim-treesitter.vim#L25-L75 as you like (like marking some elements with italics).

I've tried a few but not all of them work.

hi TSMethod      guifg=#0066FF " Only one working
hi TSParameter   guifg=red
hi TSProperty    guifg=pink
hi TSField       guifg=forestgreen
hi TSConstructor guifg=#66FF22 

This is the result:

image

Is there something I'm missing?

I've looked into the field groups that you are trying to use and it looks like they don't necessarily line up.

TSMethod -> works.
TSParameter -> works.
TSProperty -> not used.
TSField -> not used, seems to be mapped TSType instead.
TSConstructor -> not used, also mapped to TSType.

We can update the queries to better match the expected highlight groups, or at least add documentation so that users know which to use.

@vigoux should we close this in favor of #81 ?

Is there something I'm missing?

surely, because atleast TSParameter works for me (java)

Was this page helpful?
0 / 5 - 0 ratings