Comments (5)
If you define your own language id, you basically have to duplicate the JSON basics extension (grammar, language configuration) and you have to provide your own language server. At least when you implement your server you can base it on the vscode-json-languageservice (which is what this repo is for).
Maybe explain why you realy need your own language id. What's special about your definition language?
from vscode-json-languageservice.
@aeschli here is our VSCode extension. It provides language support for DTDL which is a definition language based on JSON format.
Recently there is a user case to support: 1) user create new file, 2) select language mode (dtdl), 3) and then author by DTDL intelliSense. In this case, we need to add a new language id to declare the file type on demand. The tricky thing is that DTDL is just an ordinary JSON file with DTDL context/syntax, so the file extension is still *.json.
In the next step, we will build our own language server to handle DTDL intelliSense. When you mentioned we can base on vscode-json-languageservice, do you mean we can copy the code of (syntax highlight, bracket auto-close and JSON format validation) to our LS, or there is a library to leverage, or calling JSON language service? What's the best practice you recommend?
BTW, is tmLanuage.json able to provide the functions (syntax highlight, bracket auto-close and JSON format validation)?
from vscode-json-languageservice.
See https://code.visualstudio.com/api/language-extensions/overview for more information on language support.
- tmLanuage.json is only for syntax highlighting
- language-configuration is for auto-close, comments and the like.
- Validation, code complete, hovers come from providers that are ideally forwarding to a language server.
We have extracted all the JSON language smarts (validation, code complete, hovers) in the vscode-json-languageservice. It's a library that might be helpful as a base. There's another library jsonc-parser that implements the scanner/parser.
So yes, you basically have to copy and extend.
from vscode-json-languageservice.
I also want to say that if your language syntax is pure JSON, but with a specific properties and values, then you don't necessary need to define your own language but can just contribute additional providers to JSON. E.g. additional validation, hovers and code completion.
That way you don't have to redefine the full JSON support. Your providers will have to probe the file content or project information to figure out if it is DTDL file or not and only get active when it is.
The status bar would still show JSON. And you would use the regular JSON syntax highlighting and language configuration.
from vscode-json-languageservice.
Thanks for your advice, @aeschli. Your last suggestion is our existing solution, I will take your opinion and re-prioritize the use case of new language id.
from vscode-json-languageservice.
Related Issues (20)
- Assigning $ref to a path that has a pound sign throws an error HOT 1
- Request textDocument/documentSymbol failed. - Cannot read properties of undefined (reading 'range')
- Make JSONSchemaService an API
- defaultSnippets not showing following v5.3.0 HOT 2
- Intellisense recommends invalid schema uris for JSON Schema drafts HOT 2
- Unexpected token after updating to 5.3.5 HOT 1
- Validation of uuid format not working
- doHover seems to use the unresolved schema
- Package exports are problematic HOT 2
- insertFinalNewline should default to true
- anyOf error messaging is broken
- code completion breaks when anyOf defines `required` properties. HOT 2
- Regression: Problems loading reference schemaservice
- How to: $ref to external schemas in VSC
- Intellisense is missing JSON Schema versions 2019-09, 2020-12 HOT 3
- Support `title` schema property in completion items
- JSON Schema meta-schemas should not be downloaded
- Validation of uri-reference format does not seem to work well
- "time" format seems to be incorrectly excluding "00:00:00" HOT 1
- `getInfoContribution` is not composable HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vscode-json-languageservice.