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

Feat: Add groups for LSP semantic tokens #52

Merged
merged 5 commits into from
Apr 4, 2023

Conversation

mactep
Copy link
Contributor

@mactep mactep commented Apr 1, 2023

I'm not sure what I am doing here, but my Lua code was getting white, so I linked some highlight groups to Treesitter ones.

@mactep mactep changed the title Add groups for LSP semantic tokens WIP: Add groups for LSP semantic tokens Apr 1, 2023
@mactep
Copy link
Contributor Author

mactep commented Apr 1, 2023

It'll probably be better to change the notation to ['@lsp.type.<group>'] = { ... }

@mactep
Copy link
Contributor Author

mactep commented Apr 1, 2023

@AlexvZyl

This comment was marked as outdated.

@AlexvZyl
Copy link
Owner

AlexvZyl commented Apr 1, 2023

It seems like these tokens are new, tokyonight added them recently.

@AlexvZyl
Copy link
Owner

AlexvZyl commented Apr 1, 2023

This PR seems to be the culprit.

@AlexvZyl AlexvZyl marked this pull request as draft April 1, 2023 17:08
@AlexvZyl AlexvZyl changed the title WIP: Add groups for LSP semantic tokens Feat: Add groups for LSP semantic tokens Apr 1, 2023
@AlexvZyl AlexvZyl added the Enhancement New feature, request or suggestion label Apr 1, 2023
@AlexvZyl
Copy link
Owner

AlexvZyl commented Apr 1, 2023

It would have been really nice if all of the Neovim colorschemes were just forks of some core repository, and then just override colors as the developers see fit...

@AlexvZyl
Copy link
Owner

AlexvZyl commented Apr 1, 2023

I am going to leave this open until there is a confirmation (from either you or me) that these groups are correct. I suspect they are, I just don't have the time now to double-check.

@mactep
Copy link
Contributor Author

mactep commented Apr 2, 2023

This PR seems to be the culprit.

According to the docs we can simply disable all tokens, but I thought it would be useful to have easy access to this variables. Just in case anyone needs it:

for _, group in ipairs(vim.fn.getcompletion("@lsp", "highlight")) do
  vim.api.nvim_set_hl(0, group, {})
end

I am going to leave this open until there is a confirmation (from either you or me) that these groups are correct. I suspect they are, I just don't have the time now to double-check.

Following that script provided by neovim team, the following seems to be "official" groups, but I guess things may change until a stable release:

  • @lsp.type.class
  • @lsp.type.decorator
  • @lsp.type.enum
  • @lsp.type.enumMember
  • @lsp.type.function
  • @lsp.type.interface
  • @lsp.type.macro
  • @lsp.type.method
  • @lsp.type.namespace
  • @lsp.type.parameter
  • @lsp.type.property
  • @lsp.type.struct
  • @lsp.type.type
  • @lsp.type.typeParameter
  • @lsp.type.variable

The docs also say that many groups are linked by default to other highlight groups:

  • @lsp.type.class = Structure
  • @lsp.type.decorator = Function
  • @lsp.type.enum = Structure
  • @lsp.type.enumMember = Constant
  • @lsp.type.function = Function
  • @lsp.type.interface = Structure
  • @lsp.type.macro = Macro
  • @lsp.type.method = Function
  • @lsp.type.namespace = Structure
  • @lsp.type.parameter = Identifier
  • @lsp.type.property = Identifier
  • @lsp.type.struct = Structure
  • @lsp.type.type = Type
  • @lsp.type.typeParameter = TypeDef
  • @lsp.type.variable = Identifier

I think we can drop the other notation from this PR, keep folke's changes and add the other possible tokens commented out as an "easy access" for future improvements. What do you think @AlexvZyl?

@AlexvZyl
Copy link
Owner

AlexvZyl commented Apr 3, 2023

Yes, I agree with you. You mind doing that?

@mactep
Copy link
Contributor Author

mactep commented Apr 3, 2023

Sure, I'll get this done later today or tomorrow.

@AlexvZyl AlexvZyl marked this pull request as ready for review April 4, 2023 08:09
@AlexvZyl
Copy link
Owner

AlexvZyl commented Apr 4, 2023

Beautiful, thanks for the work!

@AlexvZyl AlexvZyl merged commit 5e66c48 into AlexvZyl:main Apr 4, 2023
@lostl1ght
Copy link
Contributor

lostl1ght commented Apr 4, 2023

There is a much easier way to disable semantic tokens:

vim.api.vim.api.nvim_create_autocmd('LspAttach', {
  callback = function(args)
      local client = vim.lsp.get_client_by_id(args.data.client_id)
      client.server_capabilities.semanticTokensProvider = nil
  end,
  group = vim.api.nvim_create_augroup('LspAug', {}),
})

I've read somewhere that it is a 'chosen' way to do that instead of messing with highlight groups.

@AlexvZyl
Copy link
Owner

AlexvZyl commented Apr 5, 2023

I've read somewhere that it is a 'chosen' way to do that instead of messing with highlight groups.

If you can find this source you are more than welcome to open a PR with the changes. We are currently not doing that since we are basically doing what Folke is doing over at tokyonight.

@mactep mactep deleted the feature/lsp-semantic-tokens branch April 5, 2023 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature, request or suggestion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants