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

Scope for keys in mappings/dictionaries (e.g. JSON, YAML) #421

Open
FichteFoll opened this issue May 21, 2016 · 9 comments
Open

Scope for keys in mappings/dictionaries (e.g. JSON, YAML) #421

FichteFoll opened this issue May 21, 2016 · 9 comments
Labels

Comments

@FichteFoll
Copy link
Collaborator

FichteFoll commented May 21, 2016

Terminology:

  • A colored scope is a scope name that most color schemes define a color for. Examples include string, entity or constant and specifications of those.
  • An uncolored scope is a scope name that is usually not colored, mainly meta and puncutation scopes.

Introduction

I'd like to discuss the standardization of a specific scope name for key elements in dictionaries or mappings or objects or whatever you call them in your language.

Currently, the JSON definition doesn't have any specific highlighting for keys which it could certainly use and I inteded to add for a while (see also wbond/package_control_channel#5496). There are different scopes for the key and value, but in a way that makes it impossible to specifically target the key with a selector.

In the YAML definition entity.name.tag is used, which is a "steal" from xml-like syntaxes where entity.name.tag should denote a tag name.

In most programming languages, no special highlighting is done.

Earlier this year, the JavaScript syntax was updated with a colored scope for keys in object literals, but many people seemed opposed of this change (hurr change is bad durr), thus causing the change to be reverted and an uncolored meta scope being used instead.

Concluding questions

  1. Should keys be highlighted with a "colored" scope and which one should it be? I personally like entity.name.key.
  2. Should keys not be highlighted and get an "uncolored" meta scope instead?
  3. Decide on a case-by-case basis? How complex would this be for color scheme creation?
@FichteFoll FichteFoll changed the title ⟦Discussion⟧ Scope for keys in mappings/dictionaries (e.g. JSON, YAML) Discussion - Scope for keys in mappings/dictionaries (e.g. JSON, YAML) May 21, 2016
@FichteFoll FichteFoll changed the title Discussion - Scope for keys in mappings/dictionaries (e.g. JSON, YAML) Discussion: Scope for keys in mappings/dictionaries (e.g. JSON, YAML) May 21, 2016
@keith-hall
Copy link
Collaborator

Personally, the first thing I do when I install ST on a new machine is modify the color scheme to highlight JSON keys. To me, it just looks wrong to have it not colored. Especially as punctuation is not colored, its harder to distinguish at a glance, where a key ends and the punctuation begins. Keys are strings and should be highlighted - simple as IMO ;)

As for scope name, I have an additional question - do we want any keys to show up in "Goto Anything"? I believe that at a minimum, "root" level keys should appear here for easier document traversal, but that's just my 2 cents. entity.name.key works for me, I like that the beginning is consistent with xml "keys" - entity.name.tag.

@keith-hall
Copy link
Collaborator

keith-hall commented May 21, 2016

The sublime-syntax definition PR uses entity.name[...] for contexts, which I find super useful - I can just Goto Definition on an include or push etc. to find it. Not sure if it would work for/benefit other YAML documents or not though if it were made generic for all YAML files, as I don't use YAML for anything else.

Obviously I realise that a different selector could be used for symbols, but again, I like the consistency - all symbols are therefore automatically/by default colored the same by the color schemes, no extra work required.

@FichteFoll
Copy link
Collaborator Author

FichteFoll commented May 21, 2016

Oh, I might as well voice my opinion too. I'm strongly in favor of 1 for all languages. It just makes things more consistent and it makes sense to highlight "string keys" differently compared to "normal strings".
There are always going to be some of these people.

The YAML-tmLanguage also uses some entity.name scope for pattern keys and adds them to the symbol list. For YAML in general, I would use https://github.com/ddiachkov/sublime-yaml-nav instead, which computes the full path of a key when pressing ctrl+r (overriding key binding).

PS: I need to check out the sublime-syntax def PR and see if I can work with it. Since I made the YAML def, I might tune it to be more precise and won't have to start from scratch, which I originally intended.

@wbond
Copy link
Member

wbond commented May 25, 2016

