2016-06-24 11:50:27 +03:00
# vscode-json-languageservice
2020-10-24 21:02:57 +03:00
2016-06-24 11:50:27 +03:00
JSON language service extracted from VSCode to be reused, e.g in the Monaco editor.
2016-06-26 13:44:16 +03:00
[![npm Package ](https://img.shields.io/npm/v/vscode-json-languageservice.svg?style=flat-square )](https://www.npmjs.org/package/vscode-json-languageservice)
[![NPM Downloads ](https://img.shields.io/npm/dm/vscode-json-languageservice.svg )](https://npmjs.org/package/vscode-json-languageservice)
2016-12-03 13:12:35 +03:00
[![Build Status ](https://travis-ci.org/Microsoft/vscode-json-languageservice.svg?branch=master )](https://travis-ci.org/Microsoft/vscode-json-languageservice)
2018-10-24 13:57:54 +03:00
[![License: MIT ](https://img.shields.io/badge/License-MIT-yellow.svg )](https://opensource.org/licenses/MIT)
2016-06-26 13:44:16 +03:00
2020-10-24 21:02:57 +03:00
## Why?
2016-06-26 13:44:16 +03:00
The _vscode-json-languageservice_ contains the language smarts behind the JSON editing experience of Visual Studio Code
and the Monaco editor.
2020-10-24 21:02:57 +03:00
- _doValidation_ analyses an input string and returns syntax and lint errors.
2020-10-24 21:03:25 +03:00
- _doComplete_ provides completion proposals for a given location.
2020-10-24 21:02:57 +03:00
- _doResolve_ resolves a completion proposals.
- _doHover_ provides a hover text for a given location.
2020-10-24 21:04:11 +03:00
- _findDocumentSymbols_ provides all symbols in the given document.
2020-10-24 21:04:59 +03:00
- _findDocumentColors_ provides all color symbols in the given document.
- _getColorPresentations_ returns available color formats for a color symbol.
2020-10-24 21:02:57 +03:00
- _format_ formats the code at the given range.
2020-10-24 21:04:11 +03:00
- _getFoldingRanges_ gets folding ranges for the given document.
2020-10-24 21:02:57 +03:00
- _getSelectionRanges_ gets selection ranges for a given location.
2020-10-24 21:04:11 +03:00
- _getMatchingSchemas_ matches a document against its schema and returns all AST nodes along with the matching sub schemas.
2020-10-24 21:04:59 +03:00
- _parseJSONDocument_ creates a JSON document from source code.
- _newJSONDocument_ creates a JSON document from an AST.
2020-09-25 11:09:25 +03:00
2020-10-24 21:02:57 +03:00
For the complete API see [jsonLanguageService.ts ](./src/jsonLanguageService.ts ) and [jsonLanguageTypes.ts ](./src/jsonLanguageTypes.ts )
2020-09-25 11:09:25 +03:00
2020-10-24 21:02:57 +03:00
## Installation
2016-06-26 13:44:16 +03:00
npm install --save vscode-json-languageservice
2020-09-25 11:09:25 +03:00
2020-10-24 21:02:57 +03:00
## Development
2020-09-25 11:09:25 +03:00
2020-10-24 21:07:07 +03:00
git clone https://github.com/microsoft/vscode-json-languageservice
cd vscode-json-languageservice
yarn
2020-09-25 11:09:25 +03:00
2020-10-24 21:07:07 +03:00
Use `yarn test` to compile and run tests
### How can I run and debug the service?
2020-09-25 11:09:25 +03:00
- 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:
2020-10-24 21:02:57 +03:00
![image ](https://user-images.githubusercontent.com/6461412/94239202-bdad4e80-ff11-11ea-99c3-cb9dbeb1c0b2.png )
2020-09-25 11:09:25 +03:00
2020-10-24 21:07:07 +03:00
### How can I run and debug the service inside an instance of VSCode?
2020-09-25 11:09:25 +03:00
- 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
2020-10-24 21:02:57 +03:00
![image ](https://user-images.githubusercontent.com/6461412/94242925-061b3b00-ff17-11ea-8c17-8da15268f1a1.png )
2020-09-25 11:09:25 +03:00
- set breakpoints, e.g. in `jsonCompletion.ts`
- in the instance run from sources, invoke code completion in the `.json` file