DetachHead / basedpyright

pyright fork with various type checking improvements, improved vscode support and pylance features built into the language server
https://docs.basedpyright.com
Other
911 stars 17 forks source link

Add typemod for decorators #278

Open johannesrld opened 5 months ago

johannesrld commented 5 months ago

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

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

DetachHead commented 5 months ago

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

johannesrld commented 4 months ago

Literally have no idea whatsoever unfortunately

johannesrld commented 4 months ago

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)