@spyglassmc/language-server 0.4.0 → 0.4.2
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 +9 -11
- package/lib/util/toLS.js +54 -22
- package/package.json +6 -6
- /package/bin/{server → server.js} +0 -0
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
|
|
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
|
|
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
|
|
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
|
|
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 => [
|
|
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,11 +122,12 @@ 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;
|
|
115
|
-
const canInsertReplace = insertReplaceSupport &&
|
|
129
|
+
const canInsertReplace = insertReplaceSupport &&
|
|
130
|
+
![core.CR, core.LF, core.CRLF].includes(insertText);
|
|
116
131
|
const textEdit = canInsertReplace
|
|
117
132
|
? ls.InsertReplaceEdit.create(insertText,
|
|
118
133
|
/* insert */ range(core.Range.create(completion.range.start, requestedOffset), doc),
|
|
@@ -128,7 +143,9 @@ export function completionItem(completion, doc, requestedOffset, insertReplaceSu
|
|
|
128
143
|
textEdit,
|
|
129
144
|
insertTextFormat: InsertTextFormat.Snippet,
|
|
130
145
|
insertTextMode: ls.InsertTextMode.adjustIndentation,
|
|
131
|
-
...completion.deprecated
|
|
146
|
+
...(completion.deprecated
|
|
147
|
+
? { tags: [ls.CompletionItemTag.Deprecated] }
|
|
148
|
+
: {}),
|
|
132
149
|
};
|
|
133
150
|
return ans;
|
|
134
151
|
}
|
|
@@ -141,13 +158,13 @@ export function location(location) {
|
|
|
141
158
|
export function locationLink(locations, doc, linkSupport) {
|
|
142
159
|
return locations?.locations
|
|
143
160
|
? linkSupport
|
|
144
|
-
? locations.locations.map(loc => ({
|
|
161
|
+
? locations.locations.map((loc) => ({
|
|
145
162
|
originSelectionRange: range(locations.range, doc),
|
|
146
163
|
targetUri: loc.uri,
|
|
147
164
|
targetRange: loc.fullPosRange ?? loc.posRange ?? ZeroRange,
|
|
148
165
|
targetSelectionRange: loc.posRange ?? ZeroRange,
|
|
149
166
|
}))
|
|
150
|
-
:
|
|
167
|
+
: locations.locations.map((loc) => location({ uri: loc.uri, posRange: loc.posRange ?? ZeroRange }))
|
|
151
168
|
: undefined;
|
|
152
169
|
}
|
|
153
170
|
export function markupContent(value) {
|
|
@@ -221,33 +238,48 @@ export function signatureInformation(info) {
|
|
|
221
238
|
return {
|
|
222
239
|
label: info.label,
|
|
223
240
|
activeParameter: info.activeParameter,
|
|
224
|
-
documentation: info.documentation
|
|
241
|
+
documentation: info.documentation
|
|
242
|
+
? markupContent(info.documentation)
|
|
243
|
+
: undefined,
|
|
225
244
|
parameters: info.parameters.map(parameterInformation),
|
|
226
245
|
};
|
|
227
246
|
}
|
|
228
247
|
export function parameterInformation(info) {
|
|
229
248
|
return {
|
|
230
249
|
label: info.label,
|
|
231
|
-
documentation: info.documentation
|
|
250
|
+
documentation: info.documentation
|
|
251
|
+
? markupContent(info.documentation)
|
|
252
|
+
: undefined,
|
|
232
253
|
};
|
|
233
254
|
}
|
|
234
255
|
export function symbolInformation(symbol, symLoc, supportedKinds = []) {
|
|
235
256
|
return {
|
|
236
257
|
name: symbol.identifier,
|
|
237
258
|
kind: symbolKind(symbol.category, symbol.subcategory, supportedKinds),
|
|
238
|
-
location: location({
|
|
259
|
+
location: location({
|
|
260
|
+
uri: symLoc.uri,
|
|
261
|
+
posRange: symLoc.fullPosRange ?? symLoc.posRange ?? ZeroRange,
|
|
262
|
+
}),
|
|
239
263
|
};
|
|
240
264
|
}
|
|
241
265
|
export function symbolInformationArray(map = {}, query, supportedKinds = []) {
|
|
242
266
|
return Object.values(map)
|
|
243
|
-
.filter(s => s.identifier.includes(query))
|
|
244
|
-
.map(s => [
|
|
267
|
+
.filter((s) => s.identifier.includes(query))
|
|
268
|
+
.map((s) => [
|
|
269
|
+
s,
|
|
270
|
+
[
|
|
271
|
+
...(s.declaration ?? []),
|
|
272
|
+
...(s.definition ?? []),
|
|
273
|
+
...(s.implementation ?? []),
|
|
274
|
+
...(s.typeDefinition ?? []),
|
|
275
|
+
][0],
|
|
276
|
+
])
|
|
245
277
|
.filter(([_s, l]) => !!l)
|
|
246
278
|
.map(([s, l]) => symbolInformation(s, l, supportedKinds));
|
|
247
279
|
}
|
|
248
280
|
export function symbolInformationArrayFromTable(table, query, supportedKinds = []) {
|
|
249
281
|
return Object.values(table)
|
|
250
|
-
.map(m => symbolInformationArray(m, query, supportedKinds))
|
|
282
|
+
.map((m) => symbolInformationArray(m, query, supportedKinds))
|
|
251
283
|
.flat();
|
|
252
284
|
}
|
|
253
285
|
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.
|
|
3
|
+
"version": "0.4.2",
|
|
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.
|
|
25
|
-
"@spyglassmc/java-edition": "0.3.
|
|
26
|
-
"@spyglassmc/locales": "0.3.
|
|
27
|
-
"@spyglassmc/mcdoc": "0.3.
|
|
24
|
+
"@spyglassmc/core": "0.4.2",
|
|
25
|
+
"@spyglassmc/java-edition": "0.3.3",
|
|
26
|
+
"@spyglassmc/locales": "0.3.2",
|
|
27
|
+
"@spyglassmc/mcdoc": "0.3.3"
|
|
28
28
|
},
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public"
|
|
File without changes
|