Thanks to visit codestin.com
Credit goes to github.com

Skip to content

RFC: use nvim-treesitter's highlight group#3355

Merged
chemzqm merged 26 commits into
masterfrom
feat/use-ts-hi-group
Jan 21, 2022
Merged

RFC: use nvim-treesitter's highlight group#3355
chemzqm merged 26 commits into
masterfrom
feat/use-ts-hi-group

Conversation

@fannheyward
Copy link
Copy Markdown
Member

@fannheyward fannheyward commented Sep 6, 2021

what've done:

  1. use TS* hi group
  2. add coc.preferences.semanticTokensFiletypes to enable semanticTokens for special language
  3. remove g:coc_default_semantic_highlight_groups and CocSem_* hi groups

@fannheyward fannheyward changed the title use nvim-treesitter's highlight group RFC: use nvim-treesitter's highlight group Sep 6, 2021
@fannheyward fannheyward marked this pull request as draft September 6, 2021 10:57
@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 6, 2021

Codecov Report

Merging #3355 (1e2c64c) into master (03a532b) will increase coverage by 0.37%.
The diff coverage is 84.80%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3355      +/-   ##
==========================================
+ Coverage   74.63%   75.00%   +0.37%     
==========================================
  Files         195      195              
  Lines       19782    19821      +39     
  Branches     4427     4439      +12     
==========================================
+ Hits        14764    14867     +103     
+ Misses       3252     3185      -67     
- Partials     1766     1769       +3     
Impacted Files Coverage Δ
src/provider/semanticTokensRangeManager.ts 52.94% <0.00%> (ø)
src/types.ts 100.00% <ø> (ø)
src/handler/semanticTokensHighlights/buffer.ts 88.37% <80.85%> (+7.97%) ⬆️
src/handler/semanticTokensHighlights/index.ts 92.17% <87.50%> (+49.59%) ⬆️
src/handler/hover.ts 85.31% <100.00%> (ø)
src/language-client/index.ts 43.06% <100.00%> (+0.08%) ⬆️
src/plugin.ts 94.68% <100.00%> (+0.02%) ⬆️
src/workspace.ts 76.40% <100.00%> (ø)
src/model/task.ts 89.47% <0.00%> (-2.64%) ⬇️
src/model/download.ts 57.50% <0.00%> (-1.25%) ⬇️
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 03a532b...1e2c64c. Read the comment docs.

@oblitum
Copy link
Copy Markdown
Member

oblitum commented Sep 6, 2021

Will this require to explicitly enable the languages for semantic tokens to work? My original suggestion was to have semantic tokens by default supported, but that when the user wants to, if it wants so, it could configure specific languages, or also, have it blacklisted for just a few.

EDIT:

Noticed it's possible to configure languages with glob ("*").

@fannheyward
Copy link
Copy Markdown
Member Author

Will this require to explicitly enable the languages for semantic tokens to work

I prefer to disable semanticTokens by default, because only clangd/rust-analzyer/gopls supports this by now, users can enable it by themself. Another reason is semanticTokens is not stable enough by now.

@fannheyward fannheyward marked this pull request as ready for review September 7, 2021 09:06
@oblitum
Copy link
Copy Markdown
Member

oblitum commented Sep 7, 2021

@fannheyward okay, I commented that because it could be annoying to have to list the languages, but I saw after that there's glob support.

@oblitum
Copy link
Copy Markdown
Member

oblitum commented Sep 7, 2021

At that, it should be documented in the added docs that glob pattern can be used to have it enabled for any server that supports it.

@fannheyward
Copy link
Copy Markdown
Member Author

be documented in the added docs that glob pattern

Done.

Comment thread doc/coc.txt Outdated
Comment thread data/schema.json Outdated
@fannheyward fannheyward marked this pull request as draft September 8, 2021 08:05
@fannheyward fannheyward marked this pull request as ready for review September 8, 2021 09:10
@oblitum
Copy link
Copy Markdown
Member

oblitum commented Sep 8, 2021

Seems worth noticing that removing the simple default groups provided by g:coc_default_semantic_highlight_groups means to remove vim support for this kind of thing.

@fannheyward
Copy link
Copy Markdown
Member Author

means to remove vim support for this kind of thing

No, if the color scheme has TS* hi group defined for vim, for example https://github.com/sainnhe/sonokai/blob/61b796d94e7b0110f1bdf321cc1d19a841697a42/colors/sonokai.vim#L331, semanticTokens highlight supports vim too.

@oblitum
Copy link
Copy Markdown
Member

oblitum commented Sep 9, 2021

@fannheyward wow, seriously, that's really nice!

@oblitum
Copy link
Copy Markdown
Member

oblitum commented Oct 17, 2021

Glob pattern isn't working anymore, dunno what happened (not sure whether it ever worked actually). I'm having to use vim.fn['coc#config']('coc.preferences', { semanticTokensFiletypes = {'rust'} }) for it to work with rust-analyzer, {'*'} doesn't work.

Comment thread src/handler/semanticTokensHighlights/buffer.ts Outdated
@oblitum
Copy link
Copy Markdown
Member

oblitum commented Oct 22, 2021

Could this be rebased? I (and maybe others) really like it and it doesn't seem there's a timeline for "the great comeback" (I'm afraid my fight had anything to do with that...).

@fannheyward
Copy link
Copy Markdown
Member Author

@oblitum I've rebased master to feat/use-ts-hi-group branch.

@oblitum
Copy link
Copy Markdown
Member

oblitum commented Oct 25, 2021

Nice, thx.

@darzok0914
Copy link
Copy Markdown

Hi, I'm currently using the CocSem_* highlight groups and I think they are great and a good complement of the TS* groups. Typically, C++ is quite hard to parse and understand for TreeSitter and clangd can provide more information. What I'm saying is that the highlight groups from Tree sitter and the one provided from lsp are not a perfect 1 to 1 mapping and we can have a better experience by combining them instead of trying to map them as it would result in a loss of information.

@fannheyward
Copy link
Copy Markdown
Member Author

fannheyward commented Dec 15, 2021

cc @oblitum tokenModifiers has been handled, something like TSDeprecated will be highlighted.

The problem is, hi group like TSStatic/TSDeprecated/TSReadonly are not defined by nvim-treesitter, we should provide these hi group, or user needed to define by themself.

@oblitum
Copy link
Copy Markdown
Member

oblitum commented Dec 15, 2021

cc @oblitum tokenModifiers has been handled, something like TSDeprecated will be highlighted.

Nice. I tried it with Go (I had to :hi link TSDeprecated CocDeprecatedHighlight manually) but got the highlighting only at definition, never at call site:

img-2021-12-15-101132

All the function calls inside main are for deprecated functions.

The problem is, hi group like TSStatic/TSDeprecated/TSReadonly are not defined by nvim-treesitter, we should provide these hi group, or user needed to define by themself.

Is it good idea to fallback highlighting (to CocDeprecatedHighlight) as commented in #3188 (comment)?

@chemzqm
Copy link
Copy Markdown
Member

chemzqm commented Jan 21, 2022

@jackhub No need to hack the code any more, composed highlight group would work, checkout :h CocSem

@chemzqm chemzqm merged commit 4fda36d into master Jan 21, 2022
@chemzqm chemzqm deleted the feat/use-ts-hi-group branch January 21, 2022 20:06
chemzqm added a commit that referenced this pull request Jan 21, 2022
4211352 docs(vim): more doc for semantic highlights
4fda36d RFC: use nvim-treesitter's highlight group (#3355)
sainnhe added a commit to sainnhe/everforest that referenced this pull request Jan 22, 2022
sainnhe added a commit to sainnhe/sonokai that referenced this pull request Jan 22, 2022
sainnhe added a commit to sainnhe/edge that referenced this pull request Jan 22, 2022
sainnhe added a commit to sainnhe/gruvbox-material that referenced this pull request Jan 22, 2022
@jackhub
Copy link
Copy Markdown

jackhub commented Jan 23, 2022

@jackhub No need to hack the code any more, composed highlight group would work, checkout :h CocSem

Thanks for your great works.

@daquexian
Copy link
Copy Markdown
Contributor

why semanticTokens.filetypes is empty by default? It should be ['*'] that aligns with the old coc.preferences.semanticTokensHighlights.

@chemzqm
Copy link
Copy Markdown
Member

chemzqm commented Jan 25, 2022

Because we don't want to surprise users with changed highlights.

@damnskippy
Copy link
Copy Markdown

Does the user have to explicitly call CocAction('semanticHighlight') to get the highlights, or does coc.nvim automatically make this call if semanticTokens.filetypes is enabled for the current &filetype in vim.
In vim I see semantic highlighting working after calling CocAction('semanticHighlight'), but not automatically, so wanted to confirm if this is expected behavior. Thanks.

@chemzqm
Copy link
Copy Markdown
Member

chemzqm commented Jan 25, 2022

does coc.nvim automatically make this call if semanticTokens.filetypes is enabled for the current &filetype in vim.

It should be automatic.

@damnskippy
Copy link
Copy Markdown

Thanks for confirming, I'll look into my environment to see what's going on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants