@spyglassmc/language-server 0.4.51 → 0.4.53
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 +57 -15
- package/lib/util/toLS.js +4 -4
- package/package.json +6 -6
package/lib/server.js
CHANGED
|
@@ -30,6 +30,14 @@ const logger = {
|
|
|
30
30
|
warn: (msg, ...args) => connection.console.warn(util.format(msg, ...args)),
|
|
31
31
|
};
|
|
32
32
|
let service;
|
|
33
|
+
function buildSemanticTokensCapability() {
|
|
34
|
+
return {
|
|
35
|
+
documentSelector: toLS.documentSelector(service.project.meta),
|
|
36
|
+
legend: toLS.semanticTokensLegend(),
|
|
37
|
+
full: { delta: false },
|
|
38
|
+
range: true,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
33
41
|
connection.onInitialize(async (params) => {
|
|
34
42
|
const initializationOptions = params.initializationOptions;
|
|
35
43
|
logger.info(`[onInitialize] processId = ${JSON.stringify(params.processId)}`);
|
|
@@ -90,6 +98,11 @@ connection.onInitialize(async (params) => {
|
|
|
90
98
|
catch (e) {
|
|
91
99
|
logger.error('[new Service]', e);
|
|
92
100
|
}
|
|
101
|
+
let semanticTokensProvider = undefined;
|
|
102
|
+
if (!capabilities.textDocument?.semanticTokens?.dynamicRegistration) {
|
|
103
|
+
logger.info("[startDynamicSemanticTokensRegistration] LanguageClient didn't permit dynamic registration for semantic tokens. Registering semantic tokens statically instead...");
|
|
104
|
+
semanticTokensProvider = buildSemanticTokensCapability();
|
|
105
|
+
}
|
|
93
106
|
const customCapabilities = {
|
|
94
107
|
dataHackPubify: true,
|
|
95
108
|
resetProjectCache: true,
|
|
@@ -110,12 +123,7 @@ connection.onInitialize(async (params) => {
|
|
|
110
123
|
documentSymbolProvider: { label: 'Spyglass' },
|
|
111
124
|
hoverProvider: {},
|
|
112
125
|
inlayHintProvider: {},
|
|
113
|
-
semanticTokensProvider
|
|
114
|
-
documentSelector: toLS.documentSelector(service.project.meta),
|
|
115
|
-
legend: toLS.semanticTokensLegend(),
|
|
116
|
-
full: { delta: false },
|
|
117
|
-
range: true,
|
|
118
|
-
},
|
|
126
|
+
semanticTokensProvider,
|
|
119
127
|
signatureHelpProvider: { triggerCharacters: [' '] },
|
|
120
128
|
textDocumentSync: { change: ls.TextDocumentSyncKind.Incremental, openClose: true },
|
|
121
129
|
workspaceSymbolProvider: {},
|
|
@@ -133,6 +141,7 @@ connection.onInitialized(async () => {
|
|
|
133
141
|
if (capabilities.textDocument?.formatting?.dynamicRegistration) {
|
|
134
142
|
void connection.client.register(ls.DocumentFormattingRequest.type, { documentSelector: [{ language: 'mcdoc' }] });
|
|
135
143
|
}
|
|
144
|
+
startDynamicSemanticTokensRegistration();
|
|
136
145
|
await service.project.ready();
|
|
137
146
|
if (capabilities.workspace?.workspaceFolders) {
|
|
138
147
|
connection.workspace.onDidChangeWorkspaceFolders(async () => {
|
|
@@ -141,6 +150,39 @@ connection.onInitialized(async () => {
|
|
|
141
150
|
});
|
|
142
151
|
}
|
|
143
152
|
});
|
|
153
|
+
function startDynamicSemanticTokensRegistration() {
|
|
154
|
+
// If the client permits it, semantic tokens are registered dynamically, such that if they are disabled in the config, the language client
|
|
155
|
+
// knows that Spyglass won't be providing tokens instead of just receiving an empty tokens list.
|
|
156
|
+
// This could otherwise cause problems with other language servers if the client decides to override their semantic tokens
|
|
157
|
+
// with the empty tokens list provided by Spyglass.
|
|
158
|
+
if (!capabilities.textDocument?.semanticTokens?.dynamicRegistration) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
let dynamicSemanticTokensDiposable = undefined;
|
|
162
|
+
function registerDynamicSemanticTokens() {
|
|
163
|
+
if (dynamicSemanticTokensDiposable !== undefined) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
logger.info('[registerDynamicSemanticTokens] Registering dynamic semantic tokens');
|
|
167
|
+
dynamicSemanticTokensDiposable = connection.client.register(ls.SemanticTokensRegistrationType.type, buildSemanticTokensCapability());
|
|
168
|
+
}
|
|
169
|
+
function unregisterDynamicSemanticTokens() {
|
|
170
|
+
logger.info('[unregisterDynamicSemanticTokens] Unregistering dynamic semantic tokens');
|
|
171
|
+
void dynamicSemanticTokensDiposable?.then(disposable => disposable.dispose());
|
|
172
|
+
dynamicSemanticTokensDiposable = undefined;
|
|
173
|
+
}
|
|
174
|
+
if (service.project.config.env.feature.semanticColoring) {
|
|
175
|
+
registerDynamicSemanticTokens();
|
|
176
|
+
}
|
|
177
|
+
service.project.on('configChanged', config => {
|
|
178
|
+
if (config.env.feature.semanticColoring) {
|
|
179
|
+
registerDynamicSemanticTokens();
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
unregisterDynamicSemanticTokens();
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
}
|
|
144
186
|
connection.onDidOpenTextDocument(({ textDocument: { text, uri, version, languageId: languageID } }) => {
|
|
145
187
|
return service.project.onDidOpen(uri, languageID, version, text);
|
|
146
188
|
});
|
|
@@ -153,7 +195,7 @@ connection.onDidCloseTextDocument(({ textDocument: { uri } }) => {
|
|
|
153
195
|
connection.workspace.onDidRenameFiles(({}) => { });
|
|
154
196
|
connection.onCodeAction(async ({ textDocument: { uri }, range }) => {
|
|
155
197
|
const docAndNode = await service.project.ensureClientManagedChecked(uri);
|
|
156
|
-
if (!docAndNode) {
|
|
198
|
+
if (!docAndNode || !service.project.config.env.feature.codeActions) {
|
|
157
199
|
return undefined;
|
|
158
200
|
}
|
|
159
201
|
const { doc, node } = docAndNode;
|
|
@@ -171,7 +213,7 @@ connection.onColorPresentation(async ({ textDocument: { uri }, color, range }) =
|
|
|
171
213
|
});
|
|
172
214
|
connection.onDocumentColor(async ({ textDocument: { uri } }) => {
|
|
173
215
|
const docAndNode = await service.project.ensureClientManagedChecked(uri);
|
|
174
|
-
if (!docAndNode) {
|
|
216
|
+
if (!docAndNode || !service.project.config.env.feature.colors) {
|
|
175
217
|
return undefined;
|
|
176
218
|
}
|
|
177
219
|
const { doc, node } = docAndNode;
|
|
@@ -180,7 +222,7 @@ connection.onDocumentColor(async ({ textDocument: { uri } }) => {
|
|
|
180
222
|
});
|
|
181
223
|
connection.onCompletion(async ({ textDocument: { uri }, position, context }) => {
|
|
182
224
|
const docAndNode = await service.project.ensureClientManagedChecked(uri);
|
|
183
|
-
if (!docAndNode) {
|
|
225
|
+
if (!docAndNode || !service.project.config.env.feature.completions) {
|
|
184
226
|
return undefined;
|
|
185
227
|
}
|
|
186
228
|
const { doc, node } = docAndNode;
|
|
@@ -251,7 +293,7 @@ connection.onTypeDefinition(async ({ textDocument: { uri }, position }) => {
|
|
|
251
293
|
});
|
|
252
294
|
connection.onDocumentHighlight(async ({ textDocument: { uri }, position }) => {
|
|
253
295
|
const docAndNode = await service.project.ensureClientManagedChecked(uri);
|
|
254
|
-
if (!docAndNode) {
|
|
296
|
+
if (!docAndNode || !service.project.config.env.feature.documentHighlighting) {
|
|
255
297
|
return undefined;
|
|
256
298
|
}
|
|
257
299
|
const { doc, node } = docAndNode;
|
|
@@ -268,7 +310,7 @@ connection.onDocumentSymbol(async ({ textDocument: { uri } }) => {
|
|
|
268
310
|
});
|
|
269
311
|
connection.onHover(async ({ textDocument: { uri }, position }) => {
|
|
270
312
|
const docAndNode = await service.project.ensureClientManagedChecked(uri);
|
|
271
|
-
if (!docAndNode) {
|
|
313
|
+
if (!docAndNode || !service.project.config.env.feature.hover) {
|
|
272
314
|
return undefined;
|
|
273
315
|
}
|
|
274
316
|
const { doc, node } = docAndNode;
|
|
@@ -292,7 +334,7 @@ connection.onRequest('spyglassmc/showCacheRoot', async () => {
|
|
|
292
334
|
});
|
|
293
335
|
connection.languages.semanticTokens.on(async ({ textDocument: { uri } }) => {
|
|
294
336
|
const docAndNode = await service.project.ensureClientManagedChecked(uri);
|
|
295
|
-
if (!docAndNode) {
|
|
337
|
+
if (!docAndNode || !service.project.config.env.feature.semanticColoring) {
|
|
296
338
|
return { data: [] };
|
|
297
339
|
}
|
|
298
340
|
const { doc, node } = docAndNode;
|
|
@@ -301,7 +343,7 @@ connection.languages.semanticTokens.on(async ({ textDocument: { uri } }) => {
|
|
|
301
343
|
});
|
|
302
344
|
connection.languages.semanticTokens.onRange(async ({ textDocument: { uri }, range }) => {
|
|
303
345
|
const docAndNode = await service.project.ensureClientManagedChecked(uri);
|
|
304
|
-
if (!docAndNode) {
|
|
346
|
+
if (!docAndNode || !service.project.config.env.feature.semanticColoring) {
|
|
305
347
|
return { data: [] };
|
|
306
348
|
}
|
|
307
349
|
const { doc, node } = docAndNode;
|
|
@@ -310,7 +352,7 @@ connection.languages.semanticTokens.onRange(async ({ textDocument: { uri }, rang
|
|
|
310
352
|
});
|
|
311
353
|
connection.onSignatureHelp(async ({ textDocument: { uri }, position }) => {
|
|
312
354
|
const docAndNode = await service.project.ensureClientManagedChecked(uri);
|
|
313
|
-
if (!docAndNode) {
|
|
355
|
+
if (!docAndNode || !service.project.config.env.feature.signatures) {
|
|
314
356
|
return undefined;
|
|
315
357
|
}
|
|
316
358
|
const { doc, node } = docAndNode;
|
|
@@ -322,7 +364,7 @@ connection.onWorkspaceSymbol(({ query }) => {
|
|
|
322
364
|
});
|
|
323
365
|
connection.onDocumentFormatting(async ({ textDocument: { uri }, options }) => {
|
|
324
366
|
const docAndNode = await service.project.ensureClientManagedChecked(uri);
|
|
325
|
-
if (!docAndNode) {
|
|
367
|
+
if (!docAndNode || !service.project.config.env.feature.formatting) {
|
|
326
368
|
return undefined;
|
|
327
369
|
}
|
|
328
370
|
const { doc, node } = docAndNode;
|
package/lib/util/toLS.js
CHANGED
|
@@ -50,13 +50,13 @@ export function diagnostics(errors) {
|
|
|
50
50
|
}
|
|
51
51
|
export function diagnosticSeverity(severity) {
|
|
52
52
|
switch (severity) {
|
|
53
|
-
case
|
|
53
|
+
case core.ErrorSeverity.Hint:
|
|
54
54
|
return ls.DiagnosticSeverity.Hint;
|
|
55
|
-
case
|
|
55
|
+
case core.ErrorSeverity.Information:
|
|
56
56
|
return ls.DiagnosticSeverity.Information;
|
|
57
|
-
case
|
|
57
|
+
case core.ErrorSeverity.Warning:
|
|
58
58
|
return ls.DiagnosticSeverity.Warning;
|
|
59
|
-
case
|
|
59
|
+
case core.ErrorSeverity.Error:
|
|
60
60
|
return ls.DiagnosticSeverity.Error;
|
|
61
61
|
}
|
|
62
62
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spyglassmc/language-server",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.53",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "lib/server.js",
|
|
6
6
|
"types": "lib/server.d.ts",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
17
|
"release": "npm publish",
|
|
18
|
-
"release:dry": "npm publish --dry-run",
|
|
18
|
+
"release:dry": "npm publish --tag latest --dry-run",
|
|
19
19
|
"build": "wireit",
|
|
20
20
|
"build:dev": "wireit"
|
|
21
21
|
},
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"env-paths": "^2.2.1",
|
|
36
36
|
"vscode-languageserver": "^9.0.1",
|
|
37
37
|
"vscode-languageserver-textdocument": "^1.0.11",
|
|
38
|
-
"@spyglassmc/core": "0.4.
|
|
39
|
-
"@spyglassmc/java-edition": "0.3.
|
|
40
|
-
"@spyglassmc/locales": "0.3.
|
|
41
|
-
"@spyglassmc/mcdoc": "0.3.
|
|
38
|
+
"@spyglassmc/core": "0.4.41",
|
|
39
|
+
"@spyglassmc/java-edition": "0.3.53",
|
|
40
|
+
"@spyglassmc/locales": "0.3.21",
|
|
41
|
+
"@spyglassmc/mcdoc": "0.3.45"
|
|
42
42
|
},
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"access": "public"
|