Combining a meta scope with a proper scope for the key makes the most "general" sense to me. For instance, meta.key string.quoted.double. That way keys can be targeted by color schemes, however I can see in some situations wanting keys to be indexed, in which case entity.name makes sense.

I don't know if this is going to be something we can fully standardize.

@wbond wbond added the question label Jun 1, 2016
@keith-hall
Copy link
Collaborator

One thing I did for my sublime-snippet PR (#576) was to use the meta.toc-list scope, to allow easier navigation using Goto Symbol. Probably overkill for snippets, but also allows color schemes to give the "keys" different colors if they desire.

@wbond wbond added RFC and removed question labels Dec 16, 2016
@wbond wbond changed the title Discussion: Scope for keys in mappings/dictionaries (e.g. JSON, YAML) Scope for keys in mappings/dictionaries (e.g. JSON, YAML) Dec 16, 2016
@FichteFoll
Copy link
Collaborator Author

FichteFoll commented Mar 25, 2017

Because I work a lot with syntax definition for JSON-based file formats currently, I took a look into this again.

I have collected a few examples for "keys" in different languages.

JSON

{"key": "value", "key2": null, "3": 3, "key4": 3.14}

JSON only allows strings as keys, which must be quoted.

JavaScript

var o = {key: "value", "key2": null, 3: 3, "key4": 3.14}

JS seems to allow quoted strings as keys and treats everything else as an unquoted string.

When looking up values, it seems that they are converted to strings, because o[3] and o["3"] do the same thing.
You can also use o[undefined] if o has a key named "undefined".

Python

d = {"key": "value", "key2": None, 3: 3, "key4": 3.14}

Python evaluates keys the same way it does for values.
Some objects are not allowed as keys because they are unhashable (e.g. lists and dicts).

Lua

local t = {key = "value", key2 = nil, [3] = 3, ["key4"] = 3.14}

Lua only allows unquoted strings as its table keys, unless you wrap the key in [] brackets, in which case it is evaluated.

(Unlike in Python, you can also use tables as keys but they only compare by reference.)


With these examples, we can observe:

  1. Not all languages only use strings for keys.
  2. Some languages have string keys quoted, some do not.

This leads myself to the following conclusions, respectively:

  1. An explicit scope with entity isn't good since it would potentially mask other scopes such as constant.numeric or entire structures (e.g. tuples as keys in Python dicts).
    A meta.key scope for the entire key would be most appropriate.
  2. All languages with unquoted string keys should have their keys scoped as such (i.e. string.unquoted.key), in addition to the meta scope.

This allows color schemes to target the entire key in general (meta.key) and string keys specifically (meta.key string).

Remaining issue

When strings appear in a structure/expression that is used as a key (tuples or function calls in dicts for Python), they would get matched by meta.key string as well.
It might be possible to exclude these matching meta.key string - meta.key meta instead, but this remains to be tested. This also implies that there should not be meta scope names between meta.key and string if they both cover the same token(s).

@wbond
Copy link
Member

wbond commented Mar 25, 2017

If I recall correctly, JavaScript has keys scoped as unquoted strings and there was a huge backlash over the change. See #141.

While I understand the argument for string.unquoted, I don't think that is going to be a tenable change. I think the only option would be to introduce something like identifier.key or variable.key for object literal keys in JS.

Also note that JavaScript supports expression as keys:

{
[myvar==true ? 'one' : 'two']: 'value'
}

@FichteFoll
Copy link
Collaborator Author

FichteFoll commented Mar 25, 2017

If I recall correctly, JavaScript has keys scoped as unquoted strings and there was a huge backlash over the change. See #141.

Yes, and they do have a point there, because to them the change did exactly the opposite of what we are trying to achieve here. We want to standardize scopes for different colorization of keys, while the change they complained about was that their keys look the same as the values. Special-casing JavaScript object keys with a different scope name seems contradictory here.

JS and Lua share a common trait (besides unquoted keys) in that they both use the same data structure for both "mappings" and "objects" and use attribute-access syntax synonymously with item-access syntax (t.key1 == t["key1"]). You also touched on this earlier (#141 (comment)). I will need to think about this and probably have to look at some real-world JavaScript to judge on this.

This post was edited.

@FichteFoll
Copy link
Collaborator Author

FichteFoll commented Mar 25, 2017

Patching the seemingly most popular color scheme, Monokai, to support these scope changes should be an easy step forward and pave the way for other scheme authors.

Ensuring the other most popular color schemes (on Package Control) are updated before the next beta build should be possible as well. We might want to consider a mailing list, a platform (the forum) or just a github issue with announcements about the default packages and scope naming standards for color scheme developers.

What I'm mostly concerned is: If we are to averse from change, nothing may change at all. I'm sure some people won't like the changes to Python decorators either because their color will change, for example. There will also be people who prefer to have their JSON keys be colored the same as their values (God knows why).
We should be looking for ways that allow us to do these changes when we consider them appropriate.

FichteFoll added a commit to SublimeText/PackageDev that referenced this issue Mar 29, 2017
deathaxe pushed a commit to deathaxe/PackageDev that referenced this issue Jan 5, 2019
This commit scopes the first line after a push/set statement as
`meta.expect-include-list-or-content`.

The following lines are scoped as `meta.include-list` until a none-empty line with a different indention level is detected or it
does not start with a `-` in case the first line is an include.

If the first line does not contain an include, no special scoping is
performed. The sequence is handled as normal `context_content` then.

Some more test cases were added to ensure correctness of the changes.

Note:

1. By pushing into a dedicated context for includes, the
   `meta.include-list` covers `\n` by design the same way as any
   `meta.block` or `meta.group` does in other syntax definitions.
   The include-list ends with the `\n` of the last include-item.

2. The `meta.flow-sequence.yaml` was removed because:
   a) it does not have any function
   b) it seems dedicated for arrays `[]`
   c) it is not part of the default YAML.sublime-syntax
   d) it does not comply with sublimehq/Packages#421
jrappen added a commit to jrappen/Packages that referenced this issue May 31, 2022
- Using inheritance split up `JSON.sublime-syntax` into:
    - `JSON.sublime-syntax` with `scope:source.json`
    - `JSONC.sublime-syntax` with `scope:source.json.jsonc`
    - `JSON5.sublime-syntax` with `scope:source.json.json5`
    - `JSON_dotNET.sublime-syntax` with `scope:source.json.json-dotnet`
- Add many more file extensions for `JSON` & `JSONC`:
    - add doc links to extensions where applicable as a reference to be
      able to more quickly verify that they (still) use said syntax
      flavor
- JSON:
    - Make use of newer syntax features including those only available
      in `version: 2` syntaxes
    - Make use of `variables` (with optimizations provided by @deathaxe
      and regex patterns provided by @Thom1729)
    - Context names now more closely match the naming scheme of other
      (recently re-written) default syntaxes
    - (correctly formatted) JSON code can now be prettified or minified
      via the context menu or the command palette. JSON code can
      optionally be auto-prettified on pre save events.
    - highlight leading, trailing & multiple commas as invalid
    - only allow exactly one structure (object, array) or value
      (constant, number, string) at top level (thanks to @keith-hall)
    - links (`meta.link.inet`) and email addresses (`meta.link.email`) are
      scoped the same as in Markdown (thanks to @deathaxe)
- JSONC:
    - highlight some files by default as `JSONC` (as decided by
      @jskinner in sublimehq#285)
    - highlight leading & multiple commas as invalid, trailing as valid
    - scope empty block comments as such
    - support syntax based folding of ST4131+,
      compare sublimehq#3291
- JSON5:
    - explicitly pos numbers, hexadecimal ints, Infinity and NaN
    - single quoted strings
    - more escape chars for strings
    - ECMA identifierName as object keys (regexes thanks to @Thom1729)
        - scoped as plain unquoted strings (thanks to @Thom1729)
        - support string interpolation (thanks to @deathaxe)
    - line continuation in strings (with tests thanks to @keith-hall)
- JSON.NET:
    - support requested by @keith-hall,
      built with feedback from @michaelblyons
- Objects:
    - Highlighting speed improvements for empty objects (thanks to
      @FichteFoll)
    - Make `mapping.*` contexts more modular
- Arrays:
    - Highlighting speed improvements for empty arrays (thanks to
      @FichteFoll)
- Numbers:
    - Correctly scope number signs with `constant.numeric.sign` instead
      of `keyword.operator.arithmetic`
    - Significantly improve number highlighting (thanks to @deathaxe)
- Completions:
    - completions have been added for language constants, including kind info
      and details (with links to docs)
        - `null`, `false`, `true` for JSON
        - `Infinity` and `NaN` for JSON5
- Settings:
    - a `default_extension` is now set for all JSON flavors
- Symbol index:
    - with an object structure at the top-level, only top-level keys
      within now show up in the index (including tests for symbols and
      syntax)
- Tests:
    - test files now test the base scope
    - Significantly extend tests to cover more parts of the syntaxes
    - Split original test file into logical parts
    - Add indentation tests for:
        - `json`, `json5` & `jsonc`
        - `mapping` (objects), `sequence` (arrays)
    - Add symbols tests for:
        - top-level keys of object structures (thanks to deathaxe)
        - languages: `json`, `json5` & `jsonc`
    - Fix tests for `meta.mapping meta.mapping.*`
- Leave `JSON` headers in `Markdown` as `json` only, but split up fenced
  code blocks into `json`, `json5` & `jsonc` to behave similarly to
  `GitHub Flavored Markdown`

BREAKING CHANGES:

- JSON does not have values that can be set via an inline calculation
  with the help of operators, but only simple number values. Scopes for
  number signs have changed from being `keyword.operator.arithmetic` to
  `constant.numeric.sign`. Color scheme authors should add this, should
  it be missing.
- The `JSON.sublime-syntax` now marks comments as `invalid`, third party
  plugin authors should instead target `JSONC.sublime-syntax` to keep
  the user experience as-is.
- Indexed symbols (i.e. top-level keys in JSON object structures) are
  scoped as `source.json meta.mapping.key - (meta.mapping.value meta.mapping.key | meta.sequence.list meta.mapping.key)`.
  Color scheme authors should add special highlighting to differentiate
  them from other keys.

- fix sublimehq#285
- address sublimehq#421 (thanks to @FichteFoll)
- address sublimehq#481 to remove incompatible regex patterns according
  to @wbond
- address sublimehq#757 to fix line comments for `JSONC` (thanks to
  @keith-hall)
- address sublimehq#2430 using sort-order (as requested by @deathaxe)
- address sublimehq#2711 with regards to `constant.language.null`
  vs. `constant.language.empty` (thanks to @FichteFoll)
- address sublimehq#2852 to fix scopes of curly braces & square
  brackets in `JSON` (thanks to @Thom1729)
- address sublimehq#3228 to fix `punctuation.separator` scopes,
  compare sublimehq#3270
- address sublimehq/sublime_text#3154 and add symbol tests

Co-authored-by: Ashwin Shenoy <[email protected]>
Co-authored-by: Jack Cherng <[email protected]>
Co-authored-by: Janos Wortmann <[email protected]>
Co-authored-by: Jon Skinner <[email protected]>
Co-authored-by: FichteFoll <[email protected]>
Co-authored-by: Keith Hall <[email protected]>
Co-authored-by: Michael B. Lyons <[email protected]>
Co-authored-by: Rafał Chłodnicki <[email protected]>
Co-authored-by: Thomas Smith <[email protected]>
Co-authored-by: Will Bond <[email protected]>
Co-authored-by: deathaxe <[email protected]>
jrappen added a commit to jrappen/Packages that referenced this issue May 31, 2022
- Using inheritance split up `JSON.sublime-syntax` into:
    - `JSON.sublime-syntax` with `scope:source.json`
    - `JSONC.sublime-syntax` with `scope:source.json.jsonc`
    - `JSON5.sublime-syntax` with `scope:source.json.json5`
    - `JSON_dotNET.sublime-syntax` with `scope:source.json.json-dotnet`
- Add many more file extensions for `JSON` & `JSONC`:
    - add doc links to extensions where applicable as a reference to be
      able to more quickly verify that they (still) use said syntax
      flavor
- JSON:
    - Make use of newer syntax features including those only available
      in `version: 2` syntaxes
    - Make use of `variables` (with optimizations provided by @deathaxe
      and regex patterns provided by @Thom1729)
    - Context names now more closely match the naming scheme of other
      (recently re-written) default syntaxes
    - (correctly formatted) JSON code can now be prettified or minified
      via the context menu or the command palette. JSON code can
      optionally be auto-prettified on pre save events.
    - highlight leading, trailing & multiple commas as invalid
    - only allow exactly one structure (object, array) or value
      (constant, number, string) at top level (thanks to @keith-hall)
    - links (`meta.link.inet`) and email addresses (`meta.link.email`) are
      scoped the same as in Markdown (thanks to @deathaxe)
- JSONC:
    - highlight some files by default as `JSONC` (as decided by
      @jskinner in sublimehq#285)
    - highlight leading & multiple commas as invalid, trailing as valid
    - scope empty block comments as such
    - support syntax based folding of ST4131+,
      compare sublimehq#3291
- JSON5:
    - explicitly pos numbers, hexadecimal ints, Infinity and NaN
    - single quoted strings
    - more escape chars for strings
    - ECMA identifierName as object keys (regexes thanks to @Thom1729)
        - scoped as plain unquoted strings (thanks to @Thom1729)
        - support string interpolation (thanks to @deathaxe)
    - line continuation in strings (with tests thanks to @keith-hall)
- JSON.NET:
    - support requested by @keith-hall,
      built with feedback from @michaelblyons
- Objects:
    - Highlighting speed improvements for empty objects (thanks to
      @FichteFoll)
    - Make `mapping.*` contexts more modular
- Arrays:
    - Highlighting speed improvements for empty arrays (thanks to
      @FichteFoll)
- Numbers:
    - Correctly scope number signs with `constant.numeric.sign` instead
      of `keyword.operator.arithmetic`
    - Significantly improve number highlighting (thanks to @deathaxe)
- Completions:
    - completions have been added for language constants, including kind info
      and details (with links to docs)
        - `null`, `false`, `true` for JSON
        - `Infinity` and `NaN` for JSON5
- Settings:
    - a `default_extension` is now set for all JSON flavors
- Symbol index:
    - with an object structure at the top-level, only top-level keys
      within now show up in the index (including tests for symbols and
      syntax)
- Tests:
    - test files now test the base scope
    - Significantly extend tests to cover more parts of the syntaxes
    - Split original test file into logical parts
    - Add indentation tests for:
        - `json`, `json5` & `jsonc`
        - `mapping` (objects), `sequence` (arrays)
    - Add symbols tests for:
        - top-level keys of object structures (thanks to deathaxe)
        - languages: `json`, `json5` & `jsonc`
    - Fix tests for `meta.mapping meta.mapping.*`
- Leave `JSON` headers in `Markdown` as `json` only, but split up fenced
  code blocks into `json`, `json5` & `jsonc` to behave similarly to
  `GitHub Flavored Markdown`

BREAKING CHANGES:

- JSON does not have values that can be set via an inline calculation
  with the help of operators, but only simple number values. Scopes for
  number signs have changed from being `keyword.operator.arithmetic` to
  `constant.numeric.sign`. Color scheme authors should add this, should
  it be missing.
- The `JSON.sublime-syntax` now marks comments as `invalid`, third party
  plugin authors should instead target `JSONC.sublime-syntax` to keep
  the user experience as-is.
- Indexed symbols (i.e. top-level keys in JSON object structures) are
  scoped as `source.json meta.mapping.key - (meta.mapping.value meta.mapping.key | meta.sequence.list meta.mapping.key)`.
  Color scheme authors should add special highlighting to differentiate
  them from other keys.

- fix sublimehq#285
- address sublimehq#421 (thanks to @FichteFoll)
- address sublimehq#481 to remove incompatible regex patterns according
  to @wbond
- address sublimehq#757 to fix line comments for `JSONC` (thanks to
  @keith-hall)
- address sublimehq#2430 using sort-order (as requested by @deathaxe)
- address sublimehq#2711 with regards to `constant.language.null`
  vs. `constant.language.empty` (thanks to @FichteFoll)
- address sublimehq#2852 to fix scopes of curly braces & square
  brackets in `JSON` (thanks to @Thom1729)
- address sublimehq#3228 to fix `punctuation.separator` scopes,
  compare sublimehq#3270
- address sublimehq/sublime_text#3154 and add symbol tests

Co-authored-by: Ashwin Shenoy <[email protected]>
Co-authored-by: Jack Cherng <[email protected]>
Co-authored-by: Janos Wortmann <[email protected]>
Co-authored-by: Jon Skinner <[email protected]>
Co-authored-by: FichteFoll <[email protected]>
Co-authored-by: Keith Hall <[email protected]>
Co-authored-by: Michael B. Lyons <[email protected]>
Co-authored-by: Rafał Chłodnicki <[email protected]>
Co-authored-by: Thomas Smith <[email protected]>
Co-authored-by: Will Bond <[email protected]>
Co-authored-by: deathaxe <[email protected]>
jrappen added a commit to jrappen/Packages that referenced this issue May 31, 2022
- Using inheritance split up `JSON.sublime-syntax` into:
    - `JSON.sublime-syntax` with `scope:source.json`
    - `JSONC.sublime-syntax` with `scope:source.json.jsonc`
    - `JSON5.sublime-syntax` with `scope:source.json.json5`
    - `JSON_dotNET.sublime-syntax` with `scope:source.json.json-dotnet`
- Add many more file extensions for `JSON` & `JSONC`:
    - add doc links to extensions where applicable as a reference to be
      able to more quickly verify that they (still) use said syntax
      flavor
- JSON:
    - Make use of newer syntax features including those only available
      in `version: 2` syntaxes
    - Make use of `variables` (with optimizations provided by @deathaxe
      and regex patterns provided by @Thom1729)
    - Context names now more closely match the naming scheme of other
      (recently re-written) default syntaxes
    - (correctly formatted) JSON code can now be prettified or minified
      via the context menu or the command palette. JSON code can
      optionally be auto-prettified on pre save events.
    - highlight leading, trailing & multiple commas as invalid
    - only allow exactly one structure (object, array) or value
      (constant, number, string) at top level (thanks to @keith-hall)
    - links (`meta.link.inet`) and email addresses (`meta.link.email`) are
      scoped the same as in Markdown (thanks to @deathaxe)
- JSONC:
    - highlight some files by default as `JSONC` (as decided by
      @jskinner in sublimehq#285)
    - highlight leading & multiple commas as invalid, trailing as valid
    - scope empty block comments as such
    - support syntax based folding of ST4131+,
      compare sublimehq#3291
- JSON5:
    - explicitly pos numbers, hexadecimal ints, Infinity and NaN
    - single quoted strings
    - more escape chars for strings
    - ECMA identifierName as object keys (regexes thanks to @Thom1729)
        - scoped as plain unquoted strings (thanks to @Thom1729)
        - support string interpolation (thanks to @deathaxe)
    - line continuation in strings (with tests thanks to @keith-hall)
- JSON.NET:
    - support requested by @keith-hall,
      built with feedback from @michaelblyons
- Objects:
    - Highlighting speed improvements for empty objects (thanks to
      @FichteFoll)
    - Make `mapping.*` contexts more modular
- Arrays:
    - Highlighting speed improvements for empty arrays (thanks to
      @FichteFoll)
- Numbers:
    - Correctly scope number signs with `constant.numeric.sign` instead
      of `keyword.operator.arithmetic`
    - Significantly improve number highlighting (thanks to @deathaxe)
- Completions:
    - completions have been added for language constants, including kind info
      and details (with links to docs)
        - `null`, `false`, `true` for JSON
        - `Infinity` and `NaN` for JSON5
- Settings:
    - a `default_extension` is now set for all JSON flavors
- Symbol index:
    - with an object structure at the top-level, only top-level keys
      within now show up in the index (including tests for symbols and
      syntax)
- Tests:
    - test files now test the base scope
    - Significantly extend tests to cover more parts of the syntaxes
    - Split original test file into logical parts
    - Add indentation tests for:
        - `json`, `json5` & `jsonc`
        - `mapping` (objects), `sequence` (arrays)
    - Add symbols tests for:
        - top-level keys of object structures (thanks to deathaxe)
        - languages: `json`, `json5` & `jsonc`
    - Fix tests for `meta.mapping meta.mapping.*`
- Leave `JSON` headers in `Markdown` as `json` only, but split up fenced
  code blocks into `json`, `json5` & `jsonc` to behave similarly to
  `GitHub Flavored Markdown`

BREAKING CHANGES:

- JSON does not have values that can be set via an inline calculation
  with the help of operators, but only simple number values. Scopes for
  number signs have changed from being `keyword.operator.arithmetic` to
  `constant.numeric.sign`. Color scheme authors should add this, should
  it be missing.
- The `JSON.sublime-syntax` now marks comments as `invalid`, third party
  plugin authors should instead target `JSONC.sublime-syntax` to keep
  the user experience as-is.
- Indexed symbols (i.e. top-level keys in JSON object structures) are
  scoped as `source.json meta.mapping.key - (meta.mapping.value meta.mapping.key | meta.sequence.list meta.mapping.key)`.
  Color scheme authors should add special highlighting to differentiate
  them from other keys.

- fix sublimehq#285
- address sublimehq#421 (thanks to @FichteFoll)
- address sublimehq#481 to remove incompatible regex patterns according
  to @wbond
- address sublimehq#757 to fix line comments for `JSONC` (thanks to
  @keith-hall)
- address sublimehq#2430 using sort-order (as requested by @deathaxe)
- address sublimehq#2711 with regards to `constant.language.null`
  vs. `constant.language.empty` (thanks to @FichteFoll)
- address sublimehq#2852 to fix scopes of curly braces & square
  brackets in `JSON` (thanks to @Thom1729)
- address sublimehq#3228 to fix `punctuation.separator` scopes,
  compare sublimehq#3270
- address sublimehq/sublime_text#3154 and add symbol tests

Co-authored-by: Ashwin Shenoy <[email protected]>
Co-authored-by: Jack Cherng <[email protected]>
Co-authored-by: Janos Wortmann <[email protected]>
Co-authored-by: Jon Skinner <[email protected]>
Co-authored-by: FichteFoll <[email protected]>
Co-authored-by: Keith Hall <[email protected]>
Co-authored-by: Michael B. Lyons <[email protected]>
Co-authored-by: Rafał Chłodnicki <[email protected]>
Co-authored-by: Thomas Smith <[email protected]>
Co-authored-by: Will Bond <[email protected]>
Co-authored-by: deathaxe <[email protected]>
jrappen added a commit to jrappen/Packages that referenced this issue Jun 1, 2022
- Using inheritance split up `JSON.sublime-syntax` into:
    - `JSON.sublime-syntax` with `scope:source.json`
    - `JSONC.sublime-syntax` with `scope:source.json.jsonc`
    - `JSON5.sublime-syntax` with `scope:source.json.json5`
    - `JSON_dotNET.sublime-syntax` with `scope:source.json.json-dotnet`
- Add many more file extensions for `JSON` & `JSONC`:
    - add doc links to extensions where applicable as a reference to be
      able to more quickly verify that they (still) use said syntax
      flavor
- JSON:
    - Make use of newer syntax features including those only available
      in `version: 2` syntaxes
    - Make use of `variables` (with optimizations provided by @deathaxe
      and regex patterns provided by @Thom1729)
    - Context names now more closely match the naming scheme of other
      (recently re-written) default syntaxes
    - (correctly formatted) JSON code can now be prettified or minified
      via the context menu or the command palette. JSON code can
      optionally be auto-prettified on pre save events.
    - highlight leading, trailing & multiple commas as invalid
    - only allow exactly one structure (object, array) or value
      (constant, number, string) at top level (thanks to @keith-hall)
    - links (`meta.link.inet`) and email addresses (`meta.link.email`) are
      scoped the same as in Markdown (thanks to @deathaxe)
