@spyglassmc/language-server 0.1.0 → 0.1.3
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/lib/server.js +39 -32
- package/lib/util/index.d.ts +2 -2
- package/lib/util/index.js +20 -3
- package/lib/util/toCore.d.ts +3 -10
- package/lib/util/toCore.js +23 -22
- package/lib/util/toLS.d.ts +40 -47
- package/lib/util/toLS.js +312 -295
- package/lib/util/types.d.ts +3 -0
- package/package.json +5 -5
package/lib/server.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -28,7 +32,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
28
32
|
const core = __importStar(require("@spyglassmc/core"));
|
|
29
33
|
const je = __importStar(require("@spyglassmc/java-edition"));
|
|
30
34
|
const locales = __importStar(require("@spyglassmc/locales"));
|
|
31
|
-
const
|
|
35
|
+
const mcdoc = __importStar(require("@spyglassmc/mcdoc"));
|
|
32
36
|
const env_paths_1 = __importDefault(require("env-paths"));
|
|
33
37
|
const util = __importStar(require("util"));
|
|
34
38
|
const ls = __importStar(require("vscode-languageserver/node"));
|
|
@@ -54,13 +58,16 @@ const logger = {
|
|
|
54
58
|
};
|
|
55
59
|
let service;
|
|
56
60
|
connection.onInitialize(async (params) => {
|
|
61
|
+
const initializationOptions = params.initializationOptions;
|
|
57
62
|
logger.info(`[onInitialize] processId = ${JSON.stringify(params.processId)}`);
|
|
58
63
|
logger.info(`[onInitialize] clientInfo = ${JSON.stringify(params.clientInfo)}`);
|
|
59
|
-
logger.info(`[onInitialize] initializationOptions = ${JSON.stringify(
|
|
64
|
+
logger.info(`[onInitialize] initializationOptions = ${JSON.stringify(initializationOptions)}`);
|
|
60
65
|
capabilities = params.capabilities;
|
|
61
66
|
workspaceFolders = params.workspaceFolders ?? [];
|
|
62
|
-
|
|
63
|
-
|
|
67
|
+
if (initializationOptions?.inDevelopmentMode) {
|
|
68
|
+
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
69
|
+
logger.warn('Delayed 3 seconds manually. If you see this in production, it means SPGoding messed up.');
|
|
70
|
+
}
|
|
64
71
|
if (params.workDoneToken) {
|
|
65
72
|
progressReporter = connection.window.attachWorkDoneProgress(params.workDoneToken);
|
|
66
73
|
progressReporter.begin(locales.localize('server.progress.preparing.title'));
|
|
@@ -75,7 +82,7 @@ connection.onInitialize(async (params) => {
|
|
|
75
82
|
service = new core.Service({
|
|
76
83
|
cacheRoot,
|
|
77
84
|
initializers: [
|
|
78
|
-
|
|
85
|
+
mcdoc.initialize,
|
|
79
86
|
je.initialize,
|
|
80
87
|
],
|
|
81
88
|
isDebugging: false,
|
|
@@ -171,10 +178,10 @@ connection.onInitialized(async () => {
|
|
|
171
178
|
});
|
|
172
179
|
}
|
|
173
180
|
});
|
|
174
|
-
connection.onDidOpenTextDocument(
|
|
181
|
+
connection.onDidOpenTextDocument(({ textDocument: { text, uri, version, languageId: languageID } }) => {
|
|
175
182
|
service.project.onDidOpen(uri, languageID, version, text);
|
|
176
183
|
});
|
|
177
|
-
connection.onDidChangeTextDocument(
|
|
184
|
+
connection.onDidChangeTextDocument(({ contentChanges, textDocument: { uri, version } }) => {
|
|
178
185
|
service.project.onDidChange(uri, contentChanges, version);
|
|
179
186
|
});
|
|
180
187
|
connection.onDidCloseTextDocument(({ textDocument: { uri } }) => {
|
|
@@ -183,7 +190,7 @@ connection.onDidCloseTextDocument(({ textDocument: { uri } }) => {
|
|
|
183
190
|
connection.workspace.onDidRenameFiles(({}) => {
|
|
184
191
|
});
|
|
185
192
|
connection.onColorPresentation(async ({ textDocument: { uri }, color, range }) => {
|
|
186
|
-
const docAndNode = await service.project.
|
|
193
|
+
const docAndNode = await service.project.ensureParsedAndCheckedOnlyWhenReady(uri);
|
|
187
194
|
if (!docAndNode) {
|
|
188
195
|
return undefined;
|
|
189
196
|
}
|
|
@@ -192,7 +199,7 @@ connection.onColorPresentation(async ({ textDocument: { uri }, color, range }) =
|
|
|
192
199
|
return util_1.toLS.colorPresentationArray(presentation, doc);
|
|
193
200
|
});
|
|
194
201
|
connection.onDocumentColor(async ({ textDocument: { uri } }) => {
|
|
195
|
-
const docAndNode = await service.project.
|
|
202
|
+
const docAndNode = await service.project.ensureParsedAndCheckedOnlyWhenReady(uri);
|
|
196
203
|
if (!docAndNode) {
|
|
197
204
|
return undefined;
|
|
198
205
|
}
|
|
@@ -201,7 +208,7 @@ connection.onDocumentColor(async ({ textDocument: { uri } }) => {
|
|
|
201
208
|
return util_1.toLS.colorInformationArray(info, doc);
|
|
202
209
|
});
|
|
203
210
|
connection.onCompletion(async ({ textDocument: { uri }, position, context }) => {
|
|
204
|
-
const docAndNode = await service.project.
|
|
211
|
+
const docAndNode = await service.project.ensureParsedAndCheckedOnlyWhenReady(uri);
|
|
205
212
|
if (!docAndNode) {
|
|
206
213
|
return undefined;
|
|
207
214
|
}
|
|
@@ -214,61 +221,61 @@ connection.onRequest('spyglassmc/dataHackPubify', ({ initialism }) => {
|
|
|
214
221
|
return service.dataHackPubify(initialism);
|
|
215
222
|
});
|
|
216
223
|
connection.onDeclaration(async ({ textDocument: { uri }, position }) => {
|
|
217
|
-
const docAndNode = await service.project.
|
|
224
|
+
const docAndNode = await service.project.ensureParsedAndCheckedOnlyWhenReady(uri);
|
|
218
225
|
if (!docAndNode) {
|
|
219
226
|
return undefined;
|
|
220
227
|
}
|
|
221
228
|
const { doc, node } = docAndNode;
|
|
222
|
-
const ans = service.getSymbolLocations(node, doc, util_1.toCore.offset(position, doc), ['declaration', 'definition']);
|
|
229
|
+
const ans = await service.getSymbolLocations(node, doc, util_1.toCore.offset(position, doc), ['declaration', 'definition']);
|
|
223
230
|
return util_1.toLS.locationLink(ans, doc, capabilities.textDocument?.declaration?.linkSupport);
|
|
224
231
|
});
|
|
225
232
|
connection.onDefinition(async ({ textDocument: { uri }, position }) => {
|
|
226
|
-
const docAndNode = await service.project.
|
|
233
|
+
const docAndNode = await service.project.ensureParsedAndCheckedOnlyWhenReady(uri);
|
|
227
234
|
if (!docAndNode) {
|
|
228
235
|
return undefined;
|
|
229
236
|
}
|
|
230
237
|
const { doc, node } = docAndNode;
|
|
231
|
-
const ans = service.getSymbolLocations(node, doc, util_1.toCore.offset(position, doc), ['definition', 'declaration', 'implementation', 'typeDefinition']);
|
|
238
|
+
const ans = await service.getSymbolLocations(node, doc, util_1.toCore.offset(position, doc), ['definition', 'declaration', 'implementation', 'typeDefinition']);
|
|
232
239
|
return util_1.toLS.locationLink(ans, doc, capabilities.textDocument?.definition?.linkSupport);
|
|
233
240
|
});
|
|
234
241
|
connection.onImplementation(async ({ textDocument: { uri }, position }) => {
|
|
235
|
-
const docAndNode = await service.project.
|
|
242
|
+
const docAndNode = await service.project.ensureParsedAndCheckedOnlyWhenReady(uri);
|
|
236
243
|
if (!docAndNode) {
|
|
237
244
|
return undefined;
|
|
238
245
|
}
|
|
239
246
|
const { doc, node } = docAndNode;
|
|
240
|
-
const ans = service.getSymbolLocations(node, doc, util_1.toCore.offset(position, doc), ['implementation', 'definition']);
|
|
247
|
+
const ans = await service.getSymbolLocations(node, doc, util_1.toCore.offset(position, doc), ['implementation', 'definition']);
|
|
241
248
|
return util_1.toLS.locationLink(ans, doc, capabilities.textDocument?.implementation?.linkSupport);
|
|
242
249
|
});
|
|
243
250
|
connection.onReferences(async ({ textDocument: { uri }, position, context: { includeDeclaration } }) => {
|
|
244
|
-
const docAndNode = await service.project.
|
|
251
|
+
const docAndNode = await service.project.ensureParsedAndCheckedOnlyWhenReady(uri);
|
|
245
252
|
if (!docAndNode) {
|
|
246
253
|
return undefined;
|
|
247
254
|
}
|
|
248
255
|
const { doc, node } = docAndNode;
|
|
249
|
-
const ans = service.getSymbolLocations(node, doc, util_1.toCore.offset(position, doc), includeDeclaration ? undefined : ['reference']);
|
|
256
|
+
const ans = await service.getSymbolLocations(node, doc, util_1.toCore.offset(position, doc), includeDeclaration ? undefined : ['reference']);
|
|
250
257
|
return util_1.toLS.locationLink(ans, doc, false);
|
|
251
258
|
});
|
|
252
259
|
connection.onTypeDefinition(async ({ textDocument: { uri }, position }) => {
|
|
253
|
-
const docAndNode = await service.project.
|
|
260
|
+
const docAndNode = await service.project.ensureParsedAndCheckedOnlyWhenReady(uri);
|
|
254
261
|
if (!docAndNode) {
|
|
255
262
|
return undefined;
|
|
256
263
|
}
|
|
257
264
|
const { doc, node } = docAndNode;
|
|
258
|
-
const ans = service.getSymbolLocations(node, doc, util_1.toCore.offset(position, doc), ['typeDefinition']);
|
|
265
|
+
const ans = await service.getSymbolLocations(node, doc, util_1.toCore.offset(position, doc), ['typeDefinition']);
|
|
259
266
|
return util_1.toLS.locationLink(ans, doc, capabilities.textDocument?.typeDefinition?.linkSupport);
|
|
260
267
|
});
|
|
261
268
|
connection.onDocumentHighlight(async ({ textDocument: { uri }, position }) => {
|
|
262
|
-
const docAndNode = await service.project.
|
|
269
|
+
const docAndNode = await service.project.ensureParsedAndCheckedOnlyWhenReady(uri);
|
|
263
270
|
if (!docAndNode) {
|
|
264
271
|
return undefined;
|
|
265
272
|
}
|
|
266
273
|
const { doc, node } = docAndNode;
|
|
267
|
-
const ans = service.getSymbolLocations(node, doc, util_1.toCore.offset(position, doc), undefined, true);
|
|
274
|
+
const ans = await service.getSymbolLocations(node, doc, util_1.toCore.offset(position, doc), undefined, true);
|
|
268
275
|
return util_1.toLS.documentHighlight(ans);
|
|
269
276
|
});
|
|
270
277
|
connection.onDocumentSymbol(async ({ textDocument: { uri } }) => {
|
|
271
|
-
const docAndNode = await service.project.
|
|
278
|
+
const docAndNode = await service.project.ensureParsedAndCheckedOnlyWhenReady(uri);
|
|
272
279
|
if (!docAndNode) {
|
|
273
280
|
return undefined;
|
|
274
281
|
}
|
|
@@ -276,7 +283,7 @@ connection.onDocumentSymbol(async ({ textDocument: { uri } }) => {
|
|
|
276
283
|
return util_1.toLS.documentSymbolsFromTables([service.project.symbols.global, ...core.AstNode.getLocalsToLeaves(node)], doc, capabilities.textDocument?.documentSymbol?.hierarchicalDocumentSymbolSupport, capabilities.textDocument?.documentSymbol?.symbolKind?.valueSet);
|
|
277
284
|
});
|
|
278
285
|
connection.onHover(async ({ textDocument: { uri }, position }) => {
|
|
279
|
-
const docAndNode = await service.project.
|
|
286
|
+
const docAndNode = await service.project.ensureParsedAndCheckedOnlyWhenReady(uri);
|
|
280
287
|
if (!docAndNode) {
|
|
281
288
|
return undefined;
|
|
282
289
|
}
|
|
@@ -285,7 +292,7 @@ connection.onHover(async ({ textDocument: { uri }, position }) => {
|
|
|
285
292
|
return ans ? util_1.toLS.hover(ans, doc) : undefined;
|
|
286
293
|
});
|
|
287
294
|
connection.onRequest('spyglassmc/inlayHints', async ({ textDocument: { uri }, range }) => {
|
|
288
|
-
const docAndNode = await service.project.
|
|
295
|
+
const docAndNode = await service.project.ensureParsedAndCheckedOnlyWhenReady(uri);
|
|
289
296
|
if (!docAndNode) {
|
|
290
297
|
return [];
|
|
291
298
|
}
|
|
@@ -301,25 +308,25 @@ connection.onRequest('spyglassmc/showCacheRoot', async () => {
|
|
|
301
308
|
return service.project.showCacheRoot();
|
|
302
309
|
});
|
|
303
310
|
connection.languages.semanticTokens.on(async ({ textDocument: { uri } }) => {
|
|
304
|
-
const docAndNode = await service.project.
|
|
311
|
+
const docAndNode = await service.project.ensureParsedAndCheckedOnlyWhenReady(uri);
|
|
305
312
|
if (!docAndNode) {
|
|
306
313
|
return { data: [] };
|
|
307
314
|
}
|
|
308
315
|
const { doc, node } = docAndNode;
|
|
309
316
|
const tokens = service.colorize(node, doc);
|
|
310
|
-
return util_1.toLS.semanticTokens(tokens, doc);
|
|
317
|
+
return util_1.toLS.semanticTokens(tokens, doc, capabilities.textDocument?.semanticTokens?.multilineTokenSupport);
|
|
311
318
|
});
|
|
312
319
|
connection.languages.semanticTokens.onRange(async ({ textDocument: { uri }, range }) => {
|
|
313
|
-
const docAndNode = await service.project.
|
|
320
|
+
const docAndNode = await service.project.ensureParsedAndCheckedOnlyWhenReady(uri);
|
|
314
321
|
if (!docAndNode) {
|
|
315
322
|
return { data: [] };
|
|
316
323
|
}
|
|
317
324
|
const { doc, node } = docAndNode;
|
|
318
325
|
const tokens = service.colorize(node, doc, util_1.toCore.range(range, doc));
|
|
319
|
-
return util_1.toLS.semanticTokens(tokens, doc);
|
|
326
|
+
return util_1.toLS.semanticTokens(tokens, doc, capabilities.textDocument?.semanticTokens?.multilineTokenSupport);
|
|
320
327
|
});
|
|
321
328
|
connection.onSignatureHelp(async ({ textDocument: { uri }, position }) => {
|
|
322
|
-
const docAndNode = await service.project.
|
|
329
|
+
const docAndNode = await service.project.ensureParsedAndCheckedOnlyWhenReady(uri);
|
|
323
330
|
if (!docAndNode) {
|
|
324
331
|
return undefined;
|
|
325
332
|
}
|
|
@@ -331,7 +338,7 @@ connection.onWorkspaceSymbol(({ query }) => {
|
|
|
331
338
|
return util_1.toLS.symbolInformationArrayFromTable(service.project.symbols.global, query, capabilities.textDocument?.documentSymbol?.symbolKind?.valueSet);
|
|
332
339
|
});
|
|
333
340
|
connection.onDocumentFormatting(async ({ textDocument: { uri }, options }) => {
|
|
334
|
-
const docAndNode = await service.project.
|
|
341
|
+
const docAndNode = await service.project.ensureParsedAndCheckedOnlyWhenReady(uri);
|
|
335
342
|
if (!docAndNode) {
|
|
336
343
|
return undefined;
|
|
337
344
|
}
|
package/lib/util/index.d.ts
CHANGED
package/lib/util/index.js
CHANGED
|
@@ -1,16 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
8
12
|
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
9
25
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
26
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
27
|
};
|
|
12
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
|
|
14
|
-
|
|
29
|
+
exports.toLS = exports.toCore = void 0;
|
|
30
|
+
exports.toCore = __importStar(require("./toCore"));
|
|
31
|
+
exports.toLS = __importStar(require("./toLS"));
|
|
15
32
|
__exportStar(require("./types"), exports);
|
|
16
33
|
//# sourceMappingURL=index.js.map
|
package/lib/util/toCore.d.ts
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import * as core from '@spyglassmc/core';
|
|
2
2
|
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
3
3
|
import type * as ls from 'vscode-languageserver/node';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* Functions are named after types in `@spyglassmc/core`.
|
|
8
|
-
*/
|
|
9
|
-
export declare namespace toCore {
|
|
10
|
-
function offset(position: ls.Position, doc: TextDocument): number;
|
|
11
|
-
function range(range: ls.Range, doc: TextDocument): core.Range;
|
|
12
|
-
function color(color: ls.Color): core.Color;
|
|
13
|
-
}
|
|
4
|
+
export declare function offset(position: ls.Position, doc: TextDocument): number;
|
|
5
|
+
export declare function range(range: ls.Range, doc: TextDocument): core.Range;
|
|
6
|
+
export declare function color(color: ls.Color): core.Color;
|
|
14
7
|
//# sourceMappingURL=toCore.d.ts.map
|
package/lib/util/toCore.js
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* A series of functions that can transform `vscode-languageserver` types to `@spyglassmc/core` types.
|
|
4
|
+
*
|
|
5
|
+
* Functions are named after types in `@spyglassmc/core`.
|
|
6
|
+
*/
|
|
2
7
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
8
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
5
14
|
}) : (function(o, m, k, k2) {
|
|
6
15
|
if (k2 === undefined) k2 = k;
|
|
7
16
|
o[k2] = m[k];
|
|
@@ -19,26 +28,18 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
28
|
return result;
|
|
20
29
|
};
|
|
21
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.
|
|
31
|
+
exports.color = exports.range = exports.offset = void 0;
|
|
23
32
|
const core = __importStar(require("@spyglassmc/core"));
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return core.Range.create(offset(range.start, doc), offset(range.end, doc));
|
|
37
|
-
}
|
|
38
|
-
toCore.range = range;
|
|
39
|
-
function color(color) {
|
|
40
|
-
return [color.red, color.green, color.blue, color.alpha];
|
|
41
|
-
}
|
|
42
|
-
toCore.color = color;
|
|
43
|
-
})(toCore = exports.toCore || (exports.toCore = {}));
|
|
33
|
+
function offset(position, doc) {
|
|
34
|
+
return doc.offsetAt(position);
|
|
35
|
+
}
|
|
36
|
+
exports.offset = offset;
|
|
37
|
+
function range(range, doc) {
|
|
38
|
+
return core.Range.create(offset(range.start, doc), offset(range.end, doc));
|
|
39
|
+
}
|
|
40
|
+
exports.range = range;
|
|
41
|
+
function color(color) {
|
|
42
|
+
return [color.red, color.green, color.blue, color.alpha];
|
|
43
|
+
}
|
|
44
|
+
exports.color = color;
|
|
44
45
|
//# sourceMappingURL=toCore.js.map
|
package/lib/util/toLS.d.ts
CHANGED
|
@@ -2,51 +2,44 @@ import * as core from '@spyglassmc/core';
|
|
|
2
2
|
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
3
3
|
import * as ls from 'vscode-languageserver/node';
|
|
4
4
|
import type { MyLspInlayHint } from './types';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export declare
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
function parameterInformation(info: core.ParameterInfo): ls.ParameterInformation;
|
|
46
|
-
function symbolInformation(symbol: core.Symbol, symLoc: core.SymbolLocation, supportedKinds?: ls.SymbolKind[]): ls.SymbolInformation;
|
|
47
|
-
function symbolInformationArray(map: core.SymbolMap | undefined, query: string, supportedKinds?: ls.SymbolKind[]): ls.SymbolInformation[];
|
|
48
|
-
function symbolInformationArrayFromTable(table: core.SymbolTable, query: string, supportedKinds?: ls.SymbolKind[]): ls.SymbolInformation[];
|
|
49
|
-
function symbolKind(category: string, subcategory?: string, supportedKinds?: ls.SymbolKind[]): ls.SymbolKind;
|
|
50
|
-
function textEdit(range: core.Range, text: string, doc: TextDocument): ls.TextEdit;
|
|
51
|
-
}
|
|
5
|
+
export declare function color(color: core.Color): ls.Color;
|
|
6
|
+
export declare function colorInformation(info: core.ColorInfo, doc: TextDocument): ls.ColorInformation;
|
|
7
|
+
export declare function colorInformationArray(info: core.ColorInfo[], doc: TextDocument): ls.ColorInformation[];
|
|
8
|
+
export declare function colorPresentation(presentation: core.ColorPresentation, doc: TextDocument): ls.ColorPresentation;
|
|
9
|
+
export declare function colorPresentationArray(presentation: core.ColorPresentation[], doc: TextDocument): ls.ColorPresentation[];
|
|
10
|
+
export declare function diagnostic(error: core.LanguageError, doc: TextDocument): ls.Diagnostic;
|
|
11
|
+
export declare function diagnostics(errors: readonly core.LanguageError[], doc: TextDocument): ls.Diagnostic[];
|
|
12
|
+
export declare function diagnosticSeverity(severity: core.ErrorSeverity): ls.DiagnosticSeverity;
|
|
13
|
+
export declare function documentHighlight(locations: core.SymbolLocations | undefined): ls.DocumentHighlight[] | undefined;
|
|
14
|
+
export declare function documentSelector(meta: core.MetaRegistry): ls.DocumentSelector;
|
|
15
|
+
export declare function documentSymbol(symbol: core.Symbol, symLoc: core.SymbolLocation, doc: TextDocument, hierarchicalSupport: boolean | undefined, supportedKinds?: ls.SymbolKind[]): ls.DocumentSymbol;
|
|
16
|
+
export declare function documentSymbols(map: core.SymbolMap | undefined, doc: TextDocument, hierarchicalSupport: boolean | undefined, supportedKinds?: ls.SymbolKind[]): ls.DocumentSymbol[];
|
|
17
|
+
export declare function documentSymbolsFromTable(table: core.SymbolTable, doc: TextDocument, hierarchicalSupport: boolean | undefined, supportedKinds?: ls.SymbolKind[]): ls.DocumentSymbol[];
|
|
18
|
+
export declare function documentSymbolsFromTables(tables: core.SymbolTable[], doc: TextDocument, hierarchicalSupport: boolean | undefined, supportedKinds?: ls.SymbolKind[]): ls.DocumentSymbol[];
|
|
19
|
+
export declare function hover(hover: core.Hover, doc: TextDocument): ls.Hover;
|
|
20
|
+
export declare function inlayHint(hint: core.InlayHint, doc: TextDocument): MyLspInlayHint;
|
|
21
|
+
export declare function inlayHints(hints: core.InlayHint[], doc: TextDocument): MyLspInlayHint[];
|
|
22
|
+
export declare function completionItem(completion: core.CompletionItem, doc: TextDocument, requestedOffset: number, insertReplaceSupport: boolean | undefined): ls.CompletionItem;
|
|
23
|
+
export declare function location(location: {
|
|
24
|
+
uri: string;
|
|
25
|
+
posRange: core.PositionRange;
|
|
26
|
+
}): ls.Location;
|
|
27
|
+
export declare function locationLink(locations: core.SymbolLocations | undefined, doc: TextDocument, linkSupport: false): ls.Location[] | undefined;
|
|
28
|
+
export declare function locationLink(locations: core.SymbolLocations | undefined, doc: TextDocument, linkSupport: boolean | undefined): ls.LocationLink[] | ls.Location[] | undefined;
|
|
29
|
+
export declare function markupContent(value: string): ls.MarkupContent;
|
|
30
|
+
export declare function position(offset: number, doc: TextDocument): ls.Position;
|
|
31
|
+
export declare function range(range: core.Range, doc: TextDocument): ls.Range;
|
|
32
|
+
export declare function semanticTokenModifier(modifier: core.ColorTokenModifier): number;
|
|
33
|
+
export declare function semanticTokenModifiers(modifiers?: readonly core.ColorTokenModifier[]): number;
|
|
34
|
+
export declare function semanticTokens(tokens: readonly core.ColorToken[], doc: TextDocument, multilineSupport: boolean | undefined): ls.SemanticTokens;
|
|
35
|
+
export declare function semanticTokensLegend(): ls.SemanticTokensLegend;
|
|
36
|
+
export declare function semanticTokenType(type: core.ColorTokenType): number;
|
|
37
|
+
export declare function signatureHelp(help: core.SignatureHelp | undefined): ls.SignatureHelp | undefined;
|
|
38
|
+
export declare function signatureInformation(info: core.SignatureInfo): ls.SignatureInformation;
|
|
39
|
+
export declare function parameterInformation(info: core.ParameterInfo): ls.ParameterInformation;
|
|
40
|
+
export declare function symbolInformation(symbol: core.Symbol, symLoc: core.SymbolLocation, supportedKinds?: ls.SymbolKind[]): ls.SymbolInformation;
|
|
41
|
+
export declare function symbolInformationArray(map: core.SymbolMap | undefined, query: string, supportedKinds?: ls.SymbolKind[]): ls.SymbolInformation[];
|
|
42
|
+
export declare function symbolInformationArrayFromTable(table: core.SymbolTable, query: string, supportedKinds?: ls.SymbolKind[]): ls.SymbolInformation[];
|
|
43
|
+
export declare function symbolKind(category: string, subcategory?: string, supportedKinds?: ls.SymbolKind[]): ls.SymbolKind;
|
|
44
|
+
export declare function textEdit(editRange: core.Range, text: string, doc: TextDocument): ls.TextEdit;
|
|
52
45
|
//# sourceMappingURL=toLS.d.ts.map
|
package/lib/util/toLS.js
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* A series of functions that can transform `@spyglassmc/core` types to `vscode-languageserver` types.
|
|
4
|
+
*
|
|
5
|
+
* Functions are named after types in `vscode-languageserver`.
|
|
6
|
+
*/
|
|
2
7
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
8
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
5
14
|
}) : (function(o, m, k, k2) {
|
|
6
15
|
if (k2 === undefined) k2 = k;
|
|
7
16
|
o[k2] = m[k];
|
|
@@ -19,309 +28,317 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
28
|
return result;
|
|
20
29
|
};
|
|
21
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.
|
|
31
|
+
exports.textEdit = exports.symbolKind = exports.symbolInformationArrayFromTable = exports.symbolInformationArray = exports.symbolInformation = exports.parameterInformation = exports.signatureInformation = exports.signatureHelp = exports.semanticTokenType = exports.semanticTokensLegend = exports.semanticTokens = exports.semanticTokenModifiers = exports.semanticTokenModifier = exports.range = exports.position = exports.markupContent = exports.locationLink = exports.location = exports.completionItem = exports.inlayHints = exports.inlayHint = exports.hover = exports.documentSymbolsFromTables = exports.documentSymbolsFromTable = exports.documentSymbols = exports.documentSymbol = exports.documentSelector = exports.documentHighlight = exports.diagnosticSeverity = exports.diagnostics = exports.diagnostic = exports.colorPresentationArray = exports.colorPresentation = exports.colorInformationArray = exports.colorInformation = exports.color = void 0;
|
|
23
32
|
const core = __importStar(require("@spyglassmc/core"));
|
|
24
33
|
const ls = __importStar(require("vscode-languageserver/node"));
|
|
25
34
|
const node_1 = require("vscode-languageserver/node");
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
if (error.info?.unnecessary) {
|
|
62
|
-
(ans.tags ?? (ans.tags = []))?.push(ls.DiagnosticTag.Unnecessary);
|
|
63
|
-
}
|
|
64
|
-
if (error.info?.codeAction) {
|
|
65
|
-
ans.data = {
|
|
66
|
-
codeAction: error.info?.codeAction,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
if (error.info?.related) {
|
|
70
|
-
ans.relatedInformation = error.info?.related.map(v => ({
|
|
71
|
-
location: location(v.location),
|
|
72
|
-
message: v.message,
|
|
73
|
-
}));
|
|
74
|
-
}
|
|
75
|
-
return ans;
|
|
76
|
-
}
|
|
77
|
-
toLS.diagnostic = diagnostic;
|
|
78
|
-
function diagnostics(errors, doc) {
|
|
79
|
-
return errors.map(e => diagnostic(e, doc));
|
|
80
|
-
}
|
|
81
|
-
toLS.diagnostics = diagnostics;
|
|
82
|
-
function diagnosticSeverity(severity) {
|
|
83
|
-
switch (severity) {
|
|
84
|
-
case 0 /* Hint */:
|
|
85
|
-
return ls.DiagnosticSeverity.Hint;
|
|
86
|
-
case 1 /* Information */:
|
|
87
|
-
return ls.DiagnosticSeverity.Information;
|
|
88
|
-
case 2 /* Warning */:
|
|
89
|
-
return ls.DiagnosticSeverity.Warning;
|
|
90
|
-
case 3 /* Error */:
|
|
91
|
-
return ls.DiagnosticSeverity.Error;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
toLS.diagnosticSeverity = diagnosticSeverity;
|
|
95
|
-
function documentHighlight(locations) {
|
|
96
|
-
return locations?.locations
|
|
97
|
-
?.filter(loc => loc.posRange)
|
|
98
|
-
?.map(loc => ({ range: loc.posRange }));
|
|
99
|
-
}
|
|
100
|
-
toLS.documentHighlight = documentHighlight;
|
|
101
|
-
function documentSelector(meta) {
|
|
102
|
-
const ans = meta.getLanguages().map(id => ({ language: id }));
|
|
103
|
-
return ans;
|
|
104
|
-
}
|
|
105
|
-
toLS.documentSelector = documentSelector;
|
|
106
|
-
function documentSymbol(symbol, symLoc, doc, hierarchicalSupport, supportedKinds = []) {
|
|
107
|
-
return {
|
|
108
|
-
name: symbol.identifier,
|
|
109
|
-
kind: symbolKind(symbol.category, symbol.subcategory, supportedKinds),
|
|
110
|
-
range: symLoc.fullPosRange ?? symLoc.posRange ?? ZeroRange,
|
|
111
|
-
selectionRange: symLoc.posRange ?? ZeroRange,
|
|
112
|
-
children: hierarchicalSupport ? documentSymbols(symbol.members, doc, hierarchicalSupport, supportedKinds) : undefined,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
toLS.documentSymbol = documentSymbol;
|
|
116
|
-
function documentSymbols(map = {}, doc, hierarchicalSupport, supportedKinds = []) {
|
|
117
|
-
return Object.values(map)
|
|
118
|
-
.map(s => [s, [...s.declaration ?? [], ...s.definition ?? [], ...s.implementation ?? [], ...s.typeDefinition ?? []].find(l => l.uri === doc.uri)])
|
|
119
|
-
.filter(([_s, l]) => !!l)
|
|
120
|
-
.map(([s, l]) => documentSymbol(s, l, doc, hierarchicalSupport, supportedKinds));
|
|
121
|
-
}
|
|
122
|
-
toLS.documentSymbols = documentSymbols;
|
|
123
|
-
function documentSymbolsFromTable(table, doc, hierarchicalSupport, supportedKinds = []) {
|
|
124
|
-
return Object.values(table)
|
|
125
|
-
.map(m => documentSymbols(m, doc, hierarchicalSupport, supportedKinds))
|
|
126
|
-
.flat();
|
|
127
|
-
}
|
|
128
|
-
toLS.documentSymbolsFromTable = documentSymbolsFromTable;
|
|
129
|
-
function documentSymbolsFromTables(tables, doc, hierarchicalSupport, supportedKinds = []) {
|
|
130
|
-
return tables
|
|
131
|
-
.map(t => documentSymbolsFromTable(t, doc, hierarchicalSupport, supportedKinds))
|
|
132
|
-
.flat();
|
|
133
|
-
}
|
|
134
|
-
toLS.documentSymbolsFromTables = documentSymbolsFromTables;
|
|
135
|
-
function hover(hover, doc) {
|
|
136
|
-
const ans = {
|
|
137
|
-
contents: markupContent(hover.markdown),
|
|
138
|
-
range: range(hover.range, doc),
|
|
139
|
-
};
|
|
140
|
-
return ans;
|
|
141
|
-
}
|
|
142
|
-
toLS.hover = hover;
|
|
143
|
-
function inlayHint(hint, doc) {
|
|
144
|
-
return {
|
|
145
|
-
position: doc.positionAt(hint.offset),
|
|
146
|
-
text: hint.text,
|
|
35
|
+
const ZeroPosition = { line: 0, character: 0 };
|
|
36
|
+
const ZeroRange = { start: ZeroPosition, end: ZeroPosition };
|
|
37
|
+
function color(color) {
|
|
38
|
+
return ls.Color.create(...color);
|
|
39
|
+
}
|
|
40
|
+
exports.color = color;
|
|
41
|
+
function colorInformation(info, doc) {
|
|
42
|
+
return ls.ColorInformation.create(range(info.range, doc), color(info.color));
|
|
43
|
+
}
|
|
44
|
+
exports.colorInformation = colorInformation;
|
|
45
|
+
function colorInformationArray(info, doc) {
|
|
46
|
+
return info.map(i => colorInformation(i, doc));
|
|
47
|
+
}
|
|
48
|
+
exports.colorInformationArray = colorInformationArray;
|
|
49
|
+
function colorPresentation(presentation, doc) {
|
|
50
|
+
const edit = ls.TextEdit.replace(range(presentation.range, doc), presentation.text);
|
|
51
|
+
return ls.ColorPresentation.create(presentation.label, edit);
|
|
52
|
+
}
|
|
53
|
+
exports.colorPresentation = colorPresentation;
|
|
54
|
+
function colorPresentationArray(presentation, doc) {
|
|
55
|
+
return presentation.map(p => colorPresentation(p, doc));
|
|
56
|
+
}
|
|
57
|
+
exports.colorPresentationArray = colorPresentationArray;
|
|
58
|
+
function diagnostic(error, doc) {
|
|
59
|
+
const ans = ls.Diagnostic.create(range(error.range, doc), error.message, diagnosticSeverity(error.severity), undefined, 'spyglassmc');
|
|
60
|
+
if (error.info?.deprecated) {
|
|
61
|
+
(ans.tags ?? (ans.tags = []))?.push(ls.DiagnosticTag.Deprecated);
|
|
62
|
+
}
|
|
63
|
+
if (error.info?.unnecessary) {
|
|
64
|
+
(ans.tags ?? (ans.tags = []))?.push(ls.DiagnosticTag.Unnecessary);
|
|
65
|
+
}
|
|
66
|
+
if (error.info?.codeAction) {
|
|
67
|
+
ans.data = {
|
|
68
|
+
codeAction: error.info?.codeAction,
|
|
147
69
|
};
|
|
148
70
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
71
|
+
if (error.info?.related) {
|
|
72
|
+
ans.relatedInformation = error.info?.related.map(v => ({
|
|
73
|
+
location: location(v.location),
|
|
74
|
+
message: v.message,
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
return ans;
|
|
78
|
+
}
|
|
79
|
+
exports.diagnostic = diagnostic;
|
|
80
|
+
function diagnostics(errors, doc) {
|
|
81
|
+
return errors.map(e => diagnostic(e, doc));
|
|
82
|
+
}
|
|
83
|
+
exports.diagnostics = diagnostics;
|
|
84
|
+
function diagnosticSeverity(severity) {
|
|
85
|
+
switch (severity) {
|
|
86
|
+
case 0 /* core.ErrorSeverity.Hint */:
|
|
87
|
+
return ls.DiagnosticSeverity.Hint;
|
|
88
|
+
case 1 /* core.ErrorSeverity.Information */:
|
|
89
|
+
return ls.DiagnosticSeverity.Information;
|
|
90
|
+
case 2 /* core.ErrorSeverity.Warning */:
|
|
91
|
+
return ls.DiagnosticSeverity.Warning;
|
|
92
|
+
case 3 /* core.ErrorSeverity.Error */:
|
|
93
|
+
return ls.DiagnosticSeverity.Error;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.diagnosticSeverity = diagnosticSeverity;
|
|
97
|
+
function documentHighlight(locations) {
|
|
98
|
+
return locations?.locations
|
|
99
|
+
?.filter(loc => loc.posRange)
|
|
100
|
+
?.map(loc => ({ range: loc.posRange }));
|
|
101
|
+
}
|
|
102
|
+
exports.documentHighlight = documentHighlight;
|
|
103
|
+
function documentSelector(meta) {
|
|
104
|
+
const ans = meta.getLanguages().map(id => ({ language: id }));
|
|
105
|
+
return ans;
|
|
106
|
+
}
|
|
107
|
+
exports.documentSelector = documentSelector;
|
|
108
|
+
function documentSymbol(symbol, symLoc, doc, hierarchicalSupport, supportedKinds = []) {
|
|
109
|
+
return {
|
|
110
|
+
name: symbol.identifier,
|
|
111
|
+
kind: symbolKind(symbol.category, symbol.subcategory, supportedKinds),
|
|
112
|
+
range: symLoc.fullPosRange ?? symLoc.posRange ?? ZeroRange,
|
|
113
|
+
selectionRange: symLoc.posRange ?? ZeroRange,
|
|
114
|
+
children: hierarchicalSupport ? documentSymbols(symbol.members, doc, hierarchicalSupport, supportedKinds) : undefined,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
exports.documentSymbol = documentSymbol;
|
|
118
|
+
function documentSymbols(map = {}, doc, hierarchicalSupport, supportedKinds = []) {
|
|
119
|
+
return Object.values(map)
|
|
120
|
+
.map(s => [s, [...s.declaration ?? [], ...s.definition ?? [], ...s.implementation ?? [], ...s.typeDefinition ?? []].find(l => l.uri === doc.uri)])
|
|
121
|
+
.filter(([_s, l]) => !!l)
|
|
122
|
+
.map(([s, l]) => documentSymbol(s, l, doc, hierarchicalSupport, supportedKinds));
|
|
123
|
+
}
|
|
124
|
+
exports.documentSymbols = documentSymbols;
|
|
125
|
+
function documentSymbolsFromTable(table, doc, hierarchicalSupport, supportedKinds = []) {
|
|
126
|
+
return Object.values(table)
|
|
127
|
+
.map(m => documentSymbols(m, doc, hierarchicalSupport, supportedKinds))
|
|
128
|
+
.flat();
|
|
129
|
+
}
|
|
130
|
+
exports.documentSymbolsFromTable = documentSymbolsFromTable;
|
|
131
|
+
function documentSymbolsFromTables(tables, doc, hierarchicalSupport, supportedKinds = []) {
|
|
132
|
+
return tables
|
|
133
|
+
.map(t => documentSymbolsFromTable(t, doc, hierarchicalSupport, supportedKinds))
|
|
134
|
+
.flat();
|
|
135
|
+
}
|
|
136
|
+
exports.documentSymbolsFromTables = documentSymbolsFromTables;
|
|
137
|
+
function hover(hover, doc) {
|
|
138
|
+
const ans = {
|
|
139
|
+
contents: markupContent(hover.markdown),
|
|
140
|
+
range: range(hover.range, doc),
|
|
141
|
+
};
|
|
142
|
+
return ans;
|
|
143
|
+
}
|
|
144
|
+
exports.hover = hover;
|
|
145
|
+
function inlayHint(hint, doc) {
|
|
146
|
+
return {
|
|
147
|
+
position: doc.positionAt(hint.offset),
|
|
148
|
+
text: hint.text,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
exports.inlayHint = inlayHint;
|
|
152
|
+
function inlayHints(hints, doc) {
|
|
153
|
+
return hints.map(h => inlayHint(h, doc));
|
|
154
|
+
}
|
|
155
|
+
exports.inlayHints = inlayHints;
|
|
156
|
+
function completionItem(completion, doc, requestedOffset, insertReplaceSupport) {
|
|
157
|
+
const insertText = completion.insertText ?? completion.label;
|
|
158
|
+
const canInsertReplace = insertReplaceSupport && ![core.CR, core.LF, core.CRLF].includes(insertText);
|
|
159
|
+
const textEdit = canInsertReplace
|
|
160
|
+
? ls.InsertReplaceEdit.create(insertText,
|
|
161
|
+
/* insert */ range(core.Range.create(completion.range.start, requestedOffset), doc),
|
|
162
|
+
/* replace */ range(completion.range, doc))
|
|
163
|
+
: ls.TextEdit.replace(range(completion.range, doc), insertText);
|
|
164
|
+
const ans = {
|
|
165
|
+
label: completion.label,
|
|
166
|
+
kind: completion.kind,
|
|
167
|
+
detail: completion.detail,
|
|
168
|
+
documentation: completion.documentation,
|
|
169
|
+
filterText: completion.filterText,
|
|
170
|
+
sortText: completion.sortText,
|
|
171
|
+
textEdit,
|
|
172
|
+
insertTextFormat: node_1.InsertTextFormat.Snippet,
|
|
173
|
+
insertTextMode: ls.InsertTextMode.adjustIndentation,
|
|
174
|
+
...completion.deprecated ? { tags: [ls.CompletionItemTag.Deprecated] } : {},
|
|
175
|
+
};
|
|
176
|
+
return ans;
|
|
177
|
+
}
|
|
178
|
+
exports.completionItem = completionItem;
|
|
179
|
+
function location(location) {
|
|
180
|
+
return {
|
|
181
|
+
uri: location.uri,
|
|
182
|
+
range: location.posRange,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
exports.location = location;
|
|
186
|
+
function locationLink(locations, doc, linkSupport) {
|
|
187
|
+
return locations?.locations
|
|
188
|
+
? linkSupport
|
|
189
|
+
? locations.locations.map(loc => ({
|
|
190
|
+
originSelectionRange: range(locations.range, doc),
|
|
191
|
+
targetUri: loc.uri,
|
|
192
|
+
targetRange: loc.fullPosRange ?? loc.posRange ?? ZeroRange,
|
|
193
|
+
targetSelectionRange: loc.posRange ?? ZeroRange,
|
|
194
|
+
}))
|
|
195
|
+
: (locations.locations).map(loc => location({ uri: loc.uri, posRange: loc.posRange ?? ZeroRange }))
|
|
196
|
+
: undefined;
|
|
197
|
+
}
|
|
198
|
+
exports.locationLink = locationLink;
|
|
199
|
+
function markupContent(value) {
|
|
200
|
+
return {
|
|
201
|
+
kind: ls.MarkupKind.Markdown,
|
|
202
|
+
value: value,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
exports.markupContent = markupContent;
|
|
206
|
+
function position(offset, doc) {
|
|
207
|
+
return doc.positionAt(offset);
|
|
208
|
+
}
|
|
209
|
+
exports.position = position;
|
|
210
|
+
function range(range, doc) {
|
|
211
|
+
return ls.Range.create(position(range.start, doc), position(range.end, doc));
|
|
212
|
+
}
|
|
213
|
+
exports.range = range;
|
|
214
|
+
function semanticTokenModifier(modifier) {
|
|
215
|
+
return core.ColorTokenModifiers.indexOf(modifier);
|
|
216
|
+
}
|
|
217
|
+
exports.semanticTokenModifier = semanticTokenModifier;
|
|
218
|
+
function semanticTokenModifiers(modifiers = []) {
|
|
219
|
+
let ans = 0;
|
|
220
|
+
for (const modifier of modifiers) {
|
|
221
|
+
ans += 1 << semanticTokenModifier(modifier);
|
|
222
|
+
}
|
|
223
|
+
return ans;
|
|
224
|
+
}
|
|
225
|
+
exports.semanticTokenModifiers = semanticTokenModifiers;
|
|
226
|
+
const MaxCharacterNumber = 2147483647;
|
|
227
|
+
function semanticTokens(tokens, doc, multilineSupport) {
|
|
228
|
+
const builder = new ls.SemanticTokensBuilder();
|
|
229
|
+
for (const token of tokens) {
|
|
230
|
+
const pos = position(token.range.start, doc);
|
|
231
|
+
const endPos = position(token.range.end, doc);
|
|
232
|
+
const type = semanticTokenType(token.type);
|
|
233
|
+
const modifiers = semanticTokenModifiers(token.modifiers);
|
|
234
|
+
if (multilineSupport || pos.line === endPos.line) {
|
|
228
235
|
const length = token.range.end - token.range.start;
|
|
229
|
-
builder.push(pos.line, pos.character, length,
|
|
236
|
+
builder.push(pos.line, pos.character, length, type, modifiers);
|
|
230
237
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
toLS.semanticTokensLegend = semanticTokensLegend;
|
|
242
|
-
function semanticTokenType(type) {
|
|
243
|
-
return core.ColorTokenTypes.indexOf(type);
|
|
244
|
-
}
|
|
245
|
-
toLS.semanticTokenType = semanticTokenType;
|
|
246
|
-
function signatureHelp(help) {
|
|
247
|
-
if (!help || help.signatures.length === 0) {
|
|
248
|
-
return undefined;
|
|
238
|
+
else {
|
|
239
|
+
const firstLineRemainingLength = doc.getText(ls.Range.create(pos.line, pos.character, pos.line, MaxCharacterNumber)).length;
|
|
240
|
+
const lastLineLeadingLength = doc.getText(ls.Range.create(endPos.line, 0, endPos.line, endPos.character)).length;
|
|
241
|
+
builder.push(pos.line, pos.character, firstLineRemainingLength, type, modifiers);
|
|
242
|
+
for (let i = pos.line + 1; i < endPos.line - 1; i++) {
|
|
243
|
+
const lineLength = doc.getText(ls.Range.create(i, 0, i, MaxCharacterNumber)).length;
|
|
244
|
+
builder.push(i, 0, lineLength, type, modifiers);
|
|
245
|
+
}
|
|
246
|
+
builder.push(endPos.line, 0, lastLineLeadingLength, type, modifiers);
|
|
249
247
|
}
|
|
250
|
-
return {
|
|
251
|
-
signatures: help.signatures.map(signatureInformation),
|
|
252
|
-
activeParameter: help.signatures[help.activeSignature].activeParameter,
|
|
253
|
-
activeSignature: help.activeSignature,
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
toLS.signatureHelp = signatureHelp;
|
|
257
|
-
function signatureInformation(info) {
|
|
258
|
-
return {
|
|
259
|
-
label: info.label,
|
|
260
|
-
activeParameter: info.activeParameter,
|
|
261
|
-
documentation: info.documentation ? markupContent(info.documentation) : undefined,
|
|
262
|
-
parameters: info.parameters.map(parameterInformation),
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
toLS.signatureInformation = signatureInformation;
|
|
266
|
-
function parameterInformation(info) {
|
|
267
|
-
return {
|
|
268
|
-
label: info.label,
|
|
269
|
-
documentation: info.documentation ? markupContent(info.documentation) : undefined,
|
|
270
|
-
};
|
|
271
248
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
249
|
+
return builder.build();
|
|
250
|
+
}
|
|
251
|
+
exports.semanticTokens = semanticTokens;
|
|
252
|
+
function semanticTokensLegend() {
|
|
253
|
+
const ans = {
|
|
254
|
+
tokenTypes: core.ColorTokenTypes,
|
|
255
|
+
tokenModifiers: core.ColorTokenModifiers,
|
|
256
|
+
};
|
|
257
|
+
return ans;
|
|
258
|
+
}
|
|
259
|
+
exports.semanticTokensLegend = semanticTokensLegend;
|
|
260
|
+
function semanticTokenType(type) {
|
|
261
|
+
return core.ColorTokenTypes.indexOf(type);
|
|
262
|
+
}
|
|
263
|
+
exports.semanticTokenType = semanticTokenType;
|
|
264
|
+
function signatureHelp(help) {
|
|
265
|
+
if (!help || help.signatures.length === 0) {
|
|
266
|
+
return undefined;
|
|
267
|
+
}
|
|
268
|
+
return {
|
|
269
|
+
signatures: help.signatures.map(signatureInformation),
|
|
270
|
+
activeParameter: help.signatures[help.activeSignature].activeParameter,
|
|
271
|
+
activeSignature: help.activeSignature,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
exports.signatureHelp = signatureHelp;
|
|
275
|
+
function signatureInformation(info) {
|
|
276
|
+
return {
|
|
277
|
+
label: info.label,
|
|
278
|
+
activeParameter: info.activeParameter,
|
|
279
|
+
documentation: info.documentation ? markupContent(info.documentation) : undefined,
|
|
280
|
+
parameters: info.parameters.map(parameterInformation),
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
exports.signatureInformation = signatureInformation;
|
|
284
|
+
function parameterInformation(info) {
|
|
285
|
+
return {
|
|
286
|
+
label: info.label,
|
|
287
|
+
documentation: info.documentation ? markupContent(info.documentation) : undefined,
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
exports.parameterInformation = parameterInformation;
|
|
291
|
+
function symbolInformation(symbol, symLoc, supportedKinds = []) {
|
|
292
|
+
return {
|
|
293
|
+
name: symbol.identifier,
|
|
294
|
+
kind: symbolKind(symbol.category, symbol.subcategory, supportedKinds),
|
|
295
|
+
location: location({ uri: symLoc.uri, posRange: symLoc.fullPosRange ?? symLoc.posRange ?? ZeroRange }),
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
exports.symbolInformation = symbolInformation;
|
|
299
|
+
function symbolInformationArray(map = {}, query, supportedKinds = []) {
|
|
300
|
+
return Object.values(map)
|
|
301
|
+
.filter(s => s.identifier.includes(query))
|
|
302
|
+
.map(s => [s, [...s.declaration ?? [], ...s.definition ?? [], ...s.implementation ?? [], ...s.typeDefinition ?? []][0]])
|
|
303
|
+
.filter(([_s, l]) => !!l)
|
|
304
|
+
.map(([s, l]) => symbolInformation(s, l, supportedKinds));
|
|
305
|
+
}
|
|
306
|
+
exports.symbolInformationArray = symbolInformationArray;
|
|
307
|
+
function symbolInformationArrayFromTable(table, query, supportedKinds = []) {
|
|
308
|
+
return Object.values(table)
|
|
309
|
+
.map(m => symbolInformationArray(m, query, supportedKinds))
|
|
310
|
+
.flat();
|
|
311
|
+
}
|
|
312
|
+
exports.symbolInformationArrayFromTable = symbolInformationArrayFromTable;
|
|
313
|
+
function symbolKind(category, subcategory = '', supportedKinds = []) {
|
|
314
|
+
const UltimateFallback = ls.SymbolKind.Variable;
|
|
315
|
+
const getKind = (kind, fallback) => supportedKinds?.includes(kind) ? kind : fallback;
|
|
316
|
+
if (core.ResourceLocationCategory.is(category)) {
|
|
317
|
+
return ls.SymbolKind.Function;
|
|
318
|
+
}
|
|
319
|
+
if (category === 'mcdoc') {
|
|
311
320
|
const map = new Map([
|
|
312
|
-
['
|
|
313
|
-
['
|
|
314
|
-
['
|
|
315
|
-
['
|
|
316
|
-
['
|
|
317
|
-
['team', ls.SymbolKind.Array],
|
|
321
|
+
['enum', ls.SymbolKind.Enum],
|
|
322
|
+
['enum_key', getKind(ls.SymbolKind.EnumMember, ls.SymbolKind.Field)],
|
|
323
|
+
['compound', getKind(ls.SymbolKind.Struct, ls.SymbolKind.Interface)],
|
|
324
|
+
['compound_key', ls.SymbolKind.Field],
|
|
325
|
+
['module', ls.SymbolKind.Module],
|
|
318
326
|
]);
|
|
319
|
-
return map.get(
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
+
return map.get(subcategory) ?? UltimateFallback;
|
|
328
|
+
}
|
|
329
|
+
const map = new Map([
|
|
330
|
+
['attribute_modifier_uuid', ls.SymbolKind.Number],
|
|
331
|
+
['mcdoc/description', ls.SymbolKind.Constructor],
|
|
332
|
+
['objective', ls.SymbolKind.Variable],
|
|
333
|
+
['score_holder', ls.SymbolKind.Class],
|
|
334
|
+
['tag', ls.SymbolKind.String],
|
|
335
|
+
['team', ls.SymbolKind.Array],
|
|
336
|
+
]);
|
|
337
|
+
return map.get(category) ?? UltimateFallback;
|
|
338
|
+
}
|
|
339
|
+
exports.symbolKind = symbolKind;
|
|
340
|
+
function textEdit(editRange, text, doc) {
|
|
341
|
+
return ls.TextEdit.replace(range(editRange, doc), text);
|
|
342
|
+
}
|
|
343
|
+
exports.textEdit = textEdit;
|
|
327
344
|
//# sourceMappingURL=toLS.js.map
|
package/lib/util/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spyglassmc/language-server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"main": "lib/server.js",
|
|
5
5
|
"types": "lib/server.d.ts",
|
|
6
6
|
"author": "SPGoding",
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
"env-paths": "^2.2.1",
|
|
21
21
|
"vscode-languageserver": "^7.0.0",
|
|
22
22
|
"vscode-languageserver-textdocument": "^1.0.1",
|
|
23
|
-
"@spyglassmc/core": "0.1.
|
|
24
|
-
"@spyglassmc/java-edition": "0.1.
|
|
25
|
-
"@spyglassmc/locales": "0.1.
|
|
26
|
-
"@spyglassmc/
|
|
23
|
+
"@spyglassmc/core": "0.1.2",
|
|
24
|
+
"@spyglassmc/java-edition": "0.1.3",
|
|
25
|
+
"@spyglassmc/locales": "0.1.2",
|
|
26
|
+
"@spyglassmc/mcdoc": "0.1.1"
|
|
27
27
|
},
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public"
|