vscode-json-languageservice 5.2.0 → 5.3.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 +5 -0
- package/lib/esm/jsonLanguageService.d.ts +3 -2
- package/lib/esm/jsonLanguageService.js +4 -14
- package/lib/esm/jsonLanguageTypes.d.ts +5 -2
- package/lib/esm/services/jsonCompletion.js +4 -4
- package/lib/esm/services/jsonDocumentSymbols.js +6 -2
- package/lib/esm/services/jsonHover.js +1 -1
- package/lib/esm/utils/format.js +20 -0
- package/lib/esm/utils/objects.js +3 -3
- package/lib/esm/utils/propertyTree.js +71 -0
- package/lib/esm/utils/sort.js +355 -0
- package/lib/esm/utils/strings.js +1 -1
- package/lib/umd/jsonLanguageService.d.ts +3 -2
- package/lib/umd/jsonLanguageService.js +5 -15
- package/lib/umd/jsonLanguageTypes.d.ts +5 -2
- package/lib/umd/services/jsonCompletion.js +4 -4
- package/lib/umd/services/jsonDocumentSymbols.js +7 -3
- package/lib/umd/services/jsonHover.js +1 -1
- package/lib/umd/utils/format.js +34 -0
- package/lib/umd/utils/objects.js +3 -3
- package/lib/umd/utils/propertyTree.js +85 -0
- package/lib/umd/utils/sort.js +369 -0
- package/lib/umd/utils/strings.js +1 -1
- package/package.json +7 -7
|
@@ -1,4 +1,4 @@
|
|
|
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, JSONLanguageStatus } from './jsonLanguageTypes';
|
|
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, JSONLanguageStatus, SortOptions } from './jsonLanguageTypes';
|
|
2
2
|
import { DocumentLink } from 'vscode-languageserver-types';
|
|
3
3
|
export type JSONDocument = {
|
|
4
4
|
root: ASTNode | undefined;
|
|
@@ -20,10 +20,11 @@ export interface LanguageService {
|
|
|
20
20
|
findDocumentColors(document: TextDocument, doc: JSONDocument, context?: DocumentColorsContext): Thenable<ColorInformation[]>;
|
|
21
21
|
getColorPresentations(document: TextDocument, doc: JSONDocument, color: Color, range: Range): ColorPresentation[];
|
|
22
22
|
doHover(document: TextDocument, position: Position, doc: JSONDocument): Thenable<Hover | null>;
|
|
23
|
-
format(document: TextDocument, range: Range, options: FormattingOptions): TextEdit[];
|
|
24
23
|
getFoldingRanges(document: TextDocument, context?: FoldingRangesContext): FoldingRange[];
|
|
25
24
|
getSelectionRanges(document: TextDocument, positions: Position[], doc: JSONDocument): SelectionRange[];
|
|
26
25
|
findDefinition(document: TextDocument, position: Position, doc: JSONDocument): Thenable<DefinitionLink[]>;
|
|
27
26
|
findLinks(document: TextDocument, doc: JSONDocument): Thenable<DocumentLink[]>;
|
|
27
|
+
format(document: TextDocument, range: Range, options: FormattingOptions): TextEdit[];
|
|
28
|
+
sort(document: TextDocument, options: SortOptions): TextEdit[];
|
|
28
29
|
}
|
|
29
30
|
export declare function getLanguageService(params: LanguageServiceParams): LanguageService;
|
|
@@ -22,7 +22,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
22
22
|
if (v !== undefined) module.exports = v;
|
|
23
23
|
}
|
|
24
24
|
else if (typeof define === "function" && define.amd) {
|
|
25
|
-
define(["require", "exports", "./services/jsonCompletion", "./services/jsonHover", "./services/jsonValidation", "./services/jsonDocumentSymbols", "./parser/jsonParser", "./services/configuration", "./services/jsonSchemaService", "./services/jsonFolding", "./services/jsonSelectionRanges", "
|
|
25
|
+
define(["require", "exports", "./services/jsonCompletion", "./services/jsonHover", "./services/jsonValidation", "./services/jsonDocumentSymbols", "./parser/jsonParser", "./services/configuration", "./services/jsonSchemaService", "./services/jsonFolding", "./services/jsonSelectionRanges", "./utils/sort", "./utils/format", "./services/jsonLinks", "./jsonLanguageTypes"], factory);
|
|
26
26
|
}
|
|
27
27
|
})(function (require, exports) {
|
|
28
28
|
"use strict";
|
|
@@ -37,8 +37,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
37
37
|
const jsonSchemaService_1 = require("./services/jsonSchemaService");
|
|
38
38
|
const jsonFolding_1 = require("./services/jsonFolding");
|
|
39
39
|
const jsonSelectionRanges_1 = require("./services/jsonSelectionRanges");
|
|
40
|
-
const
|
|
41
|
-
const
|
|
40
|
+
const sort_1 = require("./utils/sort");
|
|
41
|
+
const format_1 = require("./utils/format");
|
|
42
42
|
const jsonLinks_1 = require("./services/jsonLinks");
|
|
43
43
|
__exportStar(require("./jsonLanguageTypes"), exports);
|
|
44
44
|
function getLanguageService(params) {
|
|
@@ -72,18 +72,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
72
72
|
getSelectionRanges: jsonSelectionRanges_1.getSelectionRanges,
|
|
73
73
|
findDefinition: () => Promise.resolve([]),
|
|
74
74
|
findLinks: jsonLinks_1.findLinks,
|
|
75
|
-
format: (
|
|
76
|
-
|
|
77
|
-
if (r) {
|
|
78
|
-
const offset = d.offsetAt(r.start);
|
|
79
|
-
const length = d.offsetAt(r.end) - offset;
|
|
80
|
-
range = { offset, length };
|
|
81
|
-
}
|
|
82
|
-
const options = { tabSize: o ? o.tabSize : 4, insertSpaces: o?.insertSpaces === true, insertFinalNewline: o?.insertFinalNewline === true, eol: '\n', keepLines: o?.keepLines === true };
|
|
83
|
-
return (0, jsonc_parser_1.format)(d.getText(), range, options).map(e => {
|
|
84
|
-
return jsonLanguageTypes_1.TextEdit.replace(jsonLanguageTypes_1.Range.create(d.positionAt(e.offset), d.positionAt(e.offset + e.length)), e.content);
|
|
85
|
-
});
|
|
86
|
-
}
|
|
75
|
+
format: (document, range, options) => (0, format_1.format)(document, options, range),
|
|
76
|
+
sort: (document, options) => (0, sort_1.sort)(document, options)
|
|
87
77
|
};
|
|
88
78
|
}
|
|
89
79
|
exports.getLanguageService = getLanguageService;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { JSONWorkerContribution, JSONPath, Segment, CompletionsCollector } from './jsonContributions';
|
|
2
2
|
import { JSONSchema } from './jsonSchema';
|
|
3
3
|
import { Range, Position, DocumentUri, MarkupContent, MarkupKind, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind, SelectionRange, Diagnostic, DiagnosticSeverity, CompletionItem, CompletionItemKind, CompletionList, CompletionItemTag, InsertTextFormat, SymbolInformation, SymbolKind, DocumentSymbol, Location, Hover, MarkedString, FormattingOptions as LSPFormattingOptions, DefinitionLink, CodeActionContext, Command, CodeAction, DocumentHighlight, DocumentLink, WorkspaceEdit, TextEdit, CodeActionKind, TextDocumentEdit, VersionedTextDocumentIdentifier, DocumentHighlightKind } from 'vscode-languageserver-types';
|
|
4
|
-
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
5
|
-
export { TextDocument, Range, Position, DocumentUri, MarkupContent, MarkupKind, JSONSchema, JSONWorkerContribution, JSONPath, Segment, CompletionsCollector, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind, SelectionRange, Diagnostic, DiagnosticSeverity, CompletionItem, CompletionItemKind, CompletionList, CompletionItemTag, InsertTextFormat, DefinitionLink, SymbolInformation, SymbolKind, DocumentSymbol, Location, Hover, MarkedString, CodeActionContext, Command, CodeAction, DocumentHighlight, DocumentLink, WorkspaceEdit, TextEdit, CodeActionKind, TextDocumentEdit, VersionedTextDocumentIdentifier, DocumentHighlightKind };
|
|
4
|
+
import { TextDocument, TextDocumentContentChangeEvent } from 'vscode-languageserver-textdocument';
|
|
5
|
+
export { TextDocument, TextDocumentContentChangeEvent, Range, Position, DocumentUri, MarkupContent, MarkupKind, JSONSchema, JSONWorkerContribution, JSONPath, Segment, CompletionsCollector, Color, ColorInformation, ColorPresentation, FoldingRange, FoldingRangeKind, SelectionRange, Diagnostic, DiagnosticSeverity, CompletionItem, CompletionItemKind, CompletionList, CompletionItemTag, InsertTextFormat, DefinitionLink, SymbolInformation, SymbolKind, DocumentSymbol, Location, Hover, MarkedString, CodeActionContext, Command, CodeAction, DocumentHighlight, DocumentLink, WorkspaceEdit, TextEdit, CodeActionKind, TextDocumentEdit, VersionedTextDocumentIdentifier, DocumentHighlightKind };
|
|
6
6
|
/**
|
|
7
7
|
* Error codes used by diagnostics
|
|
8
8
|
*/
|
|
@@ -295,3 +295,6 @@ export interface FormattingOptions extends LSPFormattingOptions {
|
|
|
295
295
|
insertFinalNewline?: boolean;
|
|
296
296
|
keepLines?: boolean;
|
|
297
297
|
}
|
|
298
|
+
export interface SortOptions extends LSPFormattingOptions {
|
|
299
|
+
insertFinalNewline?: boolean;
|
|
300
|
+
}
|
|
@@ -699,7 +699,7 @@
|
|
|
699
699
|
return text.replace(/[\\\$\}]/g, '\\$&'); // escape $, \ and }
|
|
700
700
|
}
|
|
701
701
|
getInsertTextForValue(value, separatorAfter) {
|
|
702
|
-
|
|
702
|
+
const text = JSON.stringify(value, null, '\t');
|
|
703
703
|
if (text === '{}') {
|
|
704
704
|
return '{$1}' + separatorAfter;
|
|
705
705
|
}
|
|
@@ -817,7 +817,7 @@
|
|
|
817
817
|
nValueProposals += propertySchema.examples.length;
|
|
818
818
|
}
|
|
819
819
|
if (nValueProposals === 0) {
|
|
820
|
-
|
|
820
|
+
let type = Array.isArray(propertySchema.type) ? propertySchema.type[0] : propertySchema.type;
|
|
821
821
|
if (!type) {
|
|
822
822
|
if (propertySchema.properties) {
|
|
823
823
|
type = 'object';
|
|
@@ -857,8 +857,8 @@
|
|
|
857
857
|
return resultText + value + separatorAfter;
|
|
858
858
|
}
|
|
859
859
|
getCurrentWord(document, offset) {
|
|
860
|
-
|
|
861
|
-
|
|
860
|
+
let i = offset - 1;
|
|
861
|
+
const text = document.getText();
|
|
862
862
|
while (i >= 0 && ' \t\n\r\v":{[,]}'.indexOf(text.charAt(i)) === -1) {
|
|
863
863
|
i--;
|
|
864
864
|
}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
if (v !== undefined) module.exports = v;
|
|
9
9
|
}
|
|
10
10
|
else if (typeof define === "function" && define.amd) {
|
|
11
|
-
define(["require", "exports", "../parser/jsonParser", "../utils/strings", "../utils/colors", "../jsonLanguageTypes"], factory);
|
|
11
|
+
define(["require", "exports", "../parser/jsonParser", "../utils/strings", "../utils/colors", "@vscode/l10n", "../jsonLanguageTypes"], factory);
|
|
12
12
|
}
|
|
13
13
|
})(function (require, exports) {
|
|
14
14
|
"use strict";
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
const Parser = require("../parser/jsonParser");
|
|
18
18
|
const Strings = require("../utils/strings");
|
|
19
19
|
const colors_1 = require("../utils/colors");
|
|
20
|
+
const l10n = require("@vscode/l10n");
|
|
20
21
|
const jsonLanguageTypes_1 = require("../jsonLanguageTypes");
|
|
21
22
|
class JSONDocumentSymbols {
|
|
22
23
|
constructor(schemaService) {
|
|
@@ -38,7 +39,7 @@
|
|
|
38
39
|
for (const property of item.properties) {
|
|
39
40
|
if (property.keyNode.value === 'key' && property.valueNode) {
|
|
40
41
|
const location = jsonLanguageTypes_1.Location.create(document.uri, getRange(document, item));
|
|
41
|
-
result.push({ name:
|
|
42
|
+
result.push({ name: getName(property.valueNode), kind: jsonLanguageTypes_1.SymbolKind.Function, location: location });
|
|
42
43
|
limit--;
|
|
43
44
|
if (limit <= 0) {
|
|
44
45
|
if (context && context.onResultLimitExceeded) {
|
|
@@ -112,7 +113,7 @@
|
|
|
112
113
|
if (property.keyNode.value === 'key' && property.valueNode) {
|
|
113
114
|
const range = getRange(document, item);
|
|
114
115
|
const selectionRange = getRange(document, property.keyNode);
|
|
115
|
-
result.push({ name:
|
|
116
|
+
result.push({ name: getName(property.valueNode), kind: jsonLanguageTypes_1.SymbolKind.Function, range, selectionRange });
|
|
116
117
|
limit--;
|
|
117
118
|
if (limit <= 0) {
|
|
118
119
|
if (context && context.onResultLimitExceeded) {
|
|
@@ -278,4 +279,7 @@
|
|
|
278
279
|
function getRange(document, node) {
|
|
279
280
|
return jsonLanguageTypes_1.Range.create(document.positionAt(node.offset), document.positionAt(node.offset + node.length));
|
|
280
281
|
}
|
|
282
|
+
function getName(node) {
|
|
283
|
+
return Parser.getNodeValue(node) || l10n.t('<empty>');
|
|
284
|
+
}
|
|
281
285
|
});
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
const hoverRange = jsonLanguageTypes_1.Range.create(document.positionAt(hoverRangeNode.offset), document.positionAt(hoverRangeNode.offset + hoverRangeNode.length));
|
|
43
|
-
|
|
43
|
+
const createHover = (contents) => {
|
|
44
44
|
const result = {
|
|
45
45
|
contents: contents,
|
|
46
46
|
range: hoverRange
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "jsonc-parser", "../jsonLanguageTypes"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.format = void 0;
|
|
13
|
+
const jsonc_parser_1 = require("jsonc-parser");
|
|
14
|
+
const jsonLanguageTypes_1 = require("../jsonLanguageTypes");
|
|
15
|
+
function format(documentToFormat, formattingOptions, formattingRange) {
|
|
16
|
+
let range = undefined;
|
|
17
|
+
if (formattingRange) {
|
|
18
|
+
const offset = documentToFormat.offsetAt(formattingRange.start);
|
|
19
|
+
const length = documentToFormat.offsetAt(formattingRange.end) - offset;
|
|
20
|
+
range = { offset, length };
|
|
21
|
+
}
|
|
22
|
+
const options = {
|
|
23
|
+
tabSize: formattingOptions ? formattingOptions.tabSize : 4,
|
|
24
|
+
insertSpaces: formattingOptions?.insertSpaces === true,
|
|
25
|
+
insertFinalNewline: formattingOptions?.insertFinalNewline === true,
|
|
26
|
+
eol: '\n',
|
|
27
|
+
keepLines: formattingOptions?.keepLines === true
|
|
28
|
+
};
|
|
29
|
+
return (0, jsonc_parser_1.format)(documentToFormat.getText(), range, options).map(edit => {
|
|
30
|
+
return jsonLanguageTypes_1.TextEdit.replace(jsonLanguageTypes_1.Range.create(documentToFormat.positionAt(edit.offset), documentToFormat.positionAt(edit.offset + edit.length)), edit.content);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
exports.format = format;
|
|
34
|
+
});
|
package/lib/umd/utils/objects.js
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
if ((Array.isArray(one)) !== (Array.isArray(other))) {
|
|
31
31
|
return false;
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
let i, key;
|
|
34
34
|
if (Array.isArray(one)) {
|
|
35
35
|
if (one.length !== other.length) {
|
|
36
36
|
return false;
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
else {
|
|
45
|
-
|
|
45
|
+
const oneKeys = [];
|
|
46
46
|
for (key in one) {
|
|
47
47
|
oneKeys.push(key);
|
|
48
48
|
}
|
|
49
49
|
oneKeys.sort();
|
|
50
|
-
|
|
50
|
+
const otherKeys = [];
|
|
51
51
|
for (key in other) {
|
|
52
52
|
otherKeys.push(key);
|
|
53
53
|
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
(function (factory) {
|
|
6
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
7
|
+
var v = factory(require, exports);
|
|
8
|
+
if (v !== undefined) module.exports = v;
|
|
9
|
+
}
|
|
10
|
+
else if (typeof define === "function" && define.amd) {
|
|
11
|
+
define(["require", "exports"], factory);
|
|
12
|
+
}
|
|
13
|
+
})(function (require, exports) {
|
|
14
|
+
"use strict";
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.PropertyTree = exports.Container = void 0;
|
|
17
|
+
var Container;
|
|
18
|
+
(function (Container) {
|
|
19
|
+
Container[Container["Object"] = 0] = "Object";
|
|
20
|
+
Container[Container["Array"] = 1] = "Array";
|
|
21
|
+
})(Container = exports.Container || (exports.Container = {}));
|
|
22
|
+
class PropertyTree {
|
|
23
|
+
constructor(propertyName, beginningLineNumber) {
|
|
24
|
+
this.propertyName = propertyName ?? '';
|
|
25
|
+
this.beginningLineNumber = beginningLineNumber;
|
|
26
|
+
this.childrenProperties = [];
|
|
27
|
+
this.lastProperty = false;
|
|
28
|
+
this.noKeyName = false;
|
|
29
|
+
}
|
|
30
|
+
addChildProperty(childProperty) {
|
|
31
|
+
childProperty.parent = this;
|
|
32
|
+
if (this.childrenProperties.length > 0) {
|
|
33
|
+
let insertionIndex = 0;
|
|
34
|
+
if (childProperty.noKeyName) {
|
|
35
|
+
insertionIndex = this.childrenProperties.length;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
insertionIndex = binarySearchOnPropertyArray(this.childrenProperties, childProperty, compareProperties);
|
|
39
|
+
}
|
|
40
|
+
if (insertionIndex < 0) {
|
|
41
|
+
insertionIndex = (insertionIndex * -1) - 1;
|
|
42
|
+
}
|
|
43
|
+
this.childrenProperties.splice(insertionIndex, 0, childProperty);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
this.childrenProperties.push(childProperty);
|
|
47
|
+
}
|
|
48
|
+
return childProperty;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.PropertyTree = PropertyTree;
|
|
52
|
+
function compareProperties(propertyTree1, propertyTree2) {
|
|
53
|
+
if (propertyTree1.propertyName < propertyTree2.propertyName) {
|
|
54
|
+
return -1;
|
|
55
|
+
}
|
|
56
|
+
else if (propertyTree1.propertyName > propertyTree2.propertyName) {
|
|
57
|
+
return 1;
|
|
58
|
+
}
|
|
59
|
+
return 0;
|
|
60
|
+
}
|
|
61
|
+
function binarySearchOnPropertyArray(propertyTreeArray, propertyTree, compare_fn) {
|
|
62
|
+
if (propertyTree.propertyName < propertyTreeArray[0].propertyName) {
|
|
63
|
+
return 0;
|
|
64
|
+
}
|
|
65
|
+
if (propertyTree.propertyName > propertyTreeArray[propertyTreeArray.length - 1].propertyName) {
|
|
66
|
+
return propertyTreeArray.length;
|
|
67
|
+
}
|
|
68
|
+
let m = 0;
|
|
69
|
+
let n = propertyTreeArray.length - 1;
|
|
70
|
+
while (m <= n) {
|
|
71
|
+
let k = (n + m) >> 1;
|
|
72
|
+
let cmp = compare_fn(propertyTree, propertyTreeArray[k]);
|
|
73
|
+
if (cmp > 0) {
|
|
74
|
+
m = k + 1;
|
|
75
|
+
}
|
|
76
|
+
else if (cmp < 0) {
|
|
77
|
+
n = k - 1;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
return k;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return -m - 1;
|
|
84
|
+
}
|
|
85
|
+
});
|