@spyglassmc/language-server 0.3.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 +14 -20
- package/lib/util/toLS.d.ts +2 -2
- package/lib/util/toLS.js +55 -24
- 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,23 +65,17 @@ 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
|
});
|
|
75
72
|
service.project
|
|
76
|
-
.on('
|
|
73
|
+
.on('documentErrored', ({ errors, uri, version }) => {
|
|
77
74
|
connection.sendDiagnostics({
|
|
78
|
-
diagnostics: toLS.diagnostics(errors
|
|
79
|
-
uri:
|
|
80
|
-
version:
|
|
75
|
+
diagnostics: toLS.diagnostics(errors),
|
|
76
|
+
uri: uri,
|
|
77
|
+
version: version,
|
|
81
78
|
});
|
|
82
|
-
})
|
|
83
|
-
.on('documentRemoved', ({ uri }) => {
|
|
84
|
-
connection.sendDiagnostics({ uri, diagnostics: [] });
|
|
85
79
|
})
|
|
86
80
|
.on('ready', () => {
|
|
87
81
|
progressReporter?.done();
|
|
@@ -164,8 +158,7 @@ connection.onDidChangeTextDocument(({ contentChanges, textDocument: { uri, versi
|
|
|
164
158
|
connection.onDidCloseTextDocument(({ textDocument: { uri } }) => {
|
|
165
159
|
service.project.onDidClose(uri);
|
|
166
160
|
});
|
|
167
|
-
connection.workspace.onDidRenameFiles(({}) => {
|
|
168
|
-
});
|
|
161
|
+
connection.workspace.onDidRenameFiles(({}) => { });
|
|
169
162
|
connection.onColorPresentation(async ({ textDocument: { uri }, color, range }) => {
|
|
170
163
|
const docAndNode = await service.project.ensureClientManagedChecked(uri);
|
|
171
164
|
if (!docAndNode) {
|
|
@@ -192,7 +185,8 @@ connection.onCompletion(async ({ textDocument: { uri }, position, context }) =>
|
|
|
192
185
|
const { doc, node } = docAndNode;
|
|
193
186
|
const offset = toCore.offset(position, doc);
|
|
194
187
|
const items = service.complete(node, doc, offset, context?.triggerCharacter);
|
|
195
|
-
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));
|
|
196
190
|
});
|
|
197
191
|
connection.onRequest('spyglassmc/dataHackPubify', ({ initialism }) => {
|
|
198
192
|
return service.dataHackPubify(initialism);
|
|
@@ -224,7 +218,7 @@ connection.onImplementation(async ({ textDocument: { uri }, position }) => {
|
|
|
224
218
|
const ans = await service.getSymbolLocations(node, doc, toCore.offset(position, doc), ['implementation', 'definition']);
|
|
225
219
|
return toLS.locationLink(ans, doc, capabilities.textDocument?.implementation?.linkSupport);
|
|
226
220
|
});
|
|
227
|
-
connection.onReferences(async ({ textDocument: { uri }, position, context: { includeDeclaration } }) => {
|
|
221
|
+
connection.onReferences(async ({ textDocument: { uri }, position, context: { includeDeclaration }, }) => {
|
|
228
222
|
const docAndNode = await service.project.ensureClientManagedChecked(uri);
|
|
229
223
|
if (!docAndNode) {
|
|
230
224
|
return undefined;
|
|
@@ -257,7 +251,8 @@ connection.onDocumentSymbol(async ({ textDocument: { uri } }) => {
|
|
|
257
251
|
return undefined;
|
|
258
252
|
}
|
|
259
253
|
const { doc, node } = docAndNode;
|
|
260
|
-
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);
|
|
261
256
|
});
|
|
262
257
|
connection.onHover(async ({ textDocument: { uri }, position }) => {
|
|
263
258
|
const docAndNode = await service.project.ensureClientManagedChecked(uri);
|
|
@@ -268,7 +263,7 @@ connection.onHover(async ({ textDocument: { uri }, position }) => {
|
|
|
268
263
|
const ans = service.getHover(node, doc, toCore.offset(position, doc));
|
|
269
264
|
return ans ? toLS.hover(ans, doc) : undefined;
|
|
270
265
|
});
|
|
271
|
-
connection.onRequest('spyglassmc/inlayHints', async ({ textDocument: { uri }, range }) => {
|
|
266
|
+
connection.onRequest('spyglassmc/inlayHints', async ({ textDocument: { uri }, range, }) => {
|
|
272
267
|
const docAndNode = await service.project.ensureClientManagedChecked(uri);
|
|
273
268
|
if (!docAndNode) {
|
|
274
269
|
return [];
|
|
@@ -278,8 +273,7 @@ connection.onRequest('spyglassmc/inlayHints', async ({ textDocument: { uri }, ra
|
|
|
278
273
|
return toLS.inlayHints(hints, doc);
|
|
279
274
|
});
|
|
280
275
|
connection.onRequest('spyglassmc/resetProjectCache', async () => {
|
|
281
|
-
service.project.resetCache();
|
|
282
|
-
return service.project.restart();
|
|
276
|
+
return service.project.resetCache();
|
|
283
277
|
});
|
|
284
278
|
connection.onRequest('spyglassmc/showCacheRoot', async () => {
|
|
285
279
|
return service.project.showCacheRoot();
|
package/lib/util/toLS.d.ts
CHANGED
|
@@ -7,8 +7,8 @@ export declare function colorInformation(info: core.ColorInfo, doc: TextDocument
|
|
|
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.
|
|
11
|
-
export declare function diagnostics(errors: readonly core.
|
|
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
|
@@ -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
|
-
export function diagnostic(error
|
|
28
|
-
const ans = ls.Diagnostic.create(
|
|
27
|
+
export function diagnostic(error) {
|
|
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,15 +40,15 @@ export function diagnostic(error, doc) {
|
|
|
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
|
}));
|
|
45
47
|
}
|
|
46
48
|
return ans;
|
|
47
49
|
}
|
|
48
|
-
export function diagnostics(errors
|
|
49
|
-
return errors.map(e => diagnostic(e
|
|
50
|
+
export function diagnostics(errors) {
|
|
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,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
|
|
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
|
-
:
|
|
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
|
|
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
|
|
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({
|
|
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 => [
|
|
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.
|
|
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.
|
|
25
|
-
"@spyglassmc/java-edition": "0.3.
|
|
26
|
-
"@spyglassmc/locales": "0.3.
|
|
27
|
-
"@spyglassmc/mcdoc": "0.3.
|
|
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
|