-
Notifications
You must be signed in to change notification settings - Fork 29.4k
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
[json] colorize string literals based on language information coming from schemas #224581
Comments
Here's the PR that added the |
This would be a great addition! As someone that co-maintains SchemaStore, I lean towards the shared use of the |
Annotating the schema is only a first, small step, the challenge is how to do the coloring. Syntax highlighting happens on the renderer, through TextMate grammars and grammar injections. It has no access to the JSON schema which is loaded and evaluated from the JSON language extension, running in a process on the extension host. We don't have a way to dynamically inject rules on runtime. What could be done is to use semantic highlighting, in the JSON language extension, but that would mean implementing a parser for shell script. Help is welcome... |
This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 20 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation. Happy Coding! |
json-language-features
to support injecting embedded languages with JSON Schemas
@aeschli I'm thinking it would work similarly to how CSS and JS can be embedded in HTML, is that a lot different? |
With HTML, the HTML grammar includes the CSS and TypeScript grammars. when ever it sees The difference is that the coloring that you want is only for certain files and properties and only at runtime (once we have loaded and evaluated the schema) we know which ones. We have no mechanism to redefine/customize grammars at runtime. |
🙂 This feature request received a sufficient number of community upvotes and we moved it to our backlog. To learn more about how we handle feature requests, please see our documentation. Happy Coding! |
I could make an extension to do this I could then provide semantic syntax highlighting using TextMate or tree-sitter I don't see how it could be possible to provide a JSON TextMate grammar to do it perfectly (built-in TextMate syntax highlighting) |
@RedCMD No the JSON language extension does not have such an API. It's unclear to me how such an API would look like. Also I'd rather avoid dependencies between extensions. Maintaining APIs is a lot of work.
I would recommend not to worry about schema support first, but just look at e.g. syntax highlighting in |
I've created up a mock extension https://marketplace.visualstudio.com/items?itemName=RedCMD.json-embedded-languages |
The built in
json-language-features
extension provides plenty of nice features for JSON Schemas, such asmarkdownDescription
anddefaultSnippets
.I would love for it to also enable indicating that the value of a property is an embedded language.
Specifically I would love for the built in
npm
extension to be able to indicate that values within the"scripts"
property ofpackage.json
files areshellscript
values.Would make it easier to interpret and author complex npm-scripts setup such as this:
Implementation brainstorming
The current schema that the
npm
extension uses is json.schemastore.org/package:vscode/extensions/npm/package.json
Lines 314 to 318 in 444d7a4
It actually already contains something similar that's aimed at IntelliJ –
"x-intellij-language-injection": "Shell Script"
, which IntelliJ added in JetBrains/intellij-community@2e490ceHere's how it looks in the
package.json
schema:Maybe something similar, such as
"x-vscode-language-injection": "shellscript"
could work? Or, considering thatShell Script
is an alias ofshellscript
, consumex-intellij-language-injection
wherever it is available?Related discussions
Mostly stumbled upon people requesting this for yaml:
runs
keyword github/vscode-github-actions#266The text was updated successfully, but these errors were encountered: