1. vscode-json-languageservice
Language service for JSON
vscode-json-languageservice
Package: vscode-json-languageservice
Created by: Microsoft
Last modified: Mon, 22 Apr 2024 18:36:22 GMT
Version: 5.3.11
License: MIT
Downloads: 3,050,231
Repository: https://github.com/Microsoft/vscode-json-languageservice

Install

npm install vscode-json-languageservice
yarn add vscode-json-languageservice

vscode-json-languageservice

JSON language service extracted from VSCode to be reused, e.g in the Monaco editor.

npm Package
NPM Downloads
Build Status
License: MIT

Why?

The vscode-json-languageservice contains the language smarts behind the JSON editing experience of Visual Studio Code
and the Monaco editor.

  • doValidation analyses an input string and returns syntax and lint errors.
  • doComplete provides completion proposals for a given location.
  • doResolve resolves a completion proposals.
  • doHover provides a hover text for a given location.
  • findDocumentSymbols provides all symbols in the given document.
  • findDocumentColors provides all color symbols in the given document.
  • getColorPresentations returns available color formats for a color symbol.
  • format formats the code at the given range.
  • getFoldingRanges gets folding ranges for the given document.
  • getSelectionRanges gets selection ranges for a given location.
  • getMatchingSchemas matches a document against its schema and returns all AST nodes along with the matching sub schemas.
  • parseJSONDocument creates a JSON document from source code.
  • newJSONDocument creates a JSON document from an AST.

For the complete API see jsonLanguageService.ts and jsonLanguageTypes.ts

Installation

npm install --save vscode-json-languageservice

Sample usage

See sample.ts for an example on how to use the JSON language service.

To run the sample use yarn sample

Development

git clone https://github.com/microsoft/vscode-json-languageservice
cd vscode-json-languageservice
yarn

Use yarn test to compile and run tests

How can I run and debug the service?

  • open the folder in VSCode.
  • set breakpoints, e.g. in jsonCompletion.ts
  • run the Unit tests from the run viewlet and wait until a breakpoint is hit:
    image

How can I run and debug the service inside an instance of VSCode?

  • run VSCode out of sources setup as described here: https://github.com/Microsoft/vscode/wiki/How-to-Contribute
  • use yarn link vscode-json-languageservice in vscode/extensions/json-language-features/server to run VSCode with the latest changes from vscode-json-languageservice
  • run VSCode out of source (vscode/scripts/code.sh|bat) and open a .json file
  • in VSCode window that is open on the vscode-json-languageservice sources, run command Debug: Attach to Node process and pick the code-oss process with the json-language-features path
    image
  • set breakpoints, e.g. in jsonCompletion.ts
  • in the instance run from sources, invoke code completion in the .json file

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code