- JSONC:
    - highlight some files by default as `JSONC` (as decided by
      @jskinner in sublimehq#285)
    - highlight leading & multiple commas as invalid, trailing as valid
    - scope empty block comments as such
    - support syntax based folding of ST4131+,
      compare sublimehq#3291
- JSON5:
    - explicitly pos numbers, hexadecimal ints, Infinity and NaN
    - single quoted strings
    - more escape chars for strings
    - ECMA identifierName as object keys (regexes thanks to @Thom1729)
        - scoped as plain unquoted strings (thanks to @Thom1729)
        - support string interpolation (thanks to @deathaxe)
    - line continuation in strings (with tests thanks to @keith-hall)
- JSON.NET:
    - support requested by @keith-hall,
      built with feedback from @michaelblyons
- Objects:
    - Highlighting speed improvements for empty objects (thanks to
      @FichteFoll)
    - Make `mapping.*` contexts more modular
- Arrays:
    - Highlighting speed improvements for empty arrays (thanks to
      @FichteFoll)
- Numbers:
    - Correctly scope number signs with `constant.numeric.sign` instead
      of `keyword.operator.arithmetic`
    - Significantly improve number highlighting (thanks to @deathaxe)
- Completions:
    - completions have been added for language constants, including kind info
      and details (with links to docs)
        - `null`, `false`, `true` for JSON
        - `Infinity` and `NaN` for JSON5
- Settings:
    - a `default_extension` is now set for all JSON flavors
- Symbol index:
    - with an object structure at the top-level, only top-level keys
      within now show up in the index (including tests for symbols and
      syntax)
- Tests:
    - test files now test the base scope
    - Significantly extend tests to cover more parts of the syntaxes
    - Split original test file into logical parts
    - Add indentation tests for:
        - `json`, `json5` & `jsonc`
        - `mapping` (objects), `sequence` (arrays)
    - Add symbols tests for:
        - top-level keys of object structures (thanks to deathaxe)
        - languages: `json`, `json5` & `jsonc`
    - Fix tests for `meta.mapping meta.mapping.*`
- Leave `JSON` headers in `Markdown` as `json` only, but split up fenced
  code blocks into `json`, `json5` & `jsonc` to behave similarly to
  `GitHub Flavored Markdown`

BREAKING CHANGES:

- JSON does not have values that can be set via an inline calculation
  with the help of operators, but only simple number values. Scopes for
  number signs have changed from being `keyword.operator.arithmetic` to
  `constant.numeric.sign`. Color scheme authors should add this, should
  it be missing.
- The `JSON.sublime-syntax` now marks comments as `invalid`, third party
  plugin authors should instead target `JSONC.sublime-syntax` to keep
  the user experience as-is.
- Indexed symbols (i.e. top-level keys in JSON object structures) are
  scoped as `source.json meta.mapping.key - (meta.mapping.value meta.mapping.key | meta.sequence.list meta.mapping.key)`.
  Color scheme authors should add special highlighting to differentiate
  them from other keys.

- fix sublimehq#285
- address sublimehq#421 (thanks to @FichteFoll)
- address sublimehq#481 to remove incompatible regex patterns according
  to @wbond
- address sublimehq#757 to fix line comments for `JSONC` (thanks to
  @keith-hall)
- address sublimehq#2430 using sort-order (as requested by @deathaxe)
- address sublimehq#2711 with regards to `constant.language.null`
  vs. `constant.language.empty` (thanks to @FichteFoll)
- address sublimehq#2852 to fix scopes of curly braces & square
  brackets in `JSON` (thanks to @Thom1729)
- address sublimehq#3228 to fix `punctuation.separator` scopes,
  compare sublimehq#3270
- address sublimehq/sublime_text#3154 and add symbol tests

Co-authored-by: Ashwin Shenoy <[email protected]>
Co-authored-by: Jack Cherng <[email protected]>
Co-authored-by: Janos Wortmann <[email protected]>
Co-authored-by: Jon Skinner <[email protected]>
Co-authored-by: FichteFoll <[email protected]>
Co-authored-by: Keith Hall <[email protected]>
Co-authored-by: Michael B. Lyons <[email protected]>
Co-authored-by: Rafał Chłodnicki <[email protected]>
Co-authored-by: Thomas Smith <[email protected]>
Co-authored-by: Will Bond <[email protected]>
Co-authored-by: deathaxe <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants