@spyglassmc/language-server 0.1.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/server CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- require('../lib/server.js')
2
+ import '../lib/server.js'
package/lib/server.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from './util/types';
1
+ export * from './util/types.js';
2
2
  //# sourceMappingURL=server.d.ts.map
package/lib/server.js CHANGED
@@ -1,55 +1,28 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = 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);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
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
- };
25
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
- };
28
- var __importDefault = (this && this.__importDefault) || function (mod) {
29
- return (mod && mod.__esModule) ? mod : { "default": mod };
30
- };
31
- Object.defineProperty(exports, "__esModule", { value: true });
32
- const core = __importStar(require("@spyglassmc/core"));
33
- const je = __importStar(require("@spyglassmc/java-edition"));
34
- const locales = __importStar(require("@spyglassmc/locales"));
35
- const mcdoc = __importStar(require("@spyglassmc/mcdoc"));
36
- const env_paths_1 = __importDefault(require("env-paths"));
37
- const util = __importStar(require("util"));
38
- const ls = __importStar(require("vscode-languageserver/node"));
39
- const util_1 = require("./util");
40
- __exportStar(require("./util/types"), exports);
1
+ import * as core from '@spyglassmc/core';
2
+ import { fileUtil } from '@spyglassmc/core';
3
+ import { NodeJsExternals } from '@spyglassmc/core/lib/nodejs.js';
4
+ import * as je from '@spyglassmc/java-edition';
5
+ import * as locales from '@spyglassmc/locales';
6
+ import * as mcdoc from '@spyglassmc/mcdoc';
7
+ import envPaths from 'env-paths';
8
+ import url from 'url';
9
+ import * as util from 'util';
10
+ import * as ls from 'vscode-languageserver/node.js';
11
+ import { toCore, toLS } from './util/index.js';
12
+ export * from './util/types.js';
41
13
  if (process.argv.length === 2) {
42
14
  // When the server is launched from the cmd script, the process arguments
43
15
  // are wiped. I don't know why it happens, but this is what it is.
44
16
  // Therefore, we push a '--stdio' if the argument list is too short.
45
17
  process.argv.push('--stdio');
46
18
  }
47
- const { cache: cacheRoot } = (0, env_paths_1.default)('spyglassmc');
19
+ const { cache: cacheRoot } = envPaths('spyglassmc');
48
20
  const connection = ls.createConnection();
49
21
  let capabilities;
50
22
  let workspaceFolders;
51
23
  let hasShutdown = false;
52
24
  let progressReporter;
