Skip to content
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

[Rust] Refactor path matching #3854

Merged
merged 7 commits into from
Jan 15, 2024
Merged

Conversation

FichteFoll
Copy link
Collaborator

@FichteFoll FichteFoll commented Oct 14, 2023

See the individual commits for details.

In this PR, I have rewritten path matching in Rust to

  • fix application of support.function scopes in function calls
    • also in annotations
  • unify handling of identifiers, function calls and types, even inside paths (e.g. f32::from(…))
  • make meta.path span the entire "path", as specified in the scope naming docs
  • make meta.generic not span the type it is being generic over
  • be more resilient against whitespaces
  • consistently apply punctuation.accessor for sub-path access

Fixes a few outstanding issues from #2305 (such as #2305 (comment), highlighting of union as a function name, which is a soft-keyword).

In addition, the syntax definition file has been restructured a bit by organizing related contexts in sections.

Move some context to related ones and add section headers.

This commit does not claim to be an accurate grouping, but some grouping
for now is better than none.

Additionally, the `statements-block` context was replaced with a `block`
context that pops after matching, following the plural vs singular
naming convention.
Rewrite type and identifier matching to fix problems with properly
highlighting function calls. Not all cases are implemented yet, but
this is a significant improvement over the previous situation.

- The generics meta scope doesn't cover the preceding identifier
  anymore.
- `meta.path` now spans the entire path, including the last segment.
- The explicit `types` context is used in a couple more newly introduced
  contexts, i.e. for variable type declarations and `type` variables.

A test file concerning identifier paths and function calls has been
added.

Some plural-vs-singular renaming has also been done, but not to all
contexts.
Rust/Rust.sublime-syntax Outdated Show resolved Hide resolved
Rust/Rust.sublime-syntax Outdated Show resolved Hide resolved
Rust/Rust.sublime-syntax Outdated Show resolved Hide resolved
Rust/Rust.sublime-syntax Show resolved Hide resolved
@jrappen
Copy link
Contributor

jrappen commented Oct 31, 2023

Looks fine generally, I don't approve the .rust suffixes you added, though.

@deathaxe
Copy link
Collaborator

Those in the test cases? They don't matter. I actually got used to add those final scope suffixes everywhere.

@FichteFoll
Copy link
Collaborator Author

I also came to like them because they indicate that a scope test tests the "full" scope name, i.e. it breaks when you add more to a scope but don't update the tests. It's also no extra effort for me to add them initially because PackageDev does all the work.

@FichteFoll FichteFoll merged commit 1fe0b24 into sublimehq:master Jan 15, 2024
2 checks passed
@FichteFoll FichteFoll deleted the pr/rust/paths branch January 15, 2024 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants