Skip to content

[Python] Tweak keyword scopes#4576

Merged
deathaxe merged 2 commits into
sublimehq:masterfrom
deathaxe:pr/python/async-scopes
Jun 27, 2026
Merged

[Python] Tweak keyword scopes#4576
deathaxe merged 2 commits into
sublimehq:masterfrom
deathaxe:pr/python/async-scopes

Conversation

@deathaxe

@deathaxe deathaxe commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator

This PR...

  1. scopes with keyword.control.context.with as flow may be dedicated to return, continue, ... .
  2. scopes async as part of corresponding control keyword to ensure consistent highlighting in default and basic color schemes. (For details, please refer to commit message).

Before:

grafik

After:

grafik

deathaxe added 2 commits June 21, 2026 10:14
This commit assigns `async` the scope of the keyword it modifies.

Basically `async def`, `async with` and `async for` are async variants of
ordinary declaration or control keywords. Hence `storage.modifier` may not be
the most appropriate choice for the latter two. The declaration, which
`storage.modifier` is intended for already uses `keyword.declaration`.

Finally highlighting of async keyword looks a bit off due to current scope in
Mariana color scheme and maybe others which target basic scopes, only.

This commit therefore attempts to align scope of `async` with the control
keyword it belongs to, with a dedicated sub-scope for those who want to
highlight it special.
@michaelblyons

Copy link
Copy Markdown
Collaborator

I support change 1. I am ambivalent about change 2.

@deathaxe

Copy link
Copy Markdown
Collaborator Author

In general I prefer dedicated scopes for single keywords as well. I also dislike how as keywords' scope is lumbered under related control keyword scopes instead of assigning keyword.operator.assignment.as.

An alternative solution may be to just consume both async for and for as keyword.control.loop.for without specially targetting async. That's what we do in SQL various times. I mean, someone could have been more creative than copying from JavaScript and use afor adef or awith. ;-)

I stumbled over both of async def looking equally while control flow differs, which is not ideal. My every day color scheme doesn't distinguish modifiers and control flow keywords. Thus inconsistent highlighting just revealed by luck.

Alternatives wellcome.

@michaelblyons

michaelblyons commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

I didn't notice in your first screenshots that you're matching the async with more closely to what async def already has.

Is there a scope name that could cover the asyncness of both a with and a def, ideally that we could also use back in JavaScript and friends? I ask because I could see someone wanting to flag async code without a big union of three-level scopes.

I guess I'm okay with this change and and RFC to talk about async more generally.

I also dislike how as keywords' scope is lumbered under related control keyword scopes instead of assigning keyword.operator.assignment.as.

I am interested in this idea.

@deathaxe

Copy link
Copy Markdown
Collaborator Author

There are no dedicated async scopes. The only thing I found was in JavaScript async functions, which was applied to async def, while lazily choosing storage.modifier for other asyncs.

I am tempted to just treat them as ordinary keyword.control same as their synchrounous counter parts.

@deathaxe
deathaxe merged commit 5f011f1 into sublimehq:master Jun 27, 2026
2 checks passed
@deathaxe
deathaxe deleted the pr/python/async-scopes branch June 27, 2026 21:41
@FichteFoll

Copy link
Copy Markdown
Collaborator

Ultimately, from an algorithmic pov it does not matter whether the for or with statement you are using is asnychronous or not since it does not affect the logic of your body. It only marks points where execution may be halted while waiting for something, which is arguably not important enough to be highlighted specifically. It's a bit more important than async def because that is primarily a marker (and affects the return type of the function invocation), but it's not enough.

In that sense, asnyc for is much closer to await, but I do not think we have a scope name that could express this behavior appropriately.

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.

4 participants