Skip to content

Commit

Permalink
fix(editor): Update config sent to language server (#6724)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
nrayburn-tech and autofix-ci[bot] authored Oct 21, 2024
1 parent 41a6ad6 commit 1bcd707
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
20 changes: 10 additions & 10 deletions editors/vscode/client/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export class ConfigService implements Config, IDisposable {
private static readonly _namespace = 'oxc';
private readonly _disposables: IDisposable[] = [];
private _inner: WorkspaceConfiguration;
private _runTrigger: 'onSave' | 'onType';
private _runTrigger: Trigger;
private _enable: boolean;
private _trace: 'off' | 'messages' | 'verbose';
private _trace: TraceLevel;
private _configPath: string;
private _binPath: string | undefined;

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

get rawConfig(): WorkspaceConfiguration {
return this._inner;
}

get runTrigger(): Trigger {
return this._runTrigger;
}
Expand Down Expand Up @@ -106,20 +102,24 @@ export class ConfigService implements Config, IDisposable {
}
}

public toJSON(): Config {
public toLanguageServerConfig(): LanguageServerConfig {
return {
runTrigger: this.runTrigger,
run: this.runTrigger,
enable: this.enable,
trace: this.trace,
configPath: this.configPath,
binPath: this.binPath,
};
}
}

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

interface LanguageServerConfig {
configPath: string;
enable: boolean;
run: Trigger;
}

/**
* See `"contributes.configuration"` in `package.json`
*/
Expand Down
5 changes: 2 additions & 3 deletions editors/vscode/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ export async function activate(context: ExtensionContext) {
// If the extension is launched in debug mode then the debug server options are used
// Otherwise the run options are used
// Options to control the language client
let clientConfig: any = JSON.parse(JSON.stringify(config.rawConfig));
let clientOptions: LanguageClientOptions = {
// Register the server for plain text documents
documentSelector: [
Expand All @@ -155,7 +154,7 @@ export async function activate(context: ExtensionContext) {
fileEvents: workspace.createFileSystemWatcher('**/.clientrc'),
},
initializationOptions: {
settings: clientConfig,
settings: config.toLanguageServerConfig(),
},
outputChannel,
traceOutputChannel,
Expand Down Expand Up @@ -200,7 +199,7 @@ export async function activate(context: ExtensionContext) {

myStatusBarItem.backgroundColor = bgColor;
}
updateStatsBar(clientConfig.enable);
updateStatsBar(config.enable);
client.start();
}

Expand Down

0 comments on commit 1bcd707

Please sign in to comment.