-
Notifications
You must be signed in to change notification settings - Fork 589
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] Sync with Rust Enhanced #2305
Conversation
@ehuss FYI:
In case you have questions, I suggest joining the SublimeHQ Discord: |
This is going to be a lot of work to accept since all of the tests and a significant amount of the syntax changed at once. From a review standpoint I've got to go through it like it is a ground-up rewrite. In the future, if there are large changes, it is much easier to accept if tests are modified via:
|
I completely understand and recognize it will be difficult. There was unfortunately quite a lot of changes since things forked 3 or 4 years ago, and trying to preserve each change on top of the latest master would have also meant more or less rewriting everything. FWIW, there is a list of changes from sublimehq to rust-lang here. I did what I could to preserve the sublimehq changes and conventions when there were conflicts. I also intend, if this is accepted, to upstream each change individually, to avoid big dumps of changes. I can maybe try to write a summary of all the PRs that changed things on the rust-lang side, would that help? |
Not really. With the scope of the changes and the tests changing it will need to be a thorough, all-details review, including making sure that appropriate tokens are using the correct choices from https://www.sublimetext.com/docs/scope_naming.html. |
@ehuss this syntax breaks the greedy In fact, this syntax doesn't account for use std::io;
// ^^ missing punctuation.accessor
fn main() {
io.into();
//^ missing punctuation.accessor
println!("Hello, world!");
} |
Note that the current syntax in master does apply this idea correctly. |
The snytax also doesn't allow using The following is legal code (example for use std::collections::HashSet;
let a: HashSet<_> = [1, 2, 3].iter().cloned().collect();
let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect();
// Print 1, 2, 3, 4 in arbitrary order.
for x in a.union(&b) {
println!("{}", x);
}
let union: HashSet<_> = a.union(&b).collect();
assert_eq!(union, [1, 2, 3, 4].iter().collect()); |
Otherwise, simply the very much more consistent highlighting of types makes this syntax basically a must have for me. There are still some edges (like those two issues reported above), but I believe it to be a solid base for further improvements. If an all-details review is required for merging it, then I can't promise when I would find the time to go through it, since it takes quite a bit of time to review 4k lines of a syntax definition, and a diff no less. Instead, I would probably go through the definition as if it was brand new and annotate things that aren't aligned with the current guidelines. Unfortunately, our guidelines themselves are constantly moving since we haven't standardized quite a few aspects of syntaxes, notably |
I forgot to mention that every function call is scoped Also, every occurance of an Uppercase identifier is scoped as |
@rwols Can you clarify what you are seeing? The examples you gave seem to set
It works correctly in some cases (such as
Can you clarify,
In practice, those are always types. That will take some time to untangle, since I'm not really sure how types should be scoped in the different circumstances they are used. (This looks to be inherited from the tmLanguage definition from over 5 years ago.) |
That's correct in general, while the "standard library" part may be a beast for some syntaxes. There's no real rule what to include and what not here, I guess. The difficulty of this rule maybe the difference of syntaxes. Some define real sets of builtin functions while others implement those in standard libraries only but interpret them as defacto builtins. While fundamental functions of a core part of a standard library whould probably be good to be scoped We should find a sane balance here. When in doupt, a syntax should use |
You're correct. I don't know where I got my syntax from then. Overall I think this is indeed definitely mergeable! |
As long as it's not a regression, this is definitely fine with me and can be worked on later.
Generally, yes, but this syntax applies this scope to all functions, even those I defined myself or bogus names, which makes this separation inapplicable. The problem with highlighting built-in functions in a language like Rust that heavily uses method chaining is that a static syntax highlighter simply cannot know which function is being executed, since it has no information on the underlying type (or trait). Now, it could try to only match function names that can be found in You can do this for Languages like Python or Php, which have a set of default global functions, but for Rust (or Java, for comparison), I simply believe this to not be applicable. (For Java, you could argue for Object methods, since all objects will have those, but then you might as well not bother.) |
I removed the use of I also added support for const generics which will be on the stable channel in March. I spent some time trying to better understand the concern about |
You're not alone with this. I say, until we find a common ground for this topic, just leave it as-is. (As I mentioned before.) |
I think that's the very appropriate scope for all kinds of user defined data types. Nothing to be concerned about. Many syntaxes used to scope class names This conflict has been resolved by scoping those keywords |
scope: support.macro.rust | ||
|
||
- match: '{{support_type}}' | ||
scope: support.type.rust | ||
- include: support-type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This context is already included in line 135. Is there a reason for it being here again?
pop: true | ||
- match: '(crate|in|self|super)' | ||
scope: keyword.other.rust | ||
- match: '::' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be a good candidate for punctuation.accessor
.
- match: '::' | ||
scope: meta.path.rust | ||
- match: '{{identifier}}' | ||
scope: meta.path.rust |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would variable.namespace
or variable.other
be a good scope here?
|
||
attribute-call: | ||
- match: \) | ||
scope: meta.function-call.rust meta.group.rust punctuation.section.group.end.rust | ||
pop: true | ||
- match: '({{identifier}})(\()' | ||
- match: '({{identifier}})\s*(\()' | ||
scope: meta.function-call.rust | ||
captures: | ||
1: variable.function.rust |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is meta.group
probably missing in line 292? I'd expect meta.group
to cover the whole function arguments list.
- match: '\]' | ||
scope: punctuation.section.group.end.rust | ||
pop: true | ||
- match: '[ \t]+' | ||
- include: strings | ||
- include: comments | ||
|
||
attribute-call: | ||
- match: \) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
attribute-call
is included in line 264, which already defines a pattern for \)
to pop a context. This makes this one being a duplicate then. Would this pattern probably be better placed before the -include: atttribute-call
in row 293?
Java and C# seem to use I was under the impression that So overall there doesn't seem to be a common convention which scope name to use for (user-defined) types. But for example the Mariana color scheme uses the same color for |
Definitely doesn't look bad. But what about this: Wouldn't it be nicer if it looks like this: spoiler <- click meSo if e.g. built-in classes get But I must mention that the current Java syntax doesn't distinguish between built-in and user-defined classes either. Some syntaxes like PHP seem to maintain huge lists of built-in classes, functions and constants. Maybe it's infeasible in Java due to the large amount of built-in classes in the Java core libraries? JavaScript uses |
I don't want to hijack this PR for general discussions, but... I agree with you in general and follow/second your intention. I just don't get why we want to use Type keywords may still be distinguished by a 3rd level scope, even though they look the same as user defined functions by default then. But I don't find that too bad, as it is just a data type as well. Of course, it would make sense then to put those under |
@ehuss As things are moving again in this repo, maybe you could:
|
support.function is intended only for functions that are provided by the standard library. Rust doesn't really have very many free functions (`drop` is about the only one in the prelude). variable.function is supposed to be used for function calls.
21c26ba
to
0ea7b78
Compare
Sorry about the delay. I rebased, but it looks like CI requires approval. I combined all the tests into one file (3046 lines) and ran the performance tests on my machine. There was a bit of variability, but in general the old syntax was about 13.5ms and the new one was about 15ms. |
First of all, thanks for this. After a quick glance at this, a few remarks:
Is this meant to be a first sync with the 3rd party package to be then worked on in a second step? If yes, this seems fine. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been using this syntax definition yet another time for my advent of code solutions in Rust and it did a good job, definitely better than the current built-in one. There are a few minor scope inconsistencies, but those are easily fixed in follow-ups and I have made some notes for them that I intend to address myself later, including the remaining open discussions by @deathaxe.
I didn't do a comparison with RustEnhanced in its current state. I believe the PR to be mergable as-is, because it is definitely an improvement over the current default syntax and it's kinda shameful it took this long. Any further issues, however small they are, can be fixed later.
So let's go ahead. |
Additions: - Added documentation on making changes for JS/JSX/TS/TSX, along with a helper shell script. Conflicts fixed: - README.md - slimsag/master had a bunch of additional information on how to add new definitions, information on licensing etc. - In upstream, there is a short description on how to submit PRs. - Fix: I moved all the additional information into MakingChanges.md, which is local to this fork. This prevents future merge conflicts from popping up in the README. - Rust.sublime-syntax: - slimsag/master had moved the file to RustEnhanced.sublime-syntax in 789a76e due to problems with the definitions upstream, and made some minor tweaks. - In upstream, there was a recent fix (sublimehq#2305) for improving Rust highlighting. - Fix: We delete RustEnhanced.sublime-syntax and use Rust.sublime-syntax from upstream. - Clojure.sublime-syntax: - slimsag/master use Clojure highlighting for .cljs and .cljx files. - Upstream did not use cljs and cljx for Clojure highlighting. Instead, it supported .cljs via a separate ClojureScript syntax, which itself is based on Clojure syntax. - The common ancestor did use Clojure highlighting for .cljs files. This was removed in cc5ce9b. - Fix: I added cljx to ClojureScript.sublime-syntax and removed it from Clojure.sublime-syntax. - JavaDoc.sublime-syntax: - slimsag/master largely matched with the common ancestor, whereas upstream had made some changes. I picked most of the changes from usptream. - There is a regex for 'escape:' which was changed: - common ancestor: \*/ - slimsag/master: \s*\*/ - upstream: \*+/ - merged (maximally lenient): \s*\*+/ - JavaScript related changes: - slimsag/master was based on a generated version of Thom1729/Sublime-JS-Custom. - Upstream had updated to a version based off Thom1729/Sublime-JS-Custom (see 40ec1f2), but it differs significantly from the generated syntax. - Additionally there are filename differences (the old syntax definitions in slimsag/master used "React" in the name). - Fix: I regenerated the files from Thom1729/Sublime-JS-Custom, and used them to replace the existing files for JSX and TSX. - Additionally, I removed the 'js' file extension from the JSX sublime-syntax file. - This change required some changes to the tests as well. However, all changes to tests involved erroneous code, so the change in highlighting is not significantly problematic.
This commit syncs the official rust-lang syntax definition from https://github.com/rust-lang/rust-enhanced/ with the changes made here in the sublimehq repository.
This is an attempt to sync the official rust-lang syntax definition from https://github.com/rust-lang/rust-enhanced/ with the changes made here in the sublimehq repository.