Git Product home page Git Product logo

Comments (5)

aeschli avatar aeschli commented on July 3, 2024

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.

eriolchan avatar eriolchan commented on July 3, 2024

@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.

aeschli avatar aeschli commented on July 3, 2024

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.

aeschli avatar aeschli commented on July 3, 2024

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.

eriolchan avatar eriolchan commented on July 3, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.