Skip to content

Commit 1bcd707

Browse files
nrayburn-techautofix-ci[bot]
andauthoredOct 21, 2024··
fix(editor): Update config sent to language server (#6724)
Syncs up the options from the language server `Options` struct with the values that the extension supplies. I tend to avoid `toJSON` because it will be used by `JSON.stringify` when called and it's not well known. There's no reason that `LanguageServerConfig` and `Config` have to both exist, but I think two types is easier to understand. --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 41a6ad6 commit 1bcd707

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed
 

‎editors/vscode/client/config.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ export class ConfigService implements Config, IDisposable {
55
private static readonly _namespace = 'oxc';
66
private readonly _disposables: IDisposable[] = [];
77
private _inner: WorkspaceConfiguration;
8-
private _runTrigger: 'onSave' | 'onType';
8+
private _runTrigger: Trigger;
99
private _enable: boolean;
10-
private _trace: 'off' | 'messages' | 'verbose';
10+
private _trace: TraceLevel;
1111
private _configPath: string;
1212
private _binPath: string | undefined;
1313

@@ -30,10 +30,6 @@ export class ConfigService implements Config, IDisposable {
3030
this._disposables.push(disposeChangeListener);
3131
}
3232

33-
get rawConfig(): WorkspaceConfiguration {
34-
return this._inner;
35-
}
36-
3733
get runTrigger(): Trigger {
3834
return this._runTrigger;
3935
}
@@ -106,20 +102,24 @@ export class ConfigService implements Config, IDisposable {
106102
}
107103
}
108104

109-
public toJSON(): Config {
105+
public toLanguageServerConfig(): LanguageServerConfig {
110106
return {
111-
runTrigger: this.runTrigger,
107+
run: this.runTrigger,
112108
enable: this.enable,
113-
trace: this.trace,
114109
configPath: this.configPath,
115-
binPath: this.binPath,
116110
};
117111
}
118112
}
119113

120114
type Trigger = 'onSave' | 'onType';
121115
type TraceLevel = 'off' | 'messages' | 'verbose';
122116

117+
interface LanguageServerConfig {
118+
configPath: string;
119+
enable: boolean;
120+
run: Trigger;
121+
}
122+
123123
/**
124124
* See `"contributes.configuration"` in `package.json`
125125
*/

‎editors/vscode/client/extension.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ export async function activate(context: ExtensionContext) {
136136
// If the extension is launched in debug mode then the debug server options are used
137137
// Otherwise the run options are used
138138
// Options to control the language client
139-
let clientConfig: any = JSON.parse(JSON.stringify(config.rawConfig));
140139
let clientOptions: LanguageClientOptions = {
141140
// Register the server for plain text documents
142141
documentSelector: [
@@ -155,7 +154,7 @@ export async function activate(context: ExtensionContext) {
155154
fileEvents: workspace.createFileSystemWatcher('**/.clientrc'),
156155
},
157156
initializationOptions: {
158-
settings: clientConfig,
157+
settings: config.toLanguageServerConfig(),
159158
},
160159
outputChannel,
161160
traceOutputChannel,
@@ -200,7 +199,7 @@ export async function activate(context: ExtensionContext) {
200199

201200
myStatusBarItem.backgroundColor = bgColor;
202201
}
203-
updateStatsBar(clientConfig.enable);
202+
updateStatsBar(config.enable);
204203
client.start();
205204
}
206205

0 commit comments

Comments
 (0)
Please sign in to comment.