-
Notifications
You must be signed in to change notification settings - Fork 38
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
Add typemod for decorators #278
Comments
is happy to support it, tho i find it weird that semantic tokens are different in each editor |
Literally have no idea whatsoever unfortunately |
Looking at the documentation, 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 edit: however, for anyone using python in neovim you can add this to ;; extends
(for_statement "in" @keyword.repeat)
(for_in_clause "in" @keyword.repeat) |
I'm not sure if this the right issue, but I'm using this workaround for decorator highlighting (for neovim) I've added this to on_attach = function()
vim.api.nvim_create_autocmd("LspTokenUpdate", {
callback = function(args)
local token = args.data.token
if token.type == "decorator" and not token.modifiers.readonly then
vim.lsp.semantic_tokens.highlight_token(
token,
args.buf,
args.data.client_id,
"@lsp.type.decorator.python",
{ priority = 130 }
)
end
end,
})
end, |
i think i know what the issue is here. some symbols get two different semantic tokens applied to them. currently decorators get both the i can fix this pretty easily, but in cases where the decorator is something other than a single name, how should those be handled? i'm leaning towards just falling back to using the tokens from each part of the decorator call like this, unless anyone has a better idea: |
vscode uses same color regardless of that (in pylance), I think it's something of opinionated matter, as for me, I would like to see one color for all parts, since decorators are always callables and there shouldn't be misunderstanding if module part is not colored differently, also I like how it looks visually, 3 different colors looks ugly for single (kinda) symbol to me |
as far as i can tell pylance doesn't use the
my concern is that since decorators can be any expression, it seems like a bad idea to highlight every symbol inside the expression as such regardless of whether the individual symbol itself is a decorator. another example off the top of my head is functions that take an argument and return a decorator, eg: class Foo:
@foo(bar) # should "bar" be highlighted as a decorator as well?
def a(self): ... but anything can be a decorator: class Foo:
@baz(qux).asdf[a + b]() # should all of these symbols be highlighted as decorators?
def b(self): ... |
I mean what would you even highlight as "decorator" in the case of maybe the best idea would be to highlight everything as a decorator except parameters? (and maybe other things like punctuation and numbers). That would help make it clear that "this is a decorator" instead of just a random bit of syntax with a "@" at the start without completely trampling over highlighting. |
now that johannesrld said it I think it might be a better approach 🙂 |
thanks for the input guys, though i still think my idea to only do it on simple decorators like |
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
orlsp.typemod.decorator.defaultLibrary
so we can highlight decorators with the same colour regardless of if they're classes or functionsThe text was updated successfully, but these errors were encountered: