@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 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.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
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 nbtdoc = __importStar(require("@spyglassmc/nbtdoc"));
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(params.initializationOptions)}`);
64
+ logger.info(`[onInitialize] initializationOptions = ${JSON.stringify(initializationOptions)}`);
60
65
  capabilities = params.capabilities;
61
66
  workspaceFolders = params.workspaceFolders ?? [];
62
- await new Promise(resolve => setTimeout(resolve, 3000));
63
- logger.warn('Delayed 3 seconds manually. If you see this in production, it means SPGoding messed up.');
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
- nbtdoc.initialize,
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(async ({ textDocument: { text, uri, version, languageId: languageID } }) => {
181
+ connection.onDidOpenTextDocument(({ textDocument: { text, uri, version, languageId: languageID } }) => {
175
182
  service.project.onDidOpen(uri, languageID, version, text);
176
183
  });
177
- connection.onDidChangeTextDocument(async ({ contentChanges, textDocument: { uri, version } }) => {
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.ensureParsedAndChecked(uri);
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.ensureParsedAndChecked(uri);
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.ensureParsedAndChecked(uri);
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.ensureParsedAndChecked(uri);
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.ensureParsedAndChecked(uri);
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.ensureParsedAndChecked(uri);
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.ensureParsedAndChecked(uri);
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.ensureParsedAndChecked(uri);
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.ensureParsedAndChecked(uri);
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.ensureParsedAndChecked(uri);
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.ensureParsedAndChecked(uri);
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.ensureParsedAndChecked(uri);
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.ensureParsedAndChecked(uri);
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.ensureParsedAndChecked(uri);
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.ensureParsedAndChecked(uri);
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.ensureParsedAndChecked(uri);
341
+ const docAndNode = await service.project.ensureParsedAndCheckedOnlyWhenReady(uri);
335
342
  if (!docAndNode) {
336
343
  return undefined;
337
344
  }
@@ -1,4 +1,4 @@
1
- export * from './toCore';
2
- export * from './toLS';
1
+ export * as toCore from './toCore';
2
+ export * as toLS from './toLS';
3
3
  export * from './types';
4
4
  //# sourceMappingURL=index.d.ts.map
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.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
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
- __exportStar(require("./toCore"), exports);
14
- __exportStar(require("./toLS"), exports);
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
@@ -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
- * A series of functions that can transform `vscode-languageserver` types to `@spyglassmc/core` types.
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
@@ -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.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
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.toCore = void 0;
31
+ exports.color = exports.range = exports.offset = void 0;
23
32
  const core = __importStar(require("@spyglassmc/core"));
24
- /**
25
- * A series of functions that can transform `vscode-languageserver` types to `@spyglassmc/core` types.
26
- *
27
- * Functions are named after types in `@spyglassmc/core`.
28
- */
29
- var toCore;
30
- (function (toCore) {
31
- function offset(position, doc) {
32
- return doc.offsetAt(position);
33
- }
34
- toCore.offset = offset;
35
- function range(range, doc) {
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
@@ -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
- * A series of functions that can transform `@spyglassmc/core` types to `vscode-languageserver` types.
7
- *
8
- * Functions are named after types in `vscode-languageserver`.
9
- */
10
- export declare namespace toLS {
11
- function color(color: core.Color): ls.Color;
12
- function colorInformation(info: core.ColorInfo, doc: TextDocument): ls.ColorInformation;
13
- function colorInformationArray(info: core.ColorInfo[], doc: TextDocument): ls.ColorInformation[];
14
- function colorPresentation(presentation: core.ColorPresentation, doc: TextDocument): ls.ColorPresentation;
15
- function colorPresentationArray(presentation: core.ColorPresentation[], doc: TextDocument): ls.ColorPresentation[];
16
- function diagnostic(error: core.LanguageError, doc: TextDocument): ls.Diagnostic;
17
- function diagnostics(errors: readonly core.LanguageError[], doc: TextDocument): ls.Diagnostic[];
18
- function diagnosticSeverity(severity: core.ErrorSeverity): ls.DiagnosticSeverity;
19
- function documentHighlight(locations: core.SymbolLocations | undefined): ls.DocumentHighlight[] | undefined;
20
- function documentSelector(meta: core.MetaRegistry): ls.DocumentSelector;
21
- function documentSymbol(symbol: core.Symbol, symLoc: core.SymbolLocation, doc: TextDocument, hierarchicalSupport: boolean | undefined, supportedKinds?: ls.SymbolKind[]): ls.DocumentSymbol;
22
- function documentSymbols(map: core.SymbolMap | undefined, doc: TextDocument, hierarchicalSupport: boolean | undefined, supportedKinds?: ls.SymbolKind[]): ls.DocumentSymbol[];
23
- function documentSymbolsFromTable(table: core.SymbolTable, doc: TextDocument, hierarchicalSupport: boolean | undefined, supportedKinds?: ls.SymbolKind[]): ls.DocumentSymbol[];
24
- function documentSymbolsFromTables(tables: core.SymbolTable[], doc: TextDocument, hierarchicalSupport: boolean | undefined, supportedKinds?: ls.SymbolKind[]): ls.DocumentSymbol[];
25
- function hover(hover: core.Hover, doc: TextDocument): ls.Hover;
26
- function inlayHint(hint: core.InlayHint, doc: TextDocument): MyLspInlayHint;
27
- function inlayHints(hints: core.InlayHint[], doc: TextDocument): MyLspInlayHint[];
28
- function completionItem(completion: core.CompletionItem, doc: TextDocument, requestedOffset: number, insertReplaceSupport: boolean | undefined): ls.CompletionItem;
29
- function location(location: {
30
- uri: string;
31
- posRange: core.PositionRange;
32
- }): ls.Location;
33
- function locationLink(locations: core.SymbolLocations | undefined, doc: TextDocument, linkSupport: false): ls.Location[] | undefined;
34
- function locationLink(locations: core.SymbolLocations | undefined, doc: TextDocument, linkSupport: boolean | undefined): ls.LocationLink[] | ls.Location[] | undefined;
35
- function markupContent(value: string): ls.MarkupContent;
36
- function position(offset: number, doc: TextDocument): ls.Position;
37
- function range(range: core.Range, doc: TextDocument): ls.Range;
38
- function semanticTokenModifier(modifier: core.ColorTokenModifier): number;
39
- function semanticTokenModifiers(modifiers?: readonly core.ColorTokenModifier[]): number;
40
- function semanticTokens(tokens: readonly core.ColorToken[], doc: TextDocument): ls.SemanticTokens;
41
- function semanticTokensLegend(): ls.SemanticTokensLegend;
42
- function semanticTokenType(type: core.ColorTokenType): number;
43
- function signatureHelp(help: core.SignatureHelp | undefined): ls.SignatureHelp | undefined;
44
- function signatureInformation(info: core.SignatureInfo): ls.SignatureInformation;
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.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
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.toLS = void 0;
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
- * A series of functions that can transform `@spyglassmc/core` types to `vscode-languageserver` types.
28
- *
29
- * Functions are named after types in `vscode-languageserver`.
30
- */
31
- var toLS;
32
- (function (toLS) {
33
- const ZeroPosition = { line: 0, character: 0 };
34
- const ZeroRange = { start: ZeroPosition, end: ZeroPosition };
35
- function color(color) {
36
- return ls.Color.create(...color);
37
- }
38
- toLS.color = color;
39
- function colorInformation(info, doc) {
40
- return ls.ColorInformation.create(range(info.range, doc), color(info.color));
41
- }
42
- toLS.colorInformation = colorInformation;
43
- function colorInformationArray(info, doc) {
44
- return info.map(i => colorInformation(i, doc));
45
- }
46
- toLS.colorInformationArray = colorInformationArray;
47
- function colorPresentation(presentation, doc) {
48
- const edit = ls.TextEdit.replace(range(presentation.range, doc), presentation.text);
49
- return ls.ColorPresentation.create(presentation.label, edit);
50
- }
51
- toLS.colorPresentation = colorPresentation;
52
- function colorPresentationArray(presentation, doc) {
53
- return presentation.map(p => colorPresentation(p, doc));
54
- }
55
- toLS.colorPresentationArray = colorPresentationArray;
56
- function diagnostic(error, doc) {
57
- const ans = ls.Diagnostic.create(range(error.range, doc), error.message, diagnosticSeverity(error.severity), undefined, 'spyglassmc');
58
- if (error.info?.deprecated) {
59
- (ans.tags ?? (ans.tags = []))?.push(ls.DiagnosticTag.Deprecated);
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
- toLS.inlayHint = inlayHint;
150
- function inlayHints(hints, doc) {
151
- return hints.map(h => inlayHint(h, doc));
152
- }
153
- toLS.inlayHints = inlayHints;
154
- function completionItem(completion, doc, requestedOffset, insertReplaceSupport) {
155
- const insertText = completion.insertText ?? completion.label;
156
- const canInsertReplace = insertReplaceSupport && ![core.CR, core.LF, core.CRLF].includes(insertText);
157
- const textEdit = canInsertReplace
158
- ? ls.InsertReplaceEdit.create(insertText,
159
- /* insert */ range(core.Range.create(completion.range.start, requestedOffset), doc),
160
- /* replace */ range(completion.range, doc))
161
- : ls.TextEdit.replace(range(completion.range, doc), insertText);
162
- const ans = {
163
- label: completion.label,
164
- kind: completion.kind,
165
- detail: completion.detail,
166
- documentation: completion.documentation,
167
- filterText: completion.filterText,
168
- sortText: completion.sortText,
169
- textEdit,
170
- insertTextFormat: node_1.InsertTextFormat.Snippet,
171
- insertTextMode: ls.InsertTextMode.adjustIndentation,
172
- ...completion.deprecated ? { tags: [ls.CompletionItemTag.Deprecated] } : {},
173
- };
174
- return ans;
175
- }
176
- toLS.completionItem = completionItem;
177
- function location(location) {
178
- return {
179
- uri: location.uri,
180
- range: location.posRange,
181
- };
182
- }
183
- toLS.location = location;
184
- function locationLink(locations, doc, linkSupport) {
185
- return locations?.locations
186
- ? linkSupport
187
- ? locations.locations.map(loc => ({
188
- originSelectionRange: range(locations.range, doc),
189
- targetUri: loc.uri,
190
- targetRange: loc.fullPosRange ?? loc.posRange ?? ZeroRange,
191
- targetSelectionRange: loc.posRange ?? ZeroRange,
192
- }))
193
- : (locations.locations).map(loc => location({ uri: loc.uri, posRange: loc.posRange ?? ZeroRange }))
194
- : undefined;
195
- }
196
- toLS.locationLink = locationLink;
197
- function markupContent(value) {
198
- return {
199
- kind: ls.MarkupKind.Markdown,
200
- value: value,
201
- };
202
- }
203
- toLS.markupContent = markupContent;
204
- function position(offset, doc) {
205
- return doc.positionAt(offset);
206
- }
207
- toLS.position = position;
208
- function range(range, doc) {
209
- return ls.Range.create(position(range.start, doc), position(range.end, doc));
210
- }
211
- toLS.range = range;
212
- function semanticTokenModifier(modifier) {
213
- return core.ColorTokenModifiers.indexOf(modifier);
214
- }
215
- toLS.semanticTokenModifier = semanticTokenModifier;
216
- function semanticTokenModifiers(modifiers = []) {
217
- let ans = 0;
218
- for (const modifier of modifiers) {
219
- ans += 1 << semanticTokenModifier(modifier);
220
- }
221
- return ans;
222
- }
223
- toLS.semanticTokenModifiers = semanticTokenModifiers;
224
- function semanticTokens(tokens, doc) {
225
- const builder = new ls.SemanticTokensBuilder();
226
- for (const token of tokens) {
227
- const pos = position(token.range.start, doc);
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, semanticTokenType(token.type), semanticTokenModifiers(token.modifiers));
236
+ builder.push(pos.line, pos.character, length, type, modifiers);
230
237
  }
231
- return builder.build();
232
- }
233
- toLS.semanticTokens = semanticTokens;
234
- function semanticTokensLegend() {
235
- const ans = {
236
- tokenTypes: core.ColorTokenTypes,
237
- tokenModifiers: core.ColorTokenModifiers,
238
- };
239
- return ans;
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
- toLS.parameterInformation = parameterInformation;
273
- function symbolInformation(symbol, symLoc, supportedKinds = []) {
274
- return {
275
- name: symbol.identifier,
276
- kind: symbolKind(symbol.category, symbol.subcategory, supportedKinds),
277
- location: location({ uri: symLoc.uri, posRange: symLoc.fullPosRange ?? symLoc.posRange ?? ZeroRange }),
278
- };
279
- }
280
- toLS.symbolInformation = symbolInformation;
281
- function symbolInformationArray(map = {}, query, supportedKinds = []) {
282
- return Object.values(map)
283
- .filter(s => s.identifier.includes(query))
284
- .map(s => [s, [...s.declaration ?? [], ...s.definition ?? [], ...s.implementation ?? [], ...s.typeDefinition ?? []][0]])
285
- .filter(([_s, l]) => !!l)
286
- .map(([s, l]) => symbolInformation(s, l, supportedKinds));
287
- }
288
- toLS.symbolInformationArray = symbolInformationArray;
289
- function symbolInformationArrayFromTable(table, query, supportedKinds = []) {
290
- return Object.values(table)
291
- .map(m => symbolInformationArray(m, query, supportedKinds))
292
- .flat();
293
- }
294
- toLS.symbolInformationArrayFromTable = symbolInformationArrayFromTable;
295
- function symbolKind(category, subcategory = '', supportedKinds = []) {
296
- const UltimateFallback = ls.SymbolKind.Variable;
297
- const getKind = (kind, fallback) => supportedKinds?.includes(kind) ? kind : fallback;
298
- if (core.ResourceLocationCategory.is(category)) {
299
- return ls.SymbolKind.Function;
300
- }
301
- if (category === 'nbtdoc') {
302
- const map = new Map([
303
- ['enum', ls.SymbolKind.Enum],
304
- ['enum_key', getKind(ls.SymbolKind.EnumMember, ls.SymbolKind.Field)],
305
- ['compound', getKind(ls.SymbolKind.Struct, ls.SymbolKind.Interface)],
306
- ['compound_key', ls.SymbolKind.Field],
307
- ['module', ls.SymbolKind.Module],
308
- ]);
309
- return map.get(subcategory) ?? UltimateFallback;
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
- ['attribute_modifier_uuid', ls.SymbolKind.Number],
313
- ['nbtdoc/description', ls.SymbolKind.Constructor],
314
- ['objective', ls.SymbolKind.Variable],
315
- ['score_holder', ls.SymbolKind.Class],
316
- ['tag', ls.SymbolKind.String],
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(category) ?? UltimateFallback;
320
- }
321
- toLS.symbolKind = symbolKind;
322
- function textEdit(range, text, doc) {
323
- return ls.TextEdit.replace(toLS.range(range, doc), text);
324
- }
325
- toLS.textEdit = textEdit;
326
- })(toLS = exports.toLS || (exports.toLS = {}));
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
@@ -1,4 +1,7 @@
1
1
  import type * as ls from 'vscode-languageserver/node';
2
+ export interface CustomInitializationOptions {
3
+ inDevelopmentMode?: boolean;
4
+ }
2
5
  export interface CustomServerCapabilities {
3
6
  dataHackPubify?: boolean;
4
7
  inlayHints?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spyglassmc/language-server",
3
- "version": "0.1.0",
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.0",
24
- "@spyglassmc/java-edition": "0.1.0",
25
- "@spyglassmc/locales": "0.1.0",
26
- "@spyglassmc/nbtdoc": "0.1.0"
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"