volar-service-json 0.0.10 → 0.0.12
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/out/index.d.ts +2 -2
- package/out/index.js +124 -119
- package/package.json +3 -3
package/out/index.d.ts
CHANGED
|
@@ -5,5 +5,5 @@ export interface Provide {
|
|
|
5
5
|
'json/jsonDocument': (document: TextDocument) => json.JSONDocument | undefined;
|
|
6
6
|
'json/languageService': () => json.LanguageService;
|
|
7
7
|
}
|
|
8
|
-
declare
|
|
9
|
-
export default
|
|
8
|
+
export declare function create(settings?: json.LanguageSettings): Service<Provide>;
|
|
9
|
+
export default create;
|
package/out/index.js
CHANGED
|
@@ -23,129 +23,134 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.create = void 0;
|
|
26
27
|
const json = __importStar(require("vscode-json-languageservice"));
|
|
27
28
|
const vscode_uri_1 = require("vscode-uri");
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const baseUri = vscode_uri_1.URI.parse(base);
|
|
45
|
-
const baseUriDir = baseUri.path.endsWith('/') ? baseUri : vscode_uri_1.Utils.dirname(baseUri);
|
|
46
|
-
return vscode_uri_1.Utils.resolvePath(baseUriDir, ref).toString(true);
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
const jsonLs = json.getLanguageService({
|
|
50
|
-
schemaRequestService: async (uri) => await context.env.fs?.readFile(uri) ?? '',
|
|
51
|
-
workspaceContext,
|
|
52
|
-
clientCapabilities: context.env.clientCapabilities,
|
|
53
|
-
});
|
|
54
|
-
if (settings) {
|
|
55
|
-
jsonLs.configure(settings);
|
|
56
|
-
}
|
|
57
|
-
return {
|
|
58
|
-
provide: {
|
|
59
|
-
'json/jsonDocument': getJsonDocument,
|
|
60
|
-
'json/languageService': () => jsonLs,
|
|
61
|
-
},
|
|
62
|
-
triggerCharacters,
|
|
63
|
-
provideCompletionItems(document, position) {
|
|
64
|
-
return worker(document, async (jsonDocument) => {
|
|
65
|
-
return await jsonLs.doComplete(document, position, jsonDocument);
|
|
66
|
-
});
|
|
67
|
-
},
|
|
68
|
-
resolveCompletionItem(item) {
|
|
69
|
-
return jsonLs.doResolve(item);
|
|
70
|
-
},
|
|
71
|
-
provideDefinition(document, position) {
|
|
72
|
-
return worker(document, async (jsonDocument) => {
|
|
73
|
-
return await jsonLs.findDefinition(document, position, jsonDocument);
|
|
74
|
-
});
|
|
75
|
-
},
|
|
76
|
-
provideDiagnostics(document) {
|
|
77
|
-
return worker(document, async (jsonDocument) => {
|
|
78
|
-
const documentLanguageSettings = undefined; // await getSettings(); // TODO
|
|
79
|
-
return await jsonLs.doValidation(document, jsonDocument, documentLanguageSettings, undefined);
|
|
80
|
-
});
|
|
81
|
-
},
|
|
82
|
-
provideHover(document, position) {
|
|
83
|
-
return worker(document, async (jsonDocument) => {
|
|
84
|
-
return await jsonLs.doHover(document, position, jsonDocument);
|
|
85
|
-
});
|
|
86
|
-
},
|
|
87
|
-
provideDocumentLinks(document) {
|
|
88
|
-
return worker(document, async (jsonDocument) => {
|
|
89
|
-
return await jsonLs.findLinks(document, jsonDocument);
|
|
90
|
-
});
|
|
91
|
-
},
|
|
92
|
-
provideDocumentSymbols(document) {
|
|
93
|
-
return worker(document, async (jsonDocument) => {
|
|
94
|
-
return await jsonLs.findDocumentSymbols2(document, jsonDocument);
|
|
95
|
-
});
|
|
96
|
-
},
|
|
97
|
-
provideDocumentColors(document) {
|
|
98
|
-
return worker(document, async (jsonDocument) => {
|
|
99
|
-
return await jsonLs.findDocumentColors(document, jsonDocument);
|
|
100
|
-
});
|
|
101
|
-
},
|
|
102
|
-
provideColorPresentations(document, color, range) {
|
|
103
|
-
return worker(document, async (jsonDocument) => {
|
|
104
|
-
return await jsonLs.getColorPresentations(document, jsonDocument, color, range);
|
|
105
|
-
});
|
|
106
|
-
},
|
|
107
|
-
provideFoldingRanges(document) {
|
|
108
|
-
return worker(document, async () => {
|
|
109
|
-
return await jsonLs.getFoldingRanges(document);
|
|
110
|
-
});
|
|
111
|
-
},
|
|
112
|
-
provideSelectionRanges(document, positions) {
|
|
113
|
-
return worker(document, async (jsonDocument) => {
|
|
114
|
-
return await jsonLs.getSelectionRanges(document, positions, jsonDocument);
|
|
115
|
-
});
|
|
116
|
-
},
|
|
117
|
-
provideDocumentFormattingEdits(document, range, options) {
|
|
118
|
-
return worker(document, async () => {
|
|
119
|
-
const options_2 = await context.env.getConfiguration?.('json.format');
|
|
120
|
-
if (!(options_2?.enable ?? true)) {
|
|
121
|
-
return;
|
|
29
|
+
// https://github.com/microsoft/vscode/blob/09850876e652688fb142e2e19fd00fd38c0bc4ba/extensions/json-language-features/server/src/jsonServer.ts#L150
|
|
30
|
+
const triggerCharacters = ['"', ':'];
|
|
31
|
+
function create(settings) {
|
|
32
|
+
return (context) => {
|
|
33
|
+
if (!context) {
|
|
34
|
+
return { triggerCharacters };
|
|
35
|
+
}
|
|
36
|
+
const jsonDocuments = new WeakMap();
|
|
37
|
+
const workspaceContext = {
|
|
38
|
+
resolveRelativePath: (ref, base) => {
|
|
39
|
+
if (ref.match(/^\w[\w\d+.-]*:/)) {
|
|
40
|
+
// starts with a schema
|
|
41
|
+
return ref;
|
|
42
|
+
}
|
|
43
|
+
if (ref[0] === '/') { // resolve absolute path against the current workspace folder
|
|
44
|
+
return base + ref;
|
|
122
45
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
46
|
+
const baseUri = vscode_uri_1.URI.parse(base);
|
|
47
|
+
const baseUriDir = baseUri.path.endsWith('/') ? baseUri : vscode_uri_1.Utils.dirname(baseUri);
|
|
48
|
+
return vscode_uri_1.Utils.resolvePath(baseUriDir, ref).toString(true);
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
const jsonLs = json.getLanguageService({
|
|
52
|
+
schemaRequestService: async (uri) => await context.env.fs?.readFile(uri) ?? '',
|
|
53
|
+
workspaceContext,
|
|
54
|
+
clientCapabilities: context.env.clientCapabilities,
|
|
55
|
+
});
|
|
56
|
+
if (settings) {
|
|
57
|
+
jsonLs.configure(settings);
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
provide: {
|
|
61
|
+
'json/jsonDocument': getJsonDocument,
|
|
62
|
+
'json/languageService': () => jsonLs,
|
|
63
|
+
},
|
|
64
|
+
triggerCharacters,
|
|
65
|
+
provideCompletionItems(document, position) {
|
|
66
|
+
return worker(document, async (jsonDocument) => {
|
|
67
|
+
return await jsonLs.doComplete(document, position, jsonDocument);
|
|
126
68
|
});
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
return
|
|
69
|
+
},
|
|
70
|
+
resolveCompletionItem(item) {
|
|
71
|
+
return jsonLs.doResolve(item);
|
|
72
|
+
},
|
|
73
|
+
provideDefinition(document, position) {
|
|
74
|
+
return worker(document, async (jsonDocument) => {
|
|
75
|
+
return await jsonLs.findDefinition(document, position, jsonDocument);
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
provideDiagnostics(document) {
|
|
79
|
+
return worker(document, async (jsonDocument) => {
|
|
80
|
+
const documentLanguageSettings = undefined; // await getSettings(); // TODO
|
|
81
|
+
return await jsonLs.doValidation(document, jsonDocument, documentLanguageSettings, undefined);
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
provideHover(document, position) {
|
|
85
|
+
return worker(document, async (jsonDocument) => {
|
|
86
|
+
return await jsonLs.doHover(document, position, jsonDocument);
|
|
87
|
+
});
|
|
88
|
+
},
|
|
89
|
+
provideDocumentLinks(document) {
|
|
90
|
+
return worker(document, async (jsonDocument) => {
|
|
91
|
+
return await jsonLs.findLinks(document, jsonDocument);
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
provideDocumentSymbols(document) {
|
|
95
|
+
return worker(document, async (jsonDocument) => {
|
|
96
|
+
return await jsonLs.findDocumentSymbols2(document, jsonDocument);
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
provideDocumentColors(document) {
|
|
100
|
+
return worker(document, async (jsonDocument) => {
|
|
101
|
+
return await jsonLs.findDocumentColors(document, jsonDocument);
|
|
102
|
+
});
|
|
103
|
+
},
|
|
104
|
+
provideColorPresentations(document, color, range) {
|
|
105
|
+
return worker(document, async (jsonDocument) => {
|
|
106
|
+
return await jsonLs.getColorPresentations(document, jsonDocument, color, range);
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
provideFoldingRanges(document) {
|
|
110
|
+
return worker(document, async () => {
|
|
111
|
+
return await jsonLs.getFoldingRanges(document);
|
|
112
|
+
});
|
|
113
|
+
},
|
|
114
|
+
provideSelectionRanges(document, positions) {
|
|
115
|
+
return worker(document, async (jsonDocument) => {
|
|
116
|
+
return await jsonLs.getSelectionRanges(document, positions, jsonDocument);
|
|
117
|
+
});
|
|
118
|
+
},
|
|
119
|
+
provideDocumentFormattingEdits(document, range, options) {
|
|
120
|
+
return worker(document, async () => {
|
|
121
|
+
const options_2 = await context.env.getConfiguration?.('json.format');
|
|
122
|
+
if (!(options_2?.enable ?? true)) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
return jsonLs.format(document, range, {
|
|
126
|
+
...options_2,
|
|
127
|
+
...options,
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
function worker(document, callback) {
|
|
133
|
+
const jsonDocument = getJsonDocument(document);
|
|
134
|
+
if (!jsonDocument)
|
|
135
|
+
return;
|
|
136
|
+
return callback(jsonDocument);
|
|
137
|
+
}
|
|
138
|
+
function getJsonDocument(textDocument) {
|
|
139
|
+
if (textDocument.languageId !== 'json' && textDocument.languageId !== 'jsonc')
|
|
140
|
+
return;
|
|
141
|
+
const cache = jsonDocuments.get(textDocument);
|
|
142
|
+
if (cache) {
|
|
143
|
+
const [cacheVersion, cacheDoc] = cache;
|
|
144
|
+
if (cacheVersion === textDocument.version) {
|
|
145
|
+
return cacheDoc;
|
|
146
|
+
}
|
|
144
147
|
}
|
|
148
|
+
const doc = jsonLs.parseJSONDocument(textDocument);
|
|
149
|
+
jsonDocuments.set(textDocument, [textDocument.version, doc]);
|
|
150
|
+
return doc;
|
|
145
151
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
};
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
exports.create = create;
|
|
155
|
+
exports.default = create;
|
|
151
156
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "volar-service-json",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"main": "out/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -20,12 +20,12 @@
|
|
|
20
20
|
"vscode-languageserver-textdocument": "^1.0.8"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"@volar/language-service": "~1.
|
|
23
|
+
"@volar/language-service": "~1.10.0"
|
|
24
24
|
},
|
|
25
25
|
"peerDependenciesMeta": {
|
|
26
26
|
"@volar/language-service": {
|
|
27
27
|
"optional": true
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "7422c8d99d498df660ff9be3491545a5b45b3622"
|
|
31
31
|
}
|