Skip to content

Commit a5109be

Browse files
committed
语言设置挪到服务器里
1 parent cdafefe commit a5109be

File tree

2 files changed

+45
-73
lines changed

2 files changed

+45
-73
lines changed

client/src/languageConfiguration.ts

Lines changed: 0 additions & 67 deletions
This file was deleted.

client/src/languageserver.ts

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as path from 'path';
22
import * as os from 'os';
33
import * as fs from 'fs';
44
import * as vscode from 'vscode';
5-
import { luaConfiguration } from './languageConfiguration';
65
import {
76
workspace as Workspace,
87
ExtensionContext,
@@ -134,8 +133,6 @@ class LuaClient extends Disposable {
134133
disposable.dispose();
135134
}
136135
});
137-
138-
this.disposables.push(vscode.languages.setLanguageConfiguration('lua', luaConfiguration));
139136
}
140137

141138
async start() {
@@ -150,11 +147,13 @@ class LuaClient extends Disposable {
150147
},
151148
initializationOptions: {
152149
changeConfiguration: true,
150+
statusBar: true,
153151
viewDocument: true,
154152
trustByClient: true,
155153
useSemanticByRange: true,
156154
codeLensViewReferences: true,
157155
fixIndents: true,
156+
languageConfiguration: true,
158157
},
159158
};
160159

@@ -193,6 +192,7 @@ class LuaClient extends Disposable {
193192
await this.client.start();
194193
this.onCommand();
195194
this.statusBar();
195+
this.languageConfiguration();
196196
}
197197

198198
private async getCommand(config: vscode.WorkspaceConfiguration) {
@@ -279,7 +279,7 @@ class LuaClient extends Disposable {
279279
this.dispose();
280280
}
281281

282-
statusBar() {
282+
private statusBar() {
283283
const client = this.client!;
284284
const bar = window.createStatusBarItem(vscode.StatusBarAlignment.Right);
285285
bar.text = "Lua";
@@ -309,7 +309,7 @@ class LuaClient extends Disposable {
309309
this.disposables.push(bar);
310310
}
311311

312-
onCommand() {
312+
private onCommand() {
313313
if (!this.client) {
314314
return;
315315
}
@@ -319,6 +319,45 @@ class LuaClient extends Disposable {
319319
})
320320
);
321321
}
322+
323+
private languageConfiguration() {
324+
if (!this.client) {
325+
return;
326+
}
327+
328+
function convertStringsToRegex(config: any): any {
329+
if (typeof config !== 'object' || config === null) {
330+
return config;
331+
}
332+
333+
for (const key in config) {
334+
if (config.hasOwnProperty(key)) {
335+
const value = config[key];
336+
337+
if (typeof value === 'object' && value !== null) {
338+
convertStringsToRegex(value);
339+
}
340+
341+
if (key === 'beforeText' || key === 'afterText') {
342+
if (typeof value === 'string') {
343+
config[key] = new RegExp(value);
344+
}
345+
}
346+
}
347+
}
348+
349+
return config;
350+
}
351+
352+
let configuration: Disposable | undefined;
353+
this.disposables.push(
354+
this.client.onNotification('$/languageConfiguration', (params) => {
355+
configuration?.dispose();
356+
configuration = vscode.languages.setLanguageConfiguration(params.id, convertStringsToRegex(params.configuration));
357+
this.disposables.push(configuration);
358+
})
359+
)
360+
}
322361
}
323362

324363
export function activate(context: ExtensionContext) {
@@ -348,7 +387,7 @@ export async function deactivate() {
348387
}
349388
return undefined;
350389
}
351-
390+
vscode.SyntaxTokenType.String
352391
export async function reportAPIDoc(params: unknown) {
353392
if (!defaultClient) {
354393
return;

0 commit comments

Comments
 (0)