-
Notifications
You must be signed in to change notification settings - Fork 591
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
[YAML] Replace entity.name.tag with meta.mapping.key #2564
[YAML] Replace entity.name.tag with meta.mapping.key #2564
Conversation
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.
meta.mapping and meta.sequence ... nice.
Thanks for the suggestions. I think I addressed all your comments, please re-review. |
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.
LGTM
If this goes through, |
|
The key is also scoped as a key for me, but the property isn't. I'll add that to the look-ahead for correctness, but values currently aren't scoped in block collections at all, because matching is too inaccurate for those. We can add that later, imo. |
Turns out this isn't as simple as I was hoping to and it does make the syntax unnecessarily complex, imo. What should happen is rewriting the key and value pair detection using branching, but I won't get to that in the near future, so this quick(er) fix should do for now. |
Beyond the default color schemes, this is going to need a forward fill for color schemes in general. Moving from |
I wonder if we can find some kind of scope for such mapping keys in general. We need it in python mappings, json and even CSS might be a candidate to apply the Basically, even though it complies with JSON/YAML specs, I find it a bit weird to scope keys |
"Symbols" in Ruby use |
It definitly might be a good scope in case a key is used to access an item, like If we think of With the intention of #1861 in mind, too, I wonder if such a key should stay within the Not sure if it needs to apply to unquoted keys only. In Erlang for instance all identifiers may be quoted, without them denoting strings. The same applies to SCL/ST (structured text) used in automation systems. One point of this PR is to avoid too much scopes being stacked. Hence I guess |
So perhaps something like I could potentially see |
I have a good feeling about The point about |
I'm not sure about And besides JSON, which is a strict subset of YAML, such a change would also require changing it again in JavaScript, Python, Lua and possibly more if we aim for consistent scopes between languages. Furthermore, as you already mentioned, it's unclear to me whether
I think these are only CSS selectors and I would say they are somewhat different from key-value mappings. The properties actually use
JSON used |
The main issue I have with Of course, we can define a special syntax for that which doesn't use strings for context names. But that's basically YAML, so it makes sense to use the same base scopes. There are other use cases where users want goto defintion functionality for enumeration keys in C/C++. How is that so much different to structured data? Otherwise the |
No, boolean keys In general, I believe we have the following ways forward:
The following evaluation is from the perspective of "what if we started from zero". All solutions would require a forward-fill for compatibility with old color schemes anyway. Advantages:
Disadvantages:
I should mention that if we were to go for 2, I would question the usefulness of |
This expression is illegal in Python, only immutable types can be keys, but lists cannot. Otherwise I agree, if we use only |
Maybe ST can just ignore its |
I like this for an additional reason: YAML keys can be explicitly quoted strings, too: foo:
- bar
- baz
'bim': true Unfortunately, they're not scoped as keys at present.
Because I'm silly and pedantic sometimes: sure, but that list as a tuple can be a key. |
True, it indeed works with tuples. But I guess examples like this aren't used very often in practice, so I wonder how relevant it is for this discussion. And actually, I would see this more as an advantage for But I'm not sure which way is simpler or more robust from the implementation side and how exactly it is implemented right now in Python. |
In my proposal, I would only apply it to scalar elements, i.e. strings and numbers and without punctuation, since this would be more of a semantic scope name. |
Ok, but is it really useful to drop the punctuation, i.e. the string quotes from Anyways, I took some time and made a few experiments in Monokai and Mariana for the resulting highlighting colors, assuming a rule for Current highlighting (as of latest ST3): Alternative 1 (this PR): Alternative 2: I would still prefer the |
I currently support With DeathAxe's idea to drop the |
Yeah, color schemes need to be tweaked anyway as JSON looks pretty plain as well. Maybe someone should have a look into those merge conflicts. I am fine with this PR as well. |
Situation won't change with this PR assuming id keeps |
An attempt to fix quoted |
Introduce named contexts and explicitly distinguish yaml 1.1 and 1.2
Group all scalar-in.. and scalar-out... contexts.
Scope quoted keys `meta.mapping.key`.
Additionally implements some fixes for explicit block keys, now verified with tests.
Applied a similar solution to block keys as well while fixing some invalid explicit block key syntax. https://github.com/yaml/yaml-editor with the c-libfyaml parser is very useful for verifying YAML syntax, by the way. |
Two things I noticed:
|
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.
LGTM! Maybe two tiny code style improvements...
That's a general issue in most syntaxes. Tests started quite simple when introduced and matured to capture more edge cases and details. I guess PRs with improved test cases are wellcome in general. |
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.
With another headsup for sublimehq/sublime_text#3590 to @sublimehq to provide a good UX with regards to highlighting JSON/YAML, I am fine with this PR.
Note: Not patching the builtin color schemes will cause YAML to look pretty plain with this PR as JSON already does for years now, unfortunatelly.
The only thing needed for Mariana is something like:
{
"name": "Mapping Key Names",
"scope": "meta.mapping.key string",
"foreground": "var(red2)"
}
Monokai should be fixed as well to maintain the highlighting users are used to.
|
The contents of a squash merge commit are taken from all the squashed commits, afaik, so changing the OP should not matter here. I added @deathaxe's note regarding sublimehq/sublime_text#3590, however. Since the scoping of key-value separators mentioned in 3228 wasn't changed in this PR, it doesn't address anything of it (outside of not changing/violating it). |
🤷🏼♂️ Not sure why you made the commit message of the merged commit loose all the details that were provided above. |
Same here 😒 |
I've been wanting to do this for a while, as
entity.name.tag
was really just a hack for a lack of an appropriate scope name when I made this syntax. Now that JSON, JavaScript and Python (and probably other syntaxes) successfully usemeta.mapping.key
, YAML should not be exempted.(via #2564 (review))
Without addressing sublimehq/sublime_text#3590, the UX of default color schemes with regards to highlighting keys differently from values will be worse but in line with JSON and the other languages using
meta.mapping.key
as the primary differntiator between keys and values.The only thing needed for Mariana is something like:
Monokai should be fixed as well to maintain the highlighting users are used to.