vscode-json-languageservice 3.9.1 → 3.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/README.md +27 -26
- package/lib/esm/jsonLanguageService.d.ts +2 -0
- package/lib/esm/jsonLanguageService.js +3 -2
- package/lib/esm/services/{jsonDefinition.js → jsonLinks.js} +19 -29
- package/lib/umd/jsonLanguageService.d.ts +2 -0
- package/lib/umd/jsonLanguageService.js +4 -3
- package/lib/umd/services/{jsonDefinition.js → jsonLinks.js} +21 -31
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
3.10.0 / 2020-11-03
|
|
2
|
+
=================
|
|
3
|
+
* new API `findLinks` return links for local `$ref` links. Replaces `findDefinition` which no longer returns results ( kept for API compatibility)
|
|
4
|
+
|
|
1
5
|
3.9.0 / 2020-09-28
|
|
2
6
|
=================
|
|
3
7
|
* new API `DocumentLanguageSettings.schemaValidation`. The severity of problems from schema validation. If set to 'ignore', schema validation will be skipped. If not set, 'warning' is used.
|
package/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# vscode-json-languageservice
|
|
2
|
+
|
|
2
3
|
JSON language service extracted from VSCode to be reused, e.g in the Monaco editor.
|
|
3
4
|
|
|
4
5
|
[](https://www.npmjs.org/package/vscode-json-languageservice)
|
|
@@ -6,52 +7,52 @@ JSON language service extracted from VSCode to be reused, e.g in the Monaco edit
|
|
|
6
7
|
[](https://travis-ci.org/Microsoft/vscode-json-languageservice)
|
|
7
8
|
[](https://opensource.org/licenses/MIT)
|
|
8
9
|
|
|
9
|
-
Why?
|
|
10
|
-
|
|
10
|
+
## Why?
|
|
11
|
+
|
|
11
12
|
The _vscode-json-languageservice_ contains the language smarts behind the JSON editing experience of Visual Studio Code
|
|
12
13
|
and the Monaco editor.
|
|
13
|
-
- *doValidation* analyses an input string and returns syntax and lint errors.
|
|
14
|
-
- *doComplete* provides completion proposals for a given location. *doResolve* resolves a completion proposal
|
|
15
|
-
- *doResolve* resolves a completion proposals.
|
|
16
|
-
- *doHover* provides a hover text for a given location.
|
|
17
|
-
- *findDocumentSymbols* provides all symbols in the given document
|
|
18
|
-
- *findDocumentColors* provides all color symbols in the given document, *getColorPresentations* returns available color formats for a color symbol.
|
|
19
|
-
- *format* formats the code at the given range.
|
|
20
|
-
- *getFoldingRanges* gets folding ranges for the given document
|
|
21
|
-
- *getSelectionRanges* gets selection ranges for a given location.
|
|
22
|
-
- *getMatchingSchemas* matches a document against its schema and returns all AST nodes along with the matching sub schemas
|
|
23
14
|
|
|
24
|
-
|
|
15
|
+
- _doValidation_ analyses an input string and returns syntax and lint errors.
|
|
16
|
+
- _doComplete_ provides completion proposals for a given location.
|
|
17
|
+
- _doResolve_ resolves a completion proposals.
|
|
18
|
+
- _doHover_ provides a hover text for a given location.
|
|
19
|
+
- _findDocumentSymbols_ provides all symbols in the given document.
|
|
20
|
+
- _findDocumentColors_ provides all color symbols in the given document.
|
|
21
|
+
- _getColorPresentations_ returns available color formats for a color symbol.
|
|
22
|
+
- _format_ formats the code at the given range.
|
|
23
|
+
- _getFoldingRanges_ gets folding ranges for the given document.
|
|
24
|
+
- _getSelectionRanges_ gets selection ranges for a given location.
|
|
25
|
+
- _getMatchingSchemas_ matches a document against its schema and returns all AST nodes along with the matching sub schemas.
|
|
26
|
+
- _parseJSONDocument_ creates a JSON document from source code.
|
|
27
|
+
- _newJSONDocument_ creates a JSON document from an AST.
|
|
25
28
|
|
|
26
|
-
For the complete API see [jsonLanguageService.ts](./src/jsonLanguageService.ts) and [jsonLanguageTypes.ts](./src/jsonLanguageTypes.ts)
|
|
29
|
+
For the complete API see [jsonLanguageService.ts](./src/jsonLanguageService.ts) and [jsonLanguageTypes.ts](./src/jsonLanguageTypes.ts)
|
|
27
30
|
|
|
28
|
-
|
|
29
|
-
Installation
|
|
30
|
-
------------
|
|
31
|
+
## Installation
|
|
31
32
|
|
|
32
33
|
npm install --save vscode-json-languageservice
|
|
33
34
|
|
|
34
|
-
Development
|
|
35
|
-
-----------
|
|
35
|
+
## Development
|
|
36
36
|
|
|
37
|
+
git clone https://github.com/microsoft/vscode-json-languageservice
|
|
38
|
+
cd vscode-json-languageservice
|
|
39
|
+
yarn
|
|
37
40
|
|
|
38
|
-
|
|
39
|
-
- `yarn test` to compile and run tests
|
|
41
|
+
Use `yarn test` to compile and run tests
|
|
40
42
|
|
|
41
|
-
How can I run and debug the service?
|
|
43
|
+
### How can I run and debug the service?
|
|
42
44
|
|
|
43
45
|
- open the folder in VSCode.
|
|
44
46
|
- set breakpoints, e.g. in `jsonCompletion.ts`
|
|
45
47
|
- run the Unit tests from the run viewlet and wait until a breakpoint is hit:
|
|
46
|
-

|
|
47
|
-
|
|
48
|
+

|
|
48
49
|
|
|
49
|
-
How can I run and debug the service inside an instance of VSCode?
|
|
50
|
+
### How can I run and debug the service inside an instance of VSCode?
|
|
50
51
|
|
|
51
52
|
- run VSCode out of sources setup as described here: https://github.com/Microsoft/vscode/wiki/How-to-Contribute
|
|
52
53
|
- use `yarn link vscode-json-languageservice` in `vscode/extensions/json-language-features/server` to run VSCode with the latest changes from `vscode-json-languageservice`
|
|
53
54
|
- run VSCode out of source (`vscode/scripts/code.sh|bat`) and open a `.json` file
|
|
54
55
|
- 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
|
|
55
|
-

|
|
56
|
+

|
|
56
57
|
- set breakpoints, e.g. in `jsonCompletion.ts`
|
|
57
58
|
- in the instance run from sources, invoke code completion in the `.json` file
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Thenable, ASTNode, Color, ColorInformation, ColorPresentation, LanguageServiceParams, LanguageSettings, DocumentLanguageSettings, FoldingRange, JSONSchema, SelectionRange, FoldingRangesContext, DocumentSymbolsContext, ColorInformationContext as DocumentColorsContext, TextDocument, Position, CompletionItem, CompletionList, Hover, Range, SymbolInformation, Diagnostic, TextEdit, FormattingOptions, DocumentSymbol, DefinitionLink, MatchingSchema } from './jsonLanguageTypes';
|
|
2
|
+
import { DocumentLink } from 'vscode-languageserver-types';
|
|
2
3
|
export declare type JSONDocument = {
|
|
3
4
|
root: ASTNode | undefined;
|
|
4
5
|
getNodeFromOffset(offset: number, includeRightBound?: boolean): ASTNode | undefined;
|
|
@@ -24,5 +25,6 @@ export interface LanguageService {
|
|
|
24
25
|
getFoldingRanges(document: TextDocument, context?: FoldingRangesContext): FoldingRange[];
|
|
25
26
|
getSelectionRanges(document: TextDocument, positions: Position[], doc: JSONDocument): SelectionRange[];
|
|
26
27
|
findDefinition(document: TextDocument, position: Position, doc: JSONDocument): Thenable<DefinitionLink[]>;
|
|
28
|
+
findLinks(document: TextDocument, doc: JSONDocument): Thenable<DocumentLink[]>;
|
|
27
29
|
}
|
|
28
30
|
export declare function getLanguageService(params: LanguageServiceParams): LanguageService;
|
|
@@ -13,7 +13,7 @@ import { getFoldingRanges } from './services/jsonFolding';
|
|
|
13
13
|
import { getSelectionRanges } from './services/jsonSelectionRanges';
|
|
14
14
|
import { format as formatJSON } from 'jsonc-parser';
|
|
15
15
|
import { Range, TextEdit } from './jsonLanguageTypes';
|
|
16
|
-
import {
|
|
16
|
+
import { findLinks } from './services/jsonLinks';
|
|
17
17
|
export * from './jsonLanguageTypes';
|
|
18
18
|
export function getLanguageService(params) {
|
|
19
19
|
var promise = params.promiseConstructor || Promise;
|
|
@@ -48,7 +48,8 @@ export function getLanguageService(params) {
|
|
|
48
48
|
doHover: jsonHover.doHover.bind(jsonHover),
|
|
49
49
|
getFoldingRanges: getFoldingRanges,
|
|
50
50
|
getSelectionRanges: getSelectionRanges,
|
|
51
|
-
findDefinition:
|
|
51
|
+
findDefinition: function () { return Promise.resolve([]); },
|
|
52
|
+
findLinks: findLinks,
|
|
52
53
|
format: function (d, r, o) {
|
|
53
54
|
var range = undefined;
|
|
54
55
|
if (r) {
|
|
@@ -3,37 +3,27 @@
|
|
|
3
3
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
import { Range } from '../jsonLanguageTypes';
|
|
6
|
-
export function
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
return Promise.resolve([definition]);
|
|
6
|
+
export function findLinks(document, doc) {
|
|
7
|
+
var links = [];
|
|
8
|
+
doc.visit(function (node) {
|
|
9
|
+
var _a;
|
|
10
|
+
if (node.type === "property" && node.keyNode.value === "$ref" && ((_a = node.valueNode) === null || _a === void 0 ? void 0 : _a.type) === 'string') {
|
|
11
|
+
var path = node.valueNode.value;
|
|
12
|
+
var targetNode = findTargetNode(doc, path);
|
|
13
|
+
if (targetNode) {
|
|
14
|
+
var targetPos = document.positionAt(targetNode.offset);
|
|
15
|
+
links.push({
|
|
16
|
+
target: document.uri + "#" + (targetPos.line + 1) + "," + (targetPos.character + 1),
|
|
17
|
+
range: createRange(document, node.valueNode)
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
});
|
|
23
|
+
return Promise.resolve(links);
|
|
26
24
|
}
|
|
27
25
|
function createRange(document, node) {
|
|
28
|
-
return Range.create(document.positionAt(node.offset), document.positionAt(node.offset + node.length));
|
|
29
|
-
}
|
|
30
|
-
function isRef(node) {
|
|
31
|
-
return node.type === 'string' &&
|
|
32
|
-
node.parent &&
|
|
33
|
-
node.parent.type === 'property' &&
|
|
34
|
-
node.parent.valueNode === node &&
|
|
35
|
-
node.parent.keyNode.value === "$ref" ||
|
|
36
|
-
false;
|
|
26
|
+
return Range.create(document.positionAt(node.offset + 1), document.positionAt(node.offset + node.length - 1));
|
|
37
27
|
}
|
|
38
28
|
function findTargetNode(doc, path) {
|
|
39
29
|
var tokens = parseJSONPointer(path);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Thenable, ASTNode, Color, ColorInformation, ColorPresentation, LanguageServiceParams, LanguageSettings, DocumentLanguageSettings, FoldingRange, JSONSchema, SelectionRange, FoldingRangesContext, DocumentSymbolsContext, ColorInformationContext as DocumentColorsContext, TextDocument, Position, CompletionItem, CompletionList, Hover, Range, SymbolInformation, Diagnostic, TextEdit, FormattingOptions, DocumentSymbol, DefinitionLink, MatchingSchema } from './jsonLanguageTypes';
|
|
2
|
+
import { DocumentLink } from 'vscode-languageserver-types';
|
|
2
3
|
export declare type JSONDocument = {
|
|
3
4
|
root: ASTNode | undefined;
|
|
4
5
|
getNodeFromOffset(offset: number, includeRightBound?: boolean): ASTNode | undefined;
|
|
@@ -24,5 +25,6 @@ export interface LanguageService {
|
|
|
24
25
|
getFoldingRanges(document: TextDocument, context?: FoldingRangesContext): FoldingRange[];
|
|
25
26
|
getSelectionRanges(document: TextDocument, positions: Position[], doc: JSONDocument): SelectionRange[];
|
|
26
27
|
findDefinition(document: TextDocument, position: Position, doc: JSONDocument): Thenable<DefinitionLink[]>;
|
|
28
|
+
findLinks(document: TextDocument, doc: JSONDocument): Thenable<DocumentLink[]>;
|
|
27
29
|
}
|
|
28
30
|
export declare function getLanguageService(params: LanguageServiceParams): LanguageService;
|
|
@@ -18,7 +18,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
18
18
|
if (v !== undefined) module.exports = v;
|
|
19
19
|
}
|
|
20
20
|
else if (typeof define === "function" && define.amd) {
|
|
21
|
-
define(["require", "exports", "./services/jsonCompletion", "./services/jsonHover", "./services/jsonValidation", "./services/jsonDocumentSymbols", "./parser/jsonParser", "./services/configuration", "./services/jsonSchemaService", "./services/jsonFolding", "./services/jsonSelectionRanges", "jsonc-parser", "./jsonLanguageTypes", "./services/
|
|
21
|
+
define(["require", "exports", "./services/jsonCompletion", "./services/jsonHover", "./services/jsonValidation", "./services/jsonDocumentSymbols", "./parser/jsonParser", "./services/configuration", "./services/jsonSchemaService", "./services/jsonFolding", "./services/jsonSelectionRanges", "jsonc-parser", "./jsonLanguageTypes", "./services/jsonLinks", "./jsonLanguageTypes"], factory);
|
|
22
22
|
}
|
|
23
23
|
})(function (require, exports) {
|
|
24
24
|
"use strict";
|
|
@@ -35,7 +35,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
35
35
|
var jsonSelectionRanges_1 = require("./services/jsonSelectionRanges");
|
|
36
36
|
var jsonc_parser_1 = require("jsonc-parser");
|
|
37
37
|
var jsonLanguageTypes_1 = require("./jsonLanguageTypes");
|
|
38
|
-
var
|
|
38
|
+
var jsonLinks_1 = require("./services/jsonLinks");
|
|
39
39
|
__exportStar(require("./jsonLanguageTypes"), exports);
|
|
40
40
|
function getLanguageService(params) {
|
|
41
41
|
var promise = params.promiseConstructor || Promise;
|
|
@@ -70,7 +70,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
70
70
|
doHover: jsonHover.doHover.bind(jsonHover),
|
|
71
71
|
getFoldingRanges: jsonFolding_1.getFoldingRanges,
|
|
72
72
|
getSelectionRanges: jsonSelectionRanges_1.getSelectionRanges,
|
|
73
|
-
findDefinition:
|
|
73
|
+
findDefinition: function () { return Promise.resolve([]); },
|
|
74
|
+
findLinks: jsonLinks_1.findLinks,
|
|
74
75
|
format: function (d, r, o) {
|
|
75
76
|
var range = undefined;
|
|
76
77
|
if (r) {
|
|
@@ -13,40 +13,30 @@
|
|
|
13
13
|
})(function (require, exports) {
|
|
14
14
|
"use strict";
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.
|
|
16
|
+
exports.findLinks = void 0;
|
|
17
17
|
var jsonLanguageTypes_1 = require("../jsonLanguageTypes");
|
|
18
|
-
function
|
|
19
|
-
var
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
};
|
|
37
|
-
return Promise.resolve([definition]);
|
|
18
|
+
function findLinks(document, doc) {
|
|
19
|
+
var links = [];
|
|
20
|
+
doc.visit(function (node) {
|
|
21
|
+
var _a;
|
|
22
|
+
if (node.type === "property" && node.keyNode.value === "$ref" && ((_a = node.valueNode) === null || _a === void 0 ? void 0 : _a.type) === 'string') {
|
|
23
|
+
var path = node.valueNode.value;
|
|
24
|
+
var targetNode = findTargetNode(doc, path);
|
|
25
|
+
if (targetNode) {
|
|
26
|
+
var targetPos = document.positionAt(targetNode.offset);
|
|
27
|
+
links.push({
|
|
28
|
+
target: document.uri + "#" + (targetPos.line + 1) + "," + (targetPos.character + 1),
|
|
29
|
+
range: createRange(document, node.valueNode)
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
});
|
|
35
|
+
return Promise.resolve(links);
|
|
38
36
|
}
|
|
39
|
-
exports.
|
|
37
|
+
exports.findLinks = findLinks;
|
|
40
38
|
function createRange(document, node) {
|
|
41
|
-
return jsonLanguageTypes_1.Range.create(document.positionAt(node.offset), document.positionAt(node.offset + node.length));
|
|
42
|
-
}
|
|
43
|
-
function isRef(node) {
|
|
44
|
-
return node.type === 'string' &&
|
|
45
|
-
node.parent &&
|
|
46
|
-
node.parent.type === 'property' &&
|
|
47
|
-
node.parent.valueNode === node &&
|
|
48
|
-
node.parent.keyNode.value === "$ref" ||
|
|
49
|
-
false;
|
|
39
|
+
return jsonLanguageTypes_1.Range.create(document.positionAt(node.offset + 1), document.positionAt(node.offset + node.length - 1));
|
|
50
40
|
}
|
|
51
41
|
function findTargetNode(doc, path) {
|
|
52
42
|
var tokens = parseJSONPointer(path);
|