25
+ const externals = NodeJsExternals;
53
26
  const logger = {
54
27
  error: (msg, ...args) => connection.console.error(util.format(msg, ...args)),
55
28
  info: (msg, ...args) => connection.console.info(util.format(msg, ...args)),
@@ -80,31 +53,32 @@ connection.onInitialize(async (params) => {
80
53
  }
81
54
  try {
82
55
  service = new core.Service({
83
- cacheRoot,
84
- initializers: [
85
- mcdoc.initialize,
86
- je.initialize,
87
- ],
88
- isDebugging: false,
56
+ isDebugging: initializationOptions?.inDevelopmentMode && false,
89
57
  logger,
90
58
  profilers: new core.ProfilerFactory(logger, [
91
59
  'cache#load',
92
60
  'cache#save',
93
61
  'project#init',
94
62
  'project#ready',
63
+ 'project#ready#bind',
95
64
  ]),
96
- projectPath: core.fileUtil.fileUriToPath(workspaceFolders[0].uri),
65
+ project: {
66
+ cacheRoot: fileUtil.ensureEndingSlash(url.pathToFileURL(cacheRoot).toString()),
67
+ externals,
68
+ initializers: [
69
+ mcdoc.initialize,
70
+ je.initialize,
71
+ ],
72
+ projectRoot: core.fileUtil.ensureEndingSlash(workspaceFolders[0].uri),
73
+ },
97
74
  });
98
75
  service.project
99
- .on('documentErrorred', ({ doc, errors }) => {
76
+ .on('documentErrored', ({ errors, uri, version }) => {
100
77
  connection.sendDiagnostics({
101
- diagnostics: util_1.toLS.diagnostics(errors, doc),
102
- uri: doc.uri,
103
- version: doc.version,
78
+ diagnostics: toLS.diagnostics(errors),
79
+ uri: uri,
80
+ version: version,
104
81
  });
105
- })
106
- .on('documentRemoved', ({ uri }) => {
107
- connection.sendDiagnostics({ uri, diagnostics: [] });
108
82
  })
109
83
  .on('ready', () => {
110
84
  progressReporter?.done();
@@ -141,8 +115,8 @@ connection.onInitialize(async (params) => {
141
115
  },
142
116
  hoverProvider: {},
143
117
  semanticTokensProvider: {
144
- documentSelector: util_1.toLS.documentSelector(service.project.meta),
145
- legend: util_1.toLS.semanticTokensLegend(),
118
+ documentSelector: toLS.documentSelector(service.project.meta),
119
+ legend: toLS.semanticTokensLegend(),
146
120
  full: { delta: false },
147
121
  range: true,
148
122
  },
@@ -179,10 +153,10 @@ connection.onInitialized(async () => {
179
153
  }
180
154
  });
181
155
  connection.onDidOpenTextDocument(({ textDocument: { text, uri, version, languageId: languageID } }) => {
182
- service.project.onDidOpen(uri, languageID, version, text);
156
+ return service.project.onDidOpen(uri, languageID, version, text);
183
157
  });
184
158
  connection.onDidChangeTextDocument(({ contentChanges, textDocument: { uri, version } }) => {
185
- service.project.onDidChange(uri, contentChanges, version);
159
+ return service.project.onDidChange(uri, contentChanges, version);
186
160
  });
187
161
  connection.onDidCloseTextDocument(({ textDocument: { uri } }) => {
188
162
  service.project.onDidClose(uri);
@@ -190,155 +164,154 @@ connection.onDidCloseTextDocument(({ textDocument: { uri } }) => {
190
164
  connection.workspace.onDidRenameFiles(({}) => {
191
165
  });
192
166
  connection.onColorPresentation(async ({ textDocument: { uri }, color, range }) => {
193
- const docAndNode = await service.project.ensureParsedAndCheckedOnlyWhenReady(uri);
167
+ const docAndNode = await service.project.ensureClientManagedChecked(uri);
194
168
  if (!docAndNode) {
195
169
  return undefined;
196
170
  }
197
171
  const { doc, node } = docAndNode;
198
- const presentation = service.getColorPresentation(node, doc, util_1.toCore.range(range, doc), util_1.toCore.color(color));
199
- return util_1.toLS.colorPresentationArray(presentation, doc);
172
+ const presentation = service.getColorPresentation(node, doc, toCore.range(range, doc), toCore.color(color));
173
+ return toLS.colorPresentationArray(presentation, doc);
200
174
  });
201
175
  connection.onDocumentColor(async ({ textDocument: { uri } }) => {
202
- const docAndNode = await service.project.ensureParsedAndCheckedOnlyWhenReady(uri);
176
+ const docAndNode = await service.project.ensureClientManagedChecked(uri);
203
177
  if (!docAndNode) {
204
178
  return undefined;
205
179
  }
206
180
  const { doc, node } = docAndNode;
207
181
  const info = service.getColorInfo(node, doc);
208
- return util_1.toLS.colorInformationArray(info, doc);
182
+ return toLS.colorInformationArray(info, doc);
209
183
  });
210
184
  connection.onCompletion(async ({ textDocument: { uri }, position, context }) => {
211
- const docAndNode = await service.project.ensureParsedAndCheckedOnlyWhenReady(uri);
185
+ const docAndNode = await service.project.ensureClientManagedChecked(uri);
212
186
  if (!docAndNode) {
213
187
  return undefined;
214
188
  }
215
189
  const { doc, node } = docAndNode;
216
- const offset = util_1.toCore.offset(position, doc);
190
+ const offset = toCore.offset(position, doc);
217
191
  const items = service.complete(node, doc, offset, context?.triggerCharacter);
218
- return items.map(item => util_1.toLS.completionItem(item, doc, offset, capabilities.textDocument?.completion?.completionItem?.insertReplaceSupport));
192
+ return items.map(item => toLS.completionItem(item, doc, offset, capabilities.textDocument?.completion?.completionItem?.insertReplaceSupport));
219
193
  });
220
194
  connection.onRequest('spyglassmc/dataHackPubify', ({ initialism }) => {
221
195
  return service.dataHackPubify(initialism);
222
196
  });
223
197
  connection.onDeclaration(async ({ textDocument: { uri }, position }) => {
224
- const docAndNode = await service.project.ensureParsedAndCheckedOnlyWhenReady(uri);
198
+ const docAndNode = await service.project.ensureClientManagedChecked(uri);
225
199
  if (!docAndNode) {
226
200
  return undefined;
227
201
  }
228
202
  const { doc, node } = docAndNode;
229
- const ans = await service.getSymbolLocations(node, doc, util_1.toCore.offset(position, doc), ['declaration', 'definition']);
230
- return util_1.toLS.locationLink(ans, doc, capabilities.textDocument?.declaration?.linkSupport);
203
+ const ans = await service.getSymbolLocations(node, doc, toCore.offset(position, doc), ['declaration', 'definition']);
204
+ return toLS.locationLink(ans, doc, capabilities.textDocument?.declaration?.linkSupport);
231
205
  });
232
206
  connection.onDefinition(async ({ textDocument: { uri }, position }) => {
233
- const docAndNode = await service.project.ensureParsedAndCheckedOnlyWhenReady(uri);
207
+ const docAndNode = await service.project.ensureClientManagedChecked(uri);
234
208
  if (!docAndNode) {
235
209
  return undefined;
236
210
  }
237
211
  const { doc, node } = docAndNode;
238
- const ans = await service.getSymbolLocations(node, doc, util_1.toCore.offset(position, doc), ['definition', 'declaration', 'implementation', 'typeDefinition']);
239
- return util_1.toLS.locationLink(ans, doc, capabilities.textDocument?.definition?.linkSupport);
212
+ const ans = await service.getSymbolLocations(node, doc, toCore.offset(position, doc), ['definition', 'declaration', 'implementation', 'typeDefinition']);
213
+ return toLS.locationLink(ans, doc, capabilities.textDocument?.definition?.linkSupport);
240
214
  });
241
215
  connection.onImplementation(async ({ textDocument: { uri }, position }) => {
242
- const docAndNode = await service.project.ensureParsedAndCheckedOnlyWhenReady(uri);
216
+ const docAndNode = await service.project.ensureClientManagedChecked(uri);
243
217
  if (!docAndNode) {
244
218
  return undefined;
245
219
  }
246
220
  const { doc, node } = docAndNode;
247
- const ans = await service.getSymbolLocations(node, doc, util_1.toCore.offset(position, doc), ['implementation', 'definition']);
248
- return util_1.toLS.locationLink(ans, doc, capabilities.textDocument?.implementation?.linkSupport);
221
+ const ans = await service.getSymbolLocations(node, doc, toCore.offset(position, doc), ['implementation', 'definition']);
222
+ return toLS.locationLink(ans, doc, capabilities.textDocument?.implementation?.linkSupport);
249
223
  });
250
224
  connection.onReferences(async ({ textDocument: { uri }, position, context: { includeDeclaration } }) => {
251
- const docAndNode = await service.project.ensureParsedAndCheckedOnlyWhenReady(uri);
225
+ const docAndNode = await service.project.ensureClientManagedChecked(uri);
252
226
  if (!docAndNode) {
253
227
  return undefined;
254
228
  }
255
229
  const { doc, node } = docAndNode;
256
- const ans = await service.getSymbolLocations(node, doc, util_1.toCore.offset(position, doc), includeDeclaration ? undefined : ['reference']);
257
- return util_1.toLS.locationLink(ans, doc, false);
230
+ const ans = await service.getSymbolLocations(node, doc, toCore.offset(position, doc), includeDeclaration ? undefined : ['reference']);
231
+ return toLS.locationLink(ans, doc, false);
258
232
  });
259
233
  connection.onTypeDefinition(async ({ textDocument: { uri }, position }) => {
260
- const docAndNode = await service.project.ensureParsedAndCheckedOnlyWhenReady(uri);
234
+ const docAndNode = await service.project.ensureClientManagedChecked(uri);
261
235
  if (!docAndNode) {
262
236
  return undefined;
263
237
  }
264
238
  const { doc, node } = docAndNode;
265
- const ans = await service.getSymbolLocations(node, doc, util_1.toCore.offset(position, doc), ['typeDefinition']);
266
- return util_1.toLS.locationLink(ans, doc, capabilities.textDocument?.typeDefinition?.linkSupport);
239
+ const ans = await service.getSymbolLocations(node, doc, toCore.offset(position, doc), ['typeDefinition']);
240
+ return toLS.locationLink(ans, doc, capabilities.textDocument?.typeDefinition?.linkSupport);
267
241
  });
268
242
  connection.onDocumentHighlight(async ({ textDocument: { uri }, position }) => {
269
- const docAndNode = await service.project.ensureParsedAndCheckedOnlyWhenReady(uri);
243
+ const docAndNode = await service.project.ensureClientManagedChecked(uri);
270
244
  if (!docAndNode) {
271
245
  return undefined;
272
246
  }
273
247
  const { doc, node } = docAndNode;
274
- const ans = await service.getSymbolLocations(node, doc, util_1.toCore.offset(position, doc), undefined, true);
275
- return util_1.toLS.documentHighlight(ans);
248
+ const ans = await service.getSymbolLocations(node, doc, toCore.offset(position, doc), undefined, true);
249
+ return toLS.documentHighlight(ans);
276
250
  });
277
251
  connection.onDocumentSymbol(async ({ textDocument: { uri } }) => {
278
- const docAndNode = await service.project.ensureParsedAndCheckedOnlyWhenReady(uri);
252
+ const docAndNode = await service.project.ensureClientManagedChecked(uri);
279
253
  if (!docAndNode) {
280
254
  return undefined;
281
255
  }
282
256
  const { doc, node } = docAndNode;
283
- return util_1.toLS.documentSymbolsFromTables([service.project.symbols.global, ...core.AstNode.getLocalsToLeaves(node)], doc, capabilities.textDocument?.documentSymbol?.hierarchicalDocumentSymbolSupport, capabilities.textDocument?.documentSymbol?.symbolKind?.valueSet);
257
+ return toLS.documentSymbolsFromTables([service.project.symbols.global, ...core.AstNode.getLocalsToLeaves(node)], doc, capabilities.textDocument?.documentSymbol?.hierarchicalDocumentSymbolSupport, capabilities.textDocument?.documentSymbol?.symbolKind?.valueSet);
284
258
  });
285
259
  connection.onHover(async ({ textDocument: { uri }, position }) => {
286
- const docAndNode = await service.project.ensureParsedAndCheckedOnlyWhenReady(uri);
260
+ const docAndNode = await service.project.ensureClientManagedChecked(uri);
287
261
  if (!docAndNode) {
288
262
  return undefined;
289
263
  }
290
264
  const { doc, node } = docAndNode;
291
- const ans = service.getHover(node, doc, util_1.toCore.offset(position, doc));
292
- return ans ? util_1.toLS.hover(ans, doc) : undefined;
265
+ const ans = service.getHover(node, doc, toCore.offset(position, doc));
266
+ return ans ? toLS.hover(ans, doc) : undefined;
293
267
  });
294
268
  connection.onRequest('spyglassmc/inlayHints', async ({ textDocument: { uri }, range }) => {
295
- const docAndNode = await service.project.ensureParsedAndCheckedOnlyWhenReady(uri);
269
+ const docAndNode = await service.project.ensureClientManagedChecked(uri);
296
270
  if (!docAndNode) {
297
271
  return [];
298
272
  }
299
273
  const { doc, node } = docAndNode;
300
- const hints = service.getInlayHints(node, doc, util_1.toCore.range(range, doc));
301
- return util_1.toLS.inlayHints(hints, doc);
274
+ const hints = service.getInlayHints(node, doc, toCore.range(range, doc));
275
+ return toLS.inlayHints(hints, doc);
302
276
  });
303
277
  connection.onRequest('spyglassmc/resetProjectCache', async () => {
304
- service.project.resetCache();
305
- return service.project.restart();
278
+ return service.project.resetCache();
306
279
  });
307
280
  connection.onRequest('spyglassmc/showCacheRoot', async () => {
308
281
  return service.project.showCacheRoot();
309
282
  });
310
283
  connection.languages.semanticTokens.on(async ({ textDocument: { uri } }) => {
311
- const docAndNode = await service.project.ensureParsedAndCheckedOnlyWhenReady(uri);
284
+ const docAndNode = await service.project.ensureClientManagedChecked(uri);
312
285
  if (!docAndNode) {
313
286
  return { data: [] };
314
287
  }
315
288
  const { doc, node } = docAndNode;
316
289
  const tokens = service.colorize(node, doc);
317
- return util_1.toLS.semanticTokens(tokens, doc, capabilities.textDocument?.semanticTokens?.multilineTokenSupport);
290
+ return toLS.semanticTokens(tokens, doc, capabilities.textDocument?.semanticTokens?.multilineTokenSupport);
318
291
  });
319
292
  connection.languages.semanticTokens.onRange(async ({ textDocument: { uri }, range }) => {
320
- const docAndNode = await service.project.ensureParsedAndCheckedOnlyWhenReady(uri);
293
+ const docAndNode = await service.project.ensureClientManagedChecked(uri);
321
294
  if (!docAndNode) {
322
295
  return { data: [] };
323
296
  }
324
297
  const { doc, node } = docAndNode;
325
- const tokens = service.colorize(node, doc, util_1.toCore.range(range, doc));
326
- return util_1.toLS.semanticTokens(tokens, doc, capabilities.textDocument?.semanticTokens?.multilineTokenSupport);
298
+ const tokens = service.colorize(node, doc, toCore.range(range, doc));
299
+ return toLS.semanticTokens(tokens, doc, capabilities.textDocument?.semanticTokens?.multilineTokenSupport);
327
300
  });
328
301
  connection.onSignatureHelp(async ({ textDocument: { uri }, position }) => {
329
- const docAndNode = await service.project.ensureParsedAndCheckedOnlyWhenReady(uri);
302
+ const docAndNode = await service.project.ensureClientManagedChecked(uri);
330
303
  if (!docAndNode) {
331
304
  return undefined;
332
305
  }
333
306
  const { doc, node } = docAndNode;
334
- const help = service.getSignatureHelp(node, doc, util_1.toCore.offset(position, doc));
335
- return util_1.toLS.signatureHelp(help);
307
+ const help = service.getSignatureHelp(node, doc, toCore.offset(position, doc));
308
+ return toLS.signatureHelp(help);
336
309
  });
337
310
  connection.onWorkspaceSymbol(({ query }) => {
338
- return util_1.toLS.symbolInformationArrayFromTable(service.project.symbols.global, query, capabilities.textDocument?.documentSymbol?.symbolKind?.valueSet);
311
+ return toLS.symbolInformationArrayFromTable(service.project.symbols.global, query, capabilities.textDocument?.documentSymbol?.symbolKind?.valueSet);
339
312
  });
340
313
  connection.onDocumentFormatting(async ({ textDocument: { uri }, options }) => {
341
- const docAndNode = await service.project.ensureParsedAndCheckedOnlyWhenReady(uri);
314
+ const docAndNode = await service.project.ensureClientManagedChecked(uri);
342
315
  if (!docAndNode) {
343
316
  return undefined;
344
317
  }
@@ -347,7 +320,7 @@ connection.onDocumentFormatting(async ({ textDocument: { uri }, options }) => {
347
320
  if (options.insertFinalNewline && text.charAt(text.length - 1) !== '\n') {
348
321
  text += '\n';
349
322
  }
350
- return [util_1.toLS.textEdit(node.range, text, doc)];
323
+ return [toLS.textEdit(node.range, text, doc)];
351
324
  });
352
325
  connection.onShutdown(async () => {
353
326
  await service.project.close();
@@ -1,4 +1,4 @@
1
- export * as toCore from './toCore';
2
- export * as toLS from './toLS';
3
- export * from './types';
1
+ export * as toCore from './toCore.js';
2
+ export * as toLS from './toLS.js';
3
+ export * from './types.js';
4
4
  //# sourceMappingURL=index.d.ts.map
package/lib/util/index.js CHANGED
@@ -1,33 +1,4 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = 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);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
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
- };
25
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.toLS = exports.toCore = void 0;
30
- exports.toCore = __importStar(require("./toCore"));
31
- exports.toLS = __importStar(require("./toLS"));
32
- __exportStar(require("./types"), exports);
1
+ export * as toCore from './toCore.js';
2
+ export * as toLS from './toLS.js';
3
+ export * from './types.js';
33
4
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,6 @@
1
1
  import * as core from '@spyglassmc/core';
2
2
  import type { TextDocument } from 'vscode-languageserver-textdocument';
3
- import type * as ls from 'vscode-languageserver/node';
3
+ import type * as ls from 'vscode-languageserver/node.js';
4
4
  export declare function offset(position: ls.Position, doc: TextDocument): number;
5
5
  export declare function range(range: ls.Range, doc: TextDocument): core.Range;
6
6
  export declare function color(color: ls.Color): core.Color;
@@ -1,45 +1,16 @@
1
- "use strict";
2
1
  /*
3
2
  * A series of functions that can transform `vscode-languageserver` types to `@spyglassmc/core` types.
4
3
  *
5
4
  * Functions are named after types in `@spyglassmc/core`.
6
5
  */
7
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
- if (k2 === undefined) k2 = 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);
14
- }) : (function(o, m, k, k2) {
15
- if (k2 === undefined) k2 = k;
16
- o[k2] = m[k];
17
- }));
18
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
- Object.defineProperty(o, "default", { enumerable: true, value: v });
20
- }) : function(o, v) {
21
- o["default"] = v;
22
- });
23
- var __importStar = (this && this.__importStar) || function (mod) {
24
- if (mod && mod.__esModule) return mod;
25
- var result = {};
26
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
27
- __setModuleDefault(result, mod);
28
- return result;
29
- };
30
- Object.defineProperty(exports, "__esModule", { value: true });
31
- exports.color = exports.range = exports.offset = void 0;
32
- const core = __importStar(require("@spyglassmc/core"));
33
- function offset(position, doc) {
6
+ import * as core from '@spyglassmc/core';
7
+ export function offset(position, doc) {
34
8
  return doc.offsetAt(position);
35
9
  }
36
- exports.offset = offset;
37
- function range(range, doc) {
10
+ export function range(range, doc) {
38
11
  return core.Range.create(offset(range.start, doc), offset(range.end, doc));
39
12
  }
40
- exports.range = range;
41
- function color(color) {
13
+ export function color(color) {
42
14
  return [color.red, color.green, color.blue, color.alpha];
43
15
  }
44
- exports.color = color;
45
16
  //# sourceMappingURL=toCore.js.map
@@ -1,14 +1,14 @@
1
1
  import * as core from '@spyglassmc/core';
2
2
  import type { TextDocument } from 'vscode-languageserver-textdocument';
3
- import * as ls from 'vscode-languageserver/node';
4
- import type { MyLspInlayHint } from './types';
3
+ import * as ls from 'vscode-languageserver/node.js';
4
+ import type { MyLspInlayHint } from './types.js';
5
5
  export declare function color(color: core.Color): ls.Color;
6
6
  export declare function colorInformation(info: core.ColorInfo, doc: TextDocument): ls.ColorInformation;
7
7
  export declare function colorInformationArray(info: core.ColorInfo[], doc: TextDocument): ls.ColorInformation[];
8
8
  export declare function colorPresentation(presentation: core.ColorPresentation, doc: TextDocument): ls.ColorPresentation;
9
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[];
10
+ export declare function diagnostic(error: core.PosRangeLanguageError): ls.Diagnostic;
11
+ export declare function diagnostics(errors: readonly core.PosRangeLanguageError[]): ls.Diagnostic[];
12
12
  export declare function diagnosticSeverity(severity: core.ErrorSeverity): ls.DiagnosticSeverity;
13
13
  export declare function documentHighlight(locations: core.SymbolLocations | undefined): ls.DocumentHighlight[] | undefined;
14
14
  export declare function documentSelector(meta: core.MetaRegistry): ls.DocumentSelector;
package/lib/util/toLS.js CHANGED
@@ -1,67 +1,36 @@
1
- "use strict";
2
1
  /*
3
2
  * A series of functions that can transform `@spyglassmc/core` types to `vscode-languageserver` types.
4
3
  *
5
4
  * Functions are named after types in `vscode-languageserver`.
6
5
  */
7
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
- if (k2 === undefined) k2 = 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);
14
- }) : (function(o, m, k, k2) {
15
- if (k2 === undefined) k2 = k;
16
- o[k2] = m[k];
17
- }));
18
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
- Object.defineProperty(o, "default", { enumerable: true, value: v });
20
- }) : function(o, v) {
21
- o["default"] = v;
22
- });
23
- var __importStar = (this && this.__importStar) || function (mod) {
24
- if (mod && mod.__esModule) return mod;
25
- var result = {};
26
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
27
- __setModuleDefault(result, mod);
28
- return result;
29
- };
30
- Object.defineProperty(exports, "__esModule", { value: true });
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;
32
- const core = __importStar(require("@spyglassmc/core"));
33
- const ls = __importStar(require("vscode-languageserver/node"));
34
- const node_1 = require("vscode-languageserver/node");
6
+ import * as core from '@spyglassmc/core';
7
+ import * as ls from 'vscode-languageserver/node.js';
8
+ import { InsertTextFormat } from 'vscode-languageserver/node.js';
35
9
  const ZeroPosition = { line: 0, character: 0 };
36
10
  const ZeroRange = { start: ZeroPosition, end: ZeroPosition };
37
- function color(color) {
11
+ export function color(color) {
38
12
  return ls.Color.create(...color);
39
13
  }
40
- exports.color = color;
41
- function colorInformation(info, doc) {
14
+ export function colorInformation(info, doc) {
42
15
  return ls.ColorInformation.create(range(info.range, doc), color(info.color));
43
16
  }
44
- exports.colorInformation = colorInformation;
45
- function colorInformationArray(info, doc) {
17
+ export function colorInformationArray(info, doc) {
46
18
  return info.map(i => colorInformation(i, doc));
47
19
  }
48
- exports.colorInformationArray = colorInformationArray;
49
- function colorPresentation(presentation, doc) {
20
+ export function colorPresentation(presentation, doc) {
50
21
  const edit = ls.TextEdit.replace(range(presentation.range, doc), presentation.text);
51
22
  return ls.ColorPresentation.create(presentation.label, edit);
52
23
  }
53
- exports.colorPresentation = colorPresentation;
54
- function colorPresentationArray(presentation, doc) {
24
+ export function colorPresentationArray(presentation, doc) {
55
25
  return presentation.map(p => colorPresentation(p, doc));
56
26
  }
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');
27
+ export function diagnostic(error) {
28
+ const ans = ls.Diagnostic.create(error.posRange, error.message, diagnosticSeverity(error.severity), undefined, 'spyglassmc');
60
29
  if (error.info?.deprecated) {
61
- (ans.tags ?? (ans.tags = []))?.push(ls.DiagnosticTag.Deprecated);
30
+ (ans.tags ??= [])?.push(ls.DiagnosticTag.Deprecated);
62
31
  }
63
32
  if (error.info?.unnecessary) {
64
- (ans.tags ?? (ans.tags = []))?.push(ls.DiagnosticTag.Unnecessary);
33
+ (ans.tags ??= [])?.push(ls.DiagnosticTag.Unnecessary);
65
34
  }
66
35
  if (error.info?.codeAction) {
67
36
  ans.data = {
@@ -76,12 +45,10 @@ function diagnostic(error, doc) {
76
45
  }
77
46
  return ans;
78
47
  }
79
- exports.diagnostic = diagnostic;
80
- function diagnostics(errors, doc) {
81
- return errors.map(e => diagnostic(e, doc));
48
+ export function diagnostics(errors) {
49
+ return errors.map(e => diagnostic(e));
82
50
  }
83
- exports.diagnostics = diagnostics;
84
- function diagnosticSeverity(severity) {
51
+ export function diagnosticSeverity(severity) {
85
52
  switch (severity) {
86
53
  case 0 /* core.ErrorSeverity.Hint */:
87
54
  return ls.DiagnosticSeverity.Hint;
@@ -93,19 +60,16 @@ function diagnosticSeverity(severity) {
93
60
  return ls.DiagnosticSeverity.Error;
94
61
  }
95
62
  }
96
- exports.diagnosticSeverity = diagnosticSeverity;
97
- function documentHighlight(locations) {
63
+ export function documentHighlight(locations) {
98
64
  return locations?.locations
99
65
  ?.filter(loc => loc.posRange)
100
66
  ?.map(loc => ({ range: loc.posRange }));
101
67
  }
102
- exports.documentHighlight = documentHighlight;
103
- function documentSelector(meta) {
68
+ export function documentSelector(meta) {
104
69
  const ans = meta.getLanguages().map(id => ({ language: id }));
105
70
  return ans;
106
71
  }
107
- exports.documentSelector = documentSelector;
108
- function documentSymbol(symbol, symLoc, doc, hierarchicalSupport, supportedKinds = []) {
72
+ export function documentSymbol(symbol, symLoc, doc, hierarchicalSupport, supportedKinds = []) {
109
73
  return {
110
74
  name: symbol.identifier,
111
75
  kind: symbolKind(symbol.category, symbol.subcategory, supportedKinds),
@@ -114,46 +78,39 @@ function documentSymbol(symbol, symLoc, doc, hierarchicalSupport, supportedKinds
114
78
  children: hierarchicalSupport ? documentSymbols(symbol.members, doc, hierarchicalSupport, supportedKinds) : undefined,
115
79
  };
116
80
  }
117
- exports.documentSymbol = documentSymbol;
118
- function documentSymbols(map = {}, doc, hierarchicalSupport, supportedKinds = []) {
81
+ export function documentSymbols(map = {}, doc, hierarchicalSupport, supportedKinds = []) {
119
82
  return Object.values(map)
120
83
  .map(s => [s, [...s.declaration ?? [], ...s.definition ?? [], ...s.implementation ?? [], ...s.typeDefinition ?? []].find(l => l.uri === doc.uri)])
121
84
  .filter(([_s, l]) => !!l)
122
85
  .map(([s, l]) => documentSymbol(s, l, doc, hierarchicalSupport, supportedKinds));
123
86
  }
124
- exports.documentSymbols = documentSymbols;
125
- function documentSymbolsFromTable(table, doc, hierarchicalSupport, supportedKinds = []) {
87
+ export function documentSymbolsFromTable(table, doc, hierarchicalSupport, supportedKinds = []) {
126
88
  return Object.values(table)
127
89
  .map(m => documentSymbols(m, doc, hierarchicalSupport, supportedKinds))
128
90
  .flat();
129
91
  }
130
- exports.documentSymbolsFromTable = documentSymbolsFromTable;
131
- function documentSymbolsFromTables(tables, doc, hierarchicalSupport, supportedKinds = []) {
92
+ export function documentSymbolsFromTables(tables, doc, hierarchicalSupport, supportedKinds = []) {
132
93
  return tables
133
94
  .map(t => documentSymbolsFromTable(t, doc, hierarchicalSupport, supportedKinds))
134
95
  .flat();
135
96
  }
136
- exports.documentSymbolsFromTables = documentSymbolsFromTables;
137
- function hover(hover, doc) {
97
+ export function hover(hover, doc) {
138
98
  const ans = {
139
99
  contents: markupContent(hover.markdown),
140
100
  range: range(hover.range, doc),
141
101
  };
142
102
  return ans;
143
103
  }
144
- exports.hover = hover;
145
- function inlayHint(hint, doc) {
104
+ export function inlayHint(hint, doc) {
146
105
  return {
147
106
  position: doc.positionAt(hint.offset),
148
107
  text: hint.text,
149
108
  };
150
109
  }
151
- exports.inlayHint = inlayHint;
152
- function inlayHints(hints, doc) {
110
+ export function inlayHints(hints, doc) {
153
111
  return hints.map(h => inlayHint(h, doc));
154
112
  }
155
- exports.inlayHints = inlayHints;
156
- function completionItem(completion, doc, requestedOffset, insertReplaceSupport) {
113
+ export function completionItem(completion, doc, requestedOffset, insertReplaceSupport) {
157
114
  const insertText = completion.insertText ?? completion.label;
158
115
  const canInsertReplace = insertReplaceSupport && ![core.CR, core.LF, core.CRLF].includes(insertText);
159
116
  const textEdit = canInsertReplace
@@ -169,21 +126,19 @@ function completionItem(completion, doc, requestedOffset, insertReplaceSupport)
169
126
  filterText: completion.filterText,
170
127
  sortText: completion.sortText,
171
128
  textEdit,
172
- insertTextFormat: node_1.InsertTextFormat.Snippet,
129
+ insertTextFormat: InsertTextFormat.Snippet,
173
130
  insertTextMode: ls.InsertTextMode.adjustIndentation,
174
131
  ...completion.deprecated ? { tags: [ls.CompletionItemTag.Deprecated] } : {},
175
132
  };
176
133
  return ans;
177
134
  }
178
- exports.completionItem = completionItem;
179
- function location(location) {
135
+ export function location(location) {
180
136
  return {
181
137
  uri: location.uri,
182
138
  range: location.posRange,
183
139
  };
184
140
  }
185
- exports.location = location;
186
- function locationLink(locations, doc, linkSupport) {
141
+ export function locationLink(locations, doc, linkSupport) {
187
142
  return locations?.locations
188
143
  ? linkSupport
189
144
  ? locations.locations.map(loc => ({
@@ -195,36 +150,30 @@ function locationLink(locations, doc, linkSupport) {
195
150
  : (locations.locations).map(loc => location({ uri: loc.uri, posRange: loc.posRange ?? ZeroRange }))
196
151
  : undefined;
197
152
  }
198
- exports.locationLink = locationLink;
199
- function markupContent(value) {
153
+ export function markupContent(value) {
200
154
  return {
201
155
  kind: ls.MarkupKind.Markdown,
202
156
  value: value,
203
157
  };
204
158
  }
205
- exports.markupContent = markupContent;
206
- function position(offset, doc) {
159
+ export function position(offset, doc) {
207
160
  return doc.positionAt(offset);
208
161
  }
209
- exports.position = position;
210
- function range(range, doc) {
162
+ export function range(range, doc) {
211
163
  return ls.Range.create(position(range.start, doc), position(range.end, doc));
212
164
  }
213
- exports.range = range;
214
- function semanticTokenModifier(modifier) {
165
+ export function semanticTokenModifier(modifier) {
215
166
  return core.ColorTokenModifiers.indexOf(modifier);
216
167
  }
217
- exports.semanticTokenModifier = semanticTokenModifier;
218
- function semanticTokenModifiers(modifiers = []) {
168
+ export function semanticTokenModifiers(modifiers = []) {
219
169
  let ans = 0;
220
170
  for (const modifier of modifiers) {
221
171
  ans += 1 << semanticTokenModifier(modifier);
222
172
  }
223
173
  return ans;
224
174
  }
225
- exports.semanticTokenModifiers = semanticTokenModifiers;
226
175
  const MaxCharacterNumber = 2147483647;
227
- function semanticTokens(tokens, doc, multilineSupport) {
176
+ export function semanticTokens(tokens, doc, multilineSupport) {
228
177
  const builder = new ls.SemanticTokensBuilder();
229
178
  for (const token of tokens) {
230
179
  const pos = position(token.range.start, doc);
@@ -248,20 +197,17 @@ function semanticTokens(tokens, doc, multilineSupport) {
248
197
  }
249
198
  return builder.build();
250
199
  }
251
- exports.semanticTokens = semanticTokens;
252
- function semanticTokensLegend() {
200
+ export function semanticTokensLegend() {
253
201
  const ans = {
254
202
  tokenTypes: core.ColorTokenTypes,
255
203
  tokenModifiers: core.ColorTokenModifiers,
256
204
  };
257
205
  return ans;
258
206
  }
259
- exports.semanticTokensLegend = semanticTokensLegend;
260
- function semanticTokenType(type) {
207
+ export function semanticTokenType(type) {
261
208
  return core.ColorTokenTypes.indexOf(type);
262
209
  }
263
- exports.semanticTokenType = semanticTokenType;
264
- function signatureHelp(help) {
210
+ export function signatureHelp(help) {
265
211
  if (!help || help.signatures.length === 0) {
266
212
  return undefined;
267
213
  }
@@ -271,8 +217,7 @@ function signatureHelp(help) {
271
217
  activeSignature: help.activeSignature,
272
218
  };
273
219
  }
274
- exports.signatureHelp = signatureHelp;
275
- function signatureInformation(info) {
220
+ export function signatureInformation(info) {
276
221
  return {
277
222
  label: info.label,
278
223
  activeParameter: info.activeParameter,
@@ -280,37 +225,32 @@ function signatureInformation(info) {
280
225
  parameters: info.parameters.map(parameterInformation),
281
226
  };
282
227
  }
283
- exports.signatureInformation = signatureInformation;
284
- function parameterInformation(info) {
228
+ export function parameterInformation(info) {
285
229
  return {
286
230
  label: info.label,
287
231
  documentation: info.documentation ? markupContent(info.documentation) : undefined,
288
232
  };
289
233
  }
290
- exports.parameterInformation = parameterInformation;
291
- function symbolInformation(symbol, symLoc, supportedKinds = []) {
234
+ export function symbolInformation(symbol, symLoc, supportedKinds = []) {
292
235
  return {
293
236
  name: symbol.identifier,
294
237
  kind: symbolKind(symbol.category, symbol.subcategory, supportedKinds),
295
238
  location: location({ uri: symLoc.uri, posRange: symLoc.fullPosRange ?? symLoc.posRange ?? ZeroRange }),
296
239
  };
297
240
  }
298
- exports.symbolInformation = symbolInformation;
299
- function symbolInformationArray(map = {}, query, supportedKinds = []) {
241
+ export function symbolInformationArray(map = {}, query, supportedKinds = []) {
300
242
  return Object.values(map)
301
243
  .filter(s => s.identifier.includes(query))
302
244
  .map(s => [s, [...s.declaration ?? [], ...s.definition ?? [], ...s.implementation ?? [], ...s.typeDefinition ?? []][0]])
303
245
  .filter(([_s, l]) => !!l)
304
246
  .map(([s, l]) => symbolInformation(s, l, supportedKinds));
305
247
  }
306
- exports.symbolInformationArray = symbolInformationArray;
307
- function symbolInformationArrayFromTable(table, query, supportedKinds = []) {
248
+ export function symbolInformationArrayFromTable(table, query, supportedKinds = []) {
308
249
  return Object.values(table)
309
250
  .map(m => symbolInformationArray(m, query, supportedKinds))
310
251
  .flat();
311
252
  }
312
- exports.symbolInformationArrayFromTable = symbolInformationArrayFromTable;
313
- function symbolKind(category, subcategory = '', supportedKinds = []) {
253
+ export function symbolKind(category, subcategory = '', supportedKinds = []) {
314
254
  const UltimateFallback = ls.SymbolKind.Variable;
315
255
  const getKind = (kind, fallback) => supportedKinds?.includes(kind) ? kind : fallback;
316
256
  if (core.ResourceLocationCategory.is(category)) {
@@ -336,9 +276,7 @@ function symbolKind(category, subcategory = '', supportedKinds = []) {
336
276
  ]);
337
277
  return map.get(category) ?? UltimateFallback;
338
278
  }
339
- exports.symbolKind = symbolKind;
340
- function textEdit(editRange, text, doc) {
279
+ export function textEdit(editRange, text, doc) {
341
280
  return ls.TextEdit.replace(range(editRange, doc), text);
342
281
  }
343
- exports.textEdit = textEdit;
344
282
  //# sourceMappingURL=toLS.js.map
@@ -1,4 +1,4 @@
1
- import type * as ls from 'vscode-languageserver/node';
1
+ import type * as ls from 'vscode-languageserver/node.js';
2
2
  export interface CustomInitializationOptions {
3
3
  inDevelopmentMode?: boolean;
4
4
  }
package/lib/util/types.js CHANGED
@@ -1,3 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
3
2
  //# sourceMappingURL=types.js.map
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@spyglassmc/language-server",
3
- "version": "0.1.3",
3
+ "version": "0.4.0",
4
+ "type": "module",
4
5
  "main": "lib/server.js",
5
6
  "types": "lib/server.d.ts",
6
7
  "author": "SPGoding",
@@ -20,10 +21,10 @@
20
21
  "env-paths": "^2.2.1",
21
22
  "vscode-languageserver": "^7.0.0",
22
23
  "vscode-languageserver-textdocument": "^1.0.1",
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"
24
+ "@spyglassmc/core": "0.4.0",
25
+ "@spyglassmc/java-edition": "0.3.1",
26
+ "@spyglassmc/locales": "0.3.0",
27
+ "@spyglassmc/mcdoc": "0.3.1"
27
28
  },
28
29
  "publishConfig": {
29
30
  "access": "public"