@spyglassmc/language-server 0.4.52 → 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 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
  });
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 0 /* core.ErrorSeverity.Hint */:
53
+ case core.ErrorSeverity.Hint:
54
54
  return ls.DiagnosticSeverity.Hint;
55
- case 1 /* core.ErrorSeverity.Information */:
55
+ case core.ErrorSeverity.Information:
56
56
  return ls.DiagnosticSeverity.Information;
57
- case 2 /* core.ErrorSeverity.Warning */:
57
+ case core.ErrorSeverity.Warning:
58
58
  return ls.DiagnosticSeverity.Warning;
59
- case 3 /* core.ErrorSeverity.Error */:
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.52",
3
+ "version": "0.4.53",
4
4
  "type": "module",
5
5
  "main": "lib/server.js",
6
6
  "types": "lib/server.d.ts",
@@ -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.40",
39
- "@spyglassmc/java-edition": "0.3.52",
40
- "@spyglassmc/locales": "0.3.20",
41
- "@spyglassmc/mcdoc": "0.3.44"
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"