basedpyright icon indicating copy to clipboard operation
basedpyright copied to clipboard

Add typemod for decorators

Open johannesrld opened this issue 2 years ago • 3 comments

Currently, lsp.type.decorator can be overwritten by a couple lsp tokens, for example @classmethod is overwritten by:

  • lsp.type.class
  • lsp.mod.builtin
  • lsp.mod.defaultLibrary
  • lsp.typemod.class.builtin
  • lsp.typemod.class.defaultLibrary

it would be nice to have something like lsp.mod.decorator, lsp.typemod.decorator.builtin or lsp.typemod.decorator.defaultLibrary so we can highlight decorators with the same colour regardless of if they're classes or functions

johannesrld avatar Apr 09 '24 10:04 johannesrld

is mod and typemod a neovim-specific thing? i see it's mentioned here but i can't find anything about it in the LSP spec

happy to support it, tho i find it weird that semantic tokens are different in each editor

DetachHead avatar Apr 09 '24 12:04 DetachHead

Literally have no idea whatsoever unfortunately

johannesrld avatar Apr 09 '24 14:04 johannesrld

Looking at the documentation, typemod and mod just seem to be for semantic token modifiers with typemod being more specific (for example you might have @lsp.mod.decorator if you want to highlight all decorators a specific colour, and then @lsp.typemod.class.decorator and @lsp.typemod.function.decorator to distinguish between function and class decorators)

the spec also says you can just define whatever you want and that the predefined values are just the default "base", for example pyright (and rust-analyzer) also changes the in operators semantic token based on if it's used in a control flow or if it's used to check for membership, for example:

image

image

edit: however, for anyone using python in neovim you can add this to after/queries/python/highlights.scm to get similar behaviour

;; extends
(for_statement "in" @keyword.repeat)
(for_in_clause "in" @keyword.repeat)

johannesrld avatar Apr 09 '24 19:04 johannesrld