Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion editors/vscode/client/VSCodeConfig.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { workspace } from 'vscode';
import { ConfigurationChangeEvent, workspace } from 'vscode';
import { ConfigService } from './ConfigService';

export class VSCodeConfig implements VSCodeConfigInterface {
private _enable!: boolean;
private _trace!: TraceLevel;
private _binPath: string | undefined;
private _nodePath: string | undefined;

constructor() {
this.refresh();
Expand All @@ -18,6 +19,7 @@ export class VSCodeConfig implements VSCodeConfigInterface {
this._enable = this.configuration.get<boolean>('enable') ?? true;
this._trace = this.configuration.get<TraceLevel>('trace.server') || 'off';
this._binPath = this.configuration.get<string>('path.server');
this._nodePath = this.configuration.get<string>('path.node');
}

get enable(): boolean {
Expand Down Expand Up @@ -46,6 +48,19 @@ export class VSCodeConfig implements VSCodeConfigInterface {
this._binPath = value;
return this.configuration.update('path.server', value);
}

get nodePath(): string | undefined {
return this._nodePath;
}

updateNodePath(value: string | undefined): PromiseLike<void> {
this._nodePath = value;
return this.configuration.update('path.node', value);
}

public effectsNodePathChange(event: ConfigurationChangeEvent): boolean {
return event.affectsConfiguration(`${ConfigService.namespace}.path.node`);
}
}

type TraceLevel = 'off' | 'messages' | 'verbose';
Expand All @@ -72,4 +87,10 @@ interface VSCodeConfigInterface {
* @default undefined
*/
binPath: string | undefined;
/**
* Path to Node binary
* `oxc.path.node`
* @default undefined
*/
nodePath: string | undefined;
}
28 changes: 23 additions & 5 deletions editors/vscode/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { Executable, LanguageClient, LanguageClientOptions, ServerOptions } from
import { join } from 'node:path';
import { ConfigService } from './ConfigService';
import { oxlintConfigFileName } from './WorkspaceConfig';
import path = require('node:path');

const languageClientName = 'oxc';
const outputChannelName = 'Oxc';
Expand Down Expand Up @@ -178,14 +179,28 @@ export async function activate(context: ExtensionContext) {
);
}

const serverEnv: Record<string, string> = {
...process.env,
RUST_LOG: process.env.RUST_LOG || 'info',
};

if (configService.vsCodeConfig.nodePath) {
outputChannel.info(`adding node path to PATH: ${configService.vsCodeConfig.nodePath}`);

// Find the PATH environment variable regardless of case (Windows uses 'Path')
const pathKey = Object.keys(serverEnv).find(key => key.toUpperCase() === 'PATH') || 'PATH';
if (serverEnv[pathKey]) {
serverEnv[pathKey] = serverEnv[pathKey].concat(path.delimiter, configService.vsCodeConfig.nodePath);
} else {
serverEnv[pathKey] = configService.vsCodeConfig.nodePath;
}
}

const command = await findBinary();
const run: Executable = {
command: command!,
options: {
env: {
...process.env,
RUST_LOG: process.env.RUST_LOG || 'info',
},
env: serverEnv,
},
};
const serverOptions: ServerOptions = {
Expand Down Expand Up @@ -316,7 +331,10 @@ export async function activate(context: ExtensionContext) {
// update the initializationOptions for a possible restart
client.clientOptions.initializationOptions = this.languageServerConfig;

if (configService.effectsWorkspaceConfigPathChange(event)) {
if (configService.vsCodeConfig.effectsNodePathChange(event)) {
// restart the extension
await commands.executeCommand('workbench.action.reloadWindow');
} else if (configService.effectsWorkspaceConfigPathChange(event)) {
client.clientOptions.synchronize = client.clientOptions.synchronize ?? {};
client.clientOptions.synchronize.fileEvents = createFileEventWatchers(this.getOxlintCustomConfigs());

Expand Down
25 changes: 15 additions & 10 deletions editors/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,6 @@
"type": "object",
"title": "oxc",
"properties": {
"oxc.lint.run": {
"scope": "resource",
"type": "string",
"enum": [
"onSave",
"onType"
],
"default": "onType",
"description": "Run the linter on save (onSave) or on type (onType)"
},
"oxc.enable": {
"type": "boolean",
"default": true,
Expand Down Expand Up @@ -101,6 +91,21 @@
"scope": "window",
"description": "Path to Oxc language server binary. Mostly for testing the language server."
},
"oxc.path.node": {
"type": "string",
"scope": "window",
"description": "The path of `node` which will be added to `PATH` server environment."
},
"oxc.lint.run": {
"scope": "resource",
"type": "string",
"enum": [
"onSave",
"onType"
],
"default": "onType",
"description": "Run the linter on save (onSave) or on type (onType)"
},
"oxc.configPath": {
"type": [
"string",
Expand Down
Loading