vscode: TextMate grammar fixes (callback-setup, @rust-attr)#11569
Open
1Mr-Newton wants to merge 2 commits intoslint-ui:masterfrom
Open
vscode: TextMate grammar fixes (callback-setup, @rust-attr)#115691Mr-Newton wants to merge 2 commits intoslint-ui:masterfrom
1Mr-Newton wants to merge 2 commits intoslint-ui:masterfrom
Conversation
The `callback-setup` rule's parenthesised pattern was opening on any `identifier(` and only closing at `)\s*=>`. Plain function calls written with an unqualified name (e.g. `max(...)`, `min(...)`, `mod(...)`, `debug(...)` at top level of a property body) entered the scope and never exited, swallowing every following token to EOF. Dotted names were unaffected because the rule's identifier class disallows `.`. Add a positive lookahead requiring `(...)\s*=>` after the identifier so the rule only fires on actual callback bindings. Slint callback bindings have flat parameter lists, so a no-nested-paren single-line lookahead is sufficient. Closes slint-ui#11568
Slint allows `@rust-attr(...)` on `struct` and `enum` declarations to
forward Rust attributes (`#[...]`) to the generated struct/enum, with
multiple `@rust-attr` allowed per item. The TextMate grammar had no
rule for this, so the whole annotation rendered as plain text and the
trailing closing paren occasionally tripped up downstream rules.
Add `rust-attr` (entry rule that opens on `@rust-attr(...)`) and
`rust-attr-body` (recursive body rule that handles nested parens,
strings, paths with `::`, identifiers, type names, `=`, and `,`).
Include `#rust-attr` near the top of the root pattern list so it
fires before `#struct`/`#enum`.
Verified with a `vscode-textmate` + `vscode-oniguruma` harness on
realistic snippets, including:
@rust-attr(derive(Debug, Clone))
@rust-attr(cfg_attr(feature="serde", derive(Serialize, Deserialize)))
export struct WinData { ... }
The whole annotation is now scoped under `meta.attribute.rust-attr.slint`
with sensible sub-scopes, the rule stack closes cleanly, and the
following `struct` declaration highlights as before.
Member
|
Thank you for improving the extension and thank you for being upfront AI was used to assist it! Someone will get back soon with a review 🤩 |
Member
|
Cool, thanks for the fix, looks good. Could you please add tests in editors/vscode/tests/grammar/ ? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two TextMate grammar fixes for
docs/common/src/utils/slint.tmLanguage.json(the canonical source;editors/vscode/slint.tmLanguage.jsonis a symlink to it).1.
callback-setupno longer swallows bare function calls (closes #11568)callback-setup's parenthesised pattern was opening on anyidentifier(and only closing at)\s*=>. Plain function calls written with an unqualified name (e.g.max(...),min(...),mod(...),debug(...)at top level of a property body) entered the scope and never exited, swallowing every following token to EOF. Dotted names (Math.foo(...),TimeUtil.foo(...)) were unaffected because the rule's identifier class[a-zA-Z_][a-zA-Z0-9_-]*disallows., so they fell through tofunction-call.Fix: add a positive lookahead requiring
(...)\s*=>after the identifier, so the rule only fires on actual callback bindings. Slint callback bindings have flat parameter lists, so a no-nested-paren single-line lookahead is sufficient.Repro
Before the patch the rule stack pushed by
max(is never popped. After the patch the file tokenises with the stack returning to depth 1 at EOF.2. Highlight
@rust-attr(...)annotationsSlint allows
@rust-attr(...)onstructandenumdeclarations to forward Rust attributes (#[...]) to the generated type, with multiple@rust-attrallowed per item. The grammar had no rule for this, so the whole annotation rendered as plain text.Fix: add a
rust-attrentry rule that opens on@rust-attr(, and a recursiverust-attr-bodyrule that handles nested parens, strings, paths with::, identifiers, type names,=, and,. Include#rust-attrnear the top of the root pattern list so it fires before#struct/#enum.Example
After the patch the whole annotation is scoped under
meta.attribute.rust-attr.slintwith sensible sub-scopes (@rust-attrassupport.function.macro,Debug/Serializeasentity.name.type,"serde"asstring.quoted.double, etc.), the rule stack closes cleanly, and the followingstructdeclaration highlights as before.Test plan
Both changes verified with a
vscode-textmate+vscode-onigurumatokenisation harness:max(...),min(...),mod(...),debug(...)calls — rule stack closes correctly,propertyand elements after the call regain their scopes.clicked => { ... }andmoved(x, y) => { ... }parse identically to before, withentity.name.function.slinton the callback name.@rust-attr(...)annotations (single, stacked, with nested parens, with strings) — every token gets a sensible scope, rule stack returns to depth 1 after the closing paren..slintfiles in a downstream project; baremax/mincalls and surrounding code now highlight as intended.