@spyglassmc/language-server 0.4.0 → 0.4.1

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
@@ -38,7 +38,7 @@ connection.onInitialize(async (params) => {
38
38
  capabilities = params.capabilities;
39
39
  workspaceFolders = params.workspaceFolders ?? [];
40
40
  if (initializationOptions?.inDevelopmentMode) {
41
- await new Promise(resolve => setTimeout(resolve, 3000));
41
+ await new Promise((resolve) => setTimeout(resolve, 3000));
42
42
  logger.warn('Delayed 3 seconds manually. If you see this in production, it means SPGoding messed up.');
43
43
  }
44
44
  if (params.workDoneToken) {
@@ -65,10 +65,7 @@ connection.onInitialize(async (params) => {
65
65
  project: {
66
66
  cacheRoot: fileUtil.ensureEndingSlash(url.pathToFileURL(cacheRoot).toString()),
67
67
  externals,
68
- initializers: [
69
- mcdoc.initialize,
70
- je.initialize,
71
- ],
68
+ initializers: [mcdoc.initialize, je.initialize],
72
69
  projectRoot: core.fileUtil.ensureEndingSlash(workspaceFolders[0].uri),
73
70
  },
74
71
  });
@@ -161,8 +158,7 @@ connection.onDidChangeTextDocument(({ contentChanges, textDocument: { uri, versi
161
158
  connection.onDidCloseTextDocument(({ textDocument: { uri } }) => {
162
159
  service.project.onDidClose(uri);
163
160
  });
164
- connection.workspace.onDidRenameFiles(({}) => {
165
- });
161
+ connection.workspace.onDidRenameFiles(({}) => { });
166
162
  connection.onColorPresentation(async ({ textDocument: { uri }, color, range }) => {
167
163
  const docAndNode = await service.project.ensureClientManagedChecked(uri);
168
164
  if (!docAndNode) {
@@ -189,7 +185,8 @@ connection.onCompletion(async ({ textDocument: { uri }, position, context }) =>
189
185
  const { doc, node } = docAndNode;
190
186
  const offset = toCore.offset(position, doc);
191
187
  const items = service.complete(node, doc, offset, context?.triggerCharacter);
192
- return items.map(item => toLS.completionItem(item, doc, offset, capabilities.textDocument?.completion?.completionItem?.insertReplaceSupport));
188
+ return items.map((item) => toLS.completionItem(item, doc, offset, capabilities.textDocument?.completion?.completionItem
189
+ ?.insertReplaceSupport));
193
190
  });
194
191
  connection.onRequest('spyglassmc/dataHackPubify', ({ initialism }) => {
195
192
  return service.dataHackPubify(initialism);
@@ -221,7 +218,7 @@ connection.onImplementation(async ({ textDocument: { uri }, position }) => {
221
218
  const ans = await service.getSymbolLocations(node, doc, toCore.offset(position, doc), ['implementation', 'definition']);
222
219
  return toLS.locationLink(ans, doc, capabilities.textDocument?.implementation?.linkSupport);
223
220
  });
224
- connection.onReferences(async ({ textDocument: { uri }, position, context: { includeDeclaration } }) => {
221
+ connection.onReferences(async ({ textDocument: { uri }, position, context: { includeDeclaration }, }) => {
225
222
  const docAndNode = await service.project.ensureClientManagedChecked(uri);
226
223
  if (!docAndNode) {
227
224
  return undefined;
@@ -254,7 +251,8 @@ connection.onDocumentSymbol(async ({ textDocument: { uri } }) => {
254
251
  return undefined;
255
252
  }
256
253
  const { doc, node } = docAndNode;
257
- return toLS.documentSymbolsFromTables([service.project.symbols.global, ...core.AstNode.getLocalsToLeaves(node)], doc, capabilities.textDocument?.documentSymbol?.hierarchicalDocumentSymbolSupport, capabilities.textDocument?.documentSymbol?.symbolKind?.valueSet);
254
+ return toLS.documentSymbolsFromTables([service.project.symbols.global, ...core.AstNode.getLocalsToLeaves(node)], doc, capabilities.textDocument?.documentSymbol
255
+ ?.hierarchicalDocumentSymbolSupport, capabilities.textDocument?.documentSymbol?.symbolKind?.valueSet);
258
256
  });
259
257
  connection.onHover(async ({ textDocument: { uri }, position }) => {
260
258
  const docAndNode = await service.project.ensureClientManagedChecked(uri);
@@ -265,7 +263,7 @@ connection.onHover(async ({ textDocument: { uri }, position }) => {
265
263
  const ans = service.getHover(node, doc, toCore.offset(position, doc));
266
264
  return ans ? toLS.hover(ans, doc) : undefined;
267
265
  });
268
- connection.onRequest('spyglassmc/inlayHints', async ({ textDocument: { uri }, range }) => {
266
+ connection.onRequest('spyglassmc/inlayHints', async ({ textDocument: { uri }, range, }) => {
269
267
  const docAndNode = await service.project.ensureClientManagedChecked(uri);
270
268
  if (!docAndNode) {
271
269
  return [];
package/lib/util/toLS.js CHANGED
@@ -15,21 +15,23 @@ export function colorInformation(info, doc) {
15
15
  return ls.ColorInformation.create(range(info.range, doc), color(info.color));
16
16
  }
17
17
  export function colorInformationArray(info, doc) {
18
- return info.map(i => colorInformation(i, doc));
18
+ return info.map((i) => colorInformation(i, doc));
19
19
  }
20
20
  export function colorPresentation(presentation, doc) {
21
21
  const edit = ls.TextEdit.replace(range(presentation.range, doc), presentation.text);
22
22
  return ls.ColorPresentation.create(presentation.label, edit);
23
23
  }
24
24
  export function colorPresentationArray(presentation, doc) {
25
- return presentation.map(p => colorPresentation(p, doc));
25
+ return presentation.map((p) => colorPresentation(p, doc));
26
26
  }
27
27
  export function diagnostic(error) {
28
28
  const ans = ls.Diagnostic.create(error.posRange, error.message, diagnosticSeverity(error.severity), undefined, 'spyglassmc');
29
29
  if (error.info?.deprecated) {
30
+ ;
30
31
  (ans.tags ??= [])?.push(ls.DiagnosticTag.Deprecated);
31
32
  }
32
33
  if (error.info?.unnecessary) {
34
+ ;
33
35
  (ans.tags ??= [])?.push(ls.DiagnosticTag.Unnecessary);
34
36
  }
35
37
  if (error.info?.codeAction) {
@@ -38,7 +40,7 @@ export function diagnostic(error) {
38
40
  };
39
41
  }
40
42
  if (error.info?.related) {
41
- ans.relatedInformation = error.info?.related.map(v => ({
43
+ ans.relatedInformation = error.info?.related.map((v) => ({
42
44
  location: location(v.location),
43
45
  message: v.message,
44
46
  }));
@@ -46,7 +48,7 @@ export function diagnostic(error) {
46
48
  return ans;
47
49
  }
48
50
  export function diagnostics(errors) {
49
- return errors.map(e => diagnostic(e));
51
+ return errors.map((e) => diagnostic(e));
50
52
  }
51
53
  export function diagnosticSeverity(severity) {
52
54
  switch (severity) {
@@ -62,11 +64,13 @@ export function diagnosticSeverity(severity) {
62
64
  }
63
65
  export function documentHighlight(locations) {
64
66
  return locations?.locations
65
- ?.filter(loc => loc.posRange)
66
- ?.map(loc => ({ range: loc.posRange }));
67
+ ?.filter((loc) => loc.posRange)
68
+ ?.map((loc) => ({ range: loc.posRange }));
67
69
  }
68
70
  export function documentSelector(meta) {
69
- const ans = meta.getLanguages().map(id => ({ language: id }));
71
+ const ans = meta
72
+ .getLanguages()
73
+ .map((id) => ({ language: id }));
70
74
  return ans;
71
75
  }
72
76
  export function documentSymbol(symbol, symLoc, doc, hierarchicalSupport, supportedKinds = []) {
@@ -75,23 +79,33 @@ export function documentSymbol(symbol, symLoc, doc, hierarchicalSupport, support
75
79
  kind: symbolKind(symbol.category, symbol.subcategory, supportedKinds),
76
80
  range: symLoc.fullPosRange ?? symLoc.posRange ?? ZeroRange,
77
81
  selectionRange: symLoc.posRange ?? ZeroRange,
78
- children: hierarchicalSupport ? documentSymbols(symbol.members, doc, hierarchicalSupport, supportedKinds) : undefined,
82
+ children: hierarchicalSupport
83
+ ? documentSymbols(symbol.members, doc, hierarchicalSupport, supportedKinds)
84
+ : undefined,
79
85
  };
80
86
  }
81
87
  export function documentSymbols(map = {}, doc, hierarchicalSupport, supportedKinds = []) {
82
88
  return Object.values(map)
83
- .map(s => [s, [...s.declaration ?? [], ...s.definition ?? [], ...s.implementation ?? [], ...s.typeDefinition ?? []].find(l => l.uri === doc.uri)])
89
+ .map((s) => [
90
+ s,
91
+ [
92
+ ...(s.declaration ?? []),
93
+ ...(s.definition ?? []),
94
+ ...(s.implementation ?? []),
95
+ ...(s.typeDefinition ?? []),
96
+ ].find((l) => l.uri === doc.uri),
97
+ ])
84
98
  .filter(([_s, l]) => !!l)
85
99
  .map(([s, l]) => documentSymbol(s, l, doc, hierarchicalSupport, supportedKinds));
86
100
  }
87
101
  export function documentSymbolsFromTable(table, doc, hierarchicalSupport, supportedKinds = []) {
88
102
  return Object.values(table)
89
- .map(m => documentSymbols(m, doc, hierarchicalSupport, supportedKinds))
103
+ .map((m) => documentSymbols(m, doc, hierarchicalSupport, supportedKinds))
90
104
  .flat();
91
105
  }
92
106
  export function documentSymbolsFromTables(tables, doc, hierarchicalSupport, supportedKinds = []) {
93
107
  return tables
94
- .map(t => documentSymbolsFromTable(t, doc, hierarchicalSupport, supportedKinds))
108
+ .map((t) => documentSymbolsFromTable(t, doc, hierarchicalSupport, supportedKinds))
95
109
  .flat();
96
110
  }
97
111
  export function hover(hover, doc) {
@@ -108,7 +122,7 @@ export function inlayHint(hint, doc) {
108
122
  };
109
123
  }
110
124
  export function inlayHints(hints, doc) {
111
- return hints.map(h => inlayHint(h, doc));
125
+ return hints.map((h) => inlayHint(h, doc));
112
126
  }
113
127
  export function completionItem(completion, doc, requestedOffset, insertReplaceSupport) {
114
128
  const insertText = completion.insertText ?? completion.label;
@@ -128,7 +142,9 @@ export function completionItem(completion, doc, requestedOffset, insertReplaceSu
128
142
  textEdit,
129
143
  insertTextFormat: InsertTextFormat.Snippet,
130
144
  insertTextMode: ls.InsertTextMode.adjustIndentation,
131
- ...completion.deprecated ? { tags: [ls.CompletionItemTag.Deprecated] } : {},
145
+ ...(completion.deprecated
146
+ ? { tags: [ls.CompletionItemTag.Deprecated] }
147
+ : {}),
132
148
  };
133
149
  return ans;
134
150
  }
@@ -141,13 +157,13 @@ export function location(location) {
141
157
  export function locationLink(locations, doc, linkSupport) {
142
158
  return locations?.locations
143
159
  ? linkSupport
144
- ? locations.locations.map(loc => ({
160
+ ? locations.locations.map((loc) => ({
145
161
  originSelectionRange: range(locations.range, doc),
146
162
  targetUri: loc.uri,
147
163
  targetRange: loc.fullPosRange ?? loc.posRange ?? ZeroRange,
148
164
  targetSelectionRange: loc.posRange ?? ZeroRange,
149
165
  }))
150
- : (locations.locations).map(loc => location({ uri: loc.uri, posRange: loc.posRange ?? ZeroRange }))
166
+ : locations.locations.map((loc) => location({ uri: loc.uri, posRange: loc.posRange ?? ZeroRange }))
151
167
  : undefined;
152
168
  }
153
169
  export function markupContent(value) {
@@ -221,33 +237,48 @@ export function signatureInformation(info) {
221
237
  return {
222
238
  label: info.label,
223
239
  activeParameter: info.activeParameter,
224
- documentation: info.documentation ? markupContent(info.documentation) : undefined,
240
+ documentation: info.documentation
241
+ ? markupContent(info.documentation)
242
+ : undefined,
225
243
  parameters: info.parameters.map(parameterInformation),
226
244
  };
227
245
  }
228
246
  export function parameterInformation(info) {
229
247
  return {
230
248
  label: info.label,
231
- documentation: info.documentation ? markupContent(info.documentation) : undefined,
249
+ documentation: info.documentation
250
+ ? markupContent(info.documentation)
251
+ : undefined,
232
252
  };
233
253
  }
234
254
  export function symbolInformation(symbol, symLoc, supportedKinds = []) {
235
255
  return {
236
256
  name: symbol.identifier,
237
257
  kind: symbolKind(symbol.category, symbol.subcategory, supportedKinds),
238
- location: location({ uri: symLoc.uri, posRange: symLoc.fullPosRange ?? symLoc.posRange ?? ZeroRange }),
258
+ location: location({
259
+ uri: symLoc.uri,
260
+ posRange: symLoc.fullPosRange ?? symLoc.posRange ?? ZeroRange,
261
+ }),
239
262
  };
240
263
  }
241
264
  export function symbolInformationArray(map = {}, query, supportedKinds = []) {
242
265
  return Object.values(map)
243
- .filter(s => s.identifier.includes(query))
244
- .map(s => [s, [...s.declaration ?? [], ...s.definition ?? [], ...s.implementation ?? [], ...s.typeDefinition ?? []][0]])
266
+ .filter((s) => s.identifier.includes(query))
267
+ .map((s) => [
268
+ s,
269
+ [
270
+ ...(s.declaration ?? []),
271
+ ...(s.definition ?? []),
272
+ ...(s.implementation ?? []),
273
+ ...(s.typeDefinition ?? []),
274
+ ][0],
275
+ ])
245
276
  .filter(([_s, l]) => !!l)
246
277
  .map(([s, l]) => symbolInformation(s, l, supportedKinds));
247
278
  }
248
279
  export function symbolInformationArrayFromTable(table, query, supportedKinds = []) {
249
280
  return Object.values(table)
250
- .map(m => symbolInformationArray(m, query, supportedKinds))
281
+ .map((m) => symbolInformationArray(m, query, supportedKinds))
251
282
  .flat();
252
283
  }
253
284
  export function symbolKind(category, subcategory = '', supportedKinds = []) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spyglassmc/language-server",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "type": "module",
5
5
  "main": "lib/server.js",
6
6
  "types": "lib/server.d.ts",
@@ -11,7 +11,7 @@
11
11
  "test": "test"
12
12
  },
13
13
  "bin": {
14
- "spyglassmc-language-server": "./bin/server"
14
+ "spyglassmc-language-server": "./bin/server.js"
15
15
  },
16
16
  "scripts": {
17
17
  "release": "npm publish",
@@ -21,10 +21,10 @@
21
21
  "env-paths": "^2.2.1",
22
22
  "vscode-languageserver": "^7.0.0",
23
23
  "vscode-languageserver-textdocument": "^1.0.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"
24
+ "@spyglassmc/core": "0.4.1",
25
+ "@spyglassmc/java-edition": "0.3.2",
26
+ "@spyglassmc/locales": "0.3.1",
27
+ "@spyglassmc/mcdoc": "0.3.2"
28
28
  },
29
29
  "publishConfig": {
30
30
  "access": "public"
File without changes