-
Notifications
You must be signed in to change notification settings - Fork 11
👌 IMPROVE: Add jsonc #6
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| { | ||
| "$schema": "http://json-schema.org/draft-07/schema#", | ||
| "$id": "http://example.com/product.schema.json", | ||
| "title": "LSP-json settings", | ||
| "description": "Configure the LSP-json settings", | ||
| "type": "object", | ||
| "definitions": { | ||
| "language": { | ||
| "type": "object", | ||
| "additionalProperties": false, | ||
| "properties": { | ||
| "languageId": { | ||
| "type": "string", | ||
| "description": "See a list of available languages Ids in https://code.visualstudio.com/docs/languages/identifiers#_known-language-identifiers" | ||
| }, | ||
| "scopes": { | ||
| "description": "Array of scopes that will trigger the activation of the language server. Open `Tools/Developer/Show scope name` menu to get the scope name.", | ||
| "type": "array", | ||
| "items": { | ||
| "description": "Open `Tools/Developer/Show scope name` menu to get the scope name", | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "syntaxes": { | ||
| "description": "Array of sublime-syntaxt strings. Run `view.settings().get('syntax')` in sublime console to get the syntax.", | ||
| "type": "array", | ||
| "items": { | ||
| "description": "Run `view.settings().get('syntax')` in sublime console to get the syntax.", | ||
| "type": "string" | ||
| } | ||
| } | ||
| }, | ||
| "required": ["languageId", "scopes", "syntaxes"] | ||
| } | ||
| }, | ||
| "properties": { | ||
| "client": { | ||
| "type": "object", | ||
| "properties": { | ||
| "enabled": { | ||
| "type": "boolean" | ||
| }, | ||
| "languages": { | ||
| "type": "array", | ||
| "items": { | ||
| "$ref": "#/definitions/language" | ||
| } | ||
| }, | ||
| "initializationOptions": { | ||
| "type": "object" | ||
| }, | ||
| "settings": { | ||
| "type": "object" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| %YAML 1.2 | ||
| --- | ||
| name: JSONC | ||
| file_extensions: | ||
| - jsonc | ||
| - sublime-settings | ||
| - sublime-menu | ||
| - sublime-keymap | ||
| - sublime-mousemap | ||
| - sublime-theme | ||
| - sublime-build | ||
| - sublime-project | ||
| - sublime-completions | ||
| - sublime-commands | ||
| - sublime-macro | ||
| - sublime-color-scheme | ||
| - ipynb | ||
| - Pipfile.lock | ||
| scope: source.jsonc | ||
| contexts: | ||
| prototype: | ||
| - include: comments | ||
| main: | ||
| - include: value | ||
| value: | ||
| - include: constant | ||
| - include: number | ||
| - include: string | ||
| - include: array | ||
| - include: object | ||
| array: | ||
| - match: '\[' | ||
| scope: punctuation.section.sequence.begin.jsonc | ||
| push: | ||
| - meta_scope: meta.sequence.jsonc | ||
| - match: '\]' | ||
| scope: punctuation.section.sequence.end.jsonc | ||
| pop: true | ||
| - include: value | ||
| - match: "," | ||
| scope: punctuation.separator.sequence.jsonc | ||
| - match: '[^\s\]]' | ||
| scope: invalid.illegal.expected-sequence-separator.jsonc | ||
| comments: | ||
| - match: /\*\*(?!/) | ||
| scope: punctuation.definition.comment.jsonc | ||
| push: | ||
| - meta_scope: comment.block.documentation.jsonc | ||
| - meta_include_prototype: false | ||
| - match: \*/ | ||
| pop: true | ||
| - match: ^\s*(\*)(?!/) | ||
| captures: | ||
| 1: punctuation.definition.comment.jsonc | ||
| - match: /\* | ||
| scope: punctuation.definition.comment.jsonc | ||
| push: | ||
| - meta_scope: comment.block.jsonc | ||
| - meta_include_prototype: false | ||
| - match: \*/ | ||
| pop: true | ||
| - match: (//).*$\n? | ||
| scope: comment.line.double-slash.js | ||
| captures: | ||
| 1: punctuation.definition.comment.jsonc | ||
| constant: | ||
| - match: \b(?:true|false|null)\b | ||
| scope: constant.language.jsonc | ||
| number: | ||
| # handles integer and decimal numbers | ||
| - match: -?(?:0|[1-9]\d*)(?:(?:(\.)\d+)(?:[eE][-+]?\d+)?|(?:[eE][-+]?\d+)) | ||
| scope: constant.numeric.float.decimal.jsonc | ||
| captures: | ||
| 1: punctuation.separator.decimal.jsonc | ||
| - match: -?(?:0|[1-9]\d*) | ||
| scope: constant.numeric.integer.decimal.jsonc | ||
| object: | ||
| # a jsonc object | ||
| - match: '\{' | ||
| scope: punctuation.section.mapping.begin.jsonc | ||
| push: | ||
| - meta_scope: meta.mapping.jsonc | ||
| - match: '\}' | ||
| scope: punctuation.section.mapping.end.jsonc | ||
| pop: true | ||
| - match: '"' | ||
| scope: punctuation.definition.string.begin.jsonc | ||
| push: | ||
| - clear_scopes: 1 | ||
| - meta_scope: meta.mapping.key.jsonc string.quoted.double.jsonc | ||
| - meta_include_prototype: false | ||
| - include: inside-string | ||
| - match: ":" | ||
| scope: punctuation.separator.mapping.key-value.jsonc | ||
| push: | ||
| - match: ',|\s?(?=\})' | ||
| scope: invalid.illegal.expected-mapping-value.jsonc | ||
| pop: true | ||
| - match: (?=\S) | ||
| set: | ||
| - clear_scopes: 1 | ||
| - meta_scope: meta.mapping.value.jsonc | ||
| - include: value | ||
| - match: '' | ||
| set: | ||
| - match: ',' | ||
| scope: punctuation.separator.mapping.pair.jsonc | ||
| pop: true | ||
| - match: \s*(?=\}) | ||
| pop: true | ||
| - match: \s(?!/[/*])(?=[^\s,])|[^\s,] | ||
| scope: invalid.illegal.expected-mapping-separator.jsonc | ||
| pop: true | ||
| - match: '[^\s\}]' | ||
| scope: invalid.illegal.expected-mapping-key.jsonc | ||
| string: | ||
| - match: '"' | ||
| scope: punctuation.definition.string.begin.jsonc | ||
| push: inside-string | ||
| inside-string: | ||
| - meta_scope: string.quoted.double.jsonc | ||
| - meta_include_prototype: false | ||
| - match: '"' | ||
| scope: punctuation.definition.string.end.jsonc | ||
| pop: true | ||
| - include: string-escape | ||
| - match: $\n? | ||
| scope: invalid.illegal.unclosed-string.jsonc | ||
| pop: true | ||
| string-escape: | ||
| - match: |- | ||
| (?x: # turn on extended mode | ||
| \\ # a literal backslash | ||
| (?: # ...followed by... | ||
| ["\\/bfnrt] # one of these characters | ||
| | # ...or... | ||
| u # a u | ||
| [0-9a-fA-F]{4} # and four hex digits | ||
| ) | ||
| ) | ||
| scope: constant.character.escape.jsonc | ||
| - match: \\. | ||
| scope: invalid.illegal.unrecognized-string-escape.jsonc | ||
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.
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.
What's the point of this sublime-syntax file?
Uh oh!
There was an error while loading. Please reload this page.
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 think He doesn't want this plugin to depend on
PackageDevso he creates it for sublime-related files. Otherwise, users can directly use #6 (comment) in their settings to activate LSP-json.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.
Yes, that is the point.
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 don't like it :( The PackageDev syntaxes have great highlighting. What's more is that there is already a syntax for JSON with comments at Packages/JavaScript/JSON.sublime-syntax.
Why does this plugin need to depend on PackageDev in the first place?
Also, why not write a language server for json-with-comments?
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.
Why not put
jsoncinstead ofjsonfor the languageId? Wouldn't that make the json-language-server shut up about comments? https://github.com/sublimelsp/LSP-json/blob/master/plugin.py#L85https://github.com/vscode-langservers/vscode-json-languageserver#server-capabilities
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 see now that this pull request modifies the languageId from
jsontojsonc. So that should already remove the errors about comments. So then why not use Packages/JavaScript/JSON.sublime-syntax? Remember that maintaining a custom JSON syntax is some serious maintainer burden...Uh oh!
There was an error while loading. Please reload this page.
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 don't like this solution either (maybe because I have PackageDev installed :D ), but...
ST's JSON doesn't differentiate
jsonandjsoncsince it treats everything asjsonc. If we do so, LSP will not treat a comma (and comment) in a JSON file as an error. If we want a way to differentiate them, then either via a 3rd-party (PackageDev) or creates our own...Another way to not actually maintain the syntax "definition" is something like:
It results in a base scope
source.jsoncwith other....jsonsubscopes.But there is no guarantee that ST will chooses your syntax definition over
PackageDev's (or other 3rd-party plugin's). I don't know how ST chooses the syntax when there are multiple qualified candidates.