Skip to content
Merged
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
19 changes: 19 additions & 0 deletions editors/vscode/client/ConfigService.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as path from 'node:path';
import { ConfigurationChangeEvent, Uri, workspace, WorkspaceFolder } from 'vscode';
import { IDisposable } from './types';
import { VSCodeConfig } from './VSCodeConfig';
Expand Down Expand Up @@ -59,6 +60,24 @@ export class ConfigService implements IDisposable {
return false;
}

public getUserServerBinPath(): string | undefined {
let bin = this.vsCodeConfig.binPath;
if (!bin) {
return;
}

if (!path.isAbsolute(bin)) {
// if the path is not absolute, resolve it to the first workspace folder
let cwd = this.workspaceConfigs.keys().next().value;
if (!cwd) {
return;
}
bin = path.normalize(path.join(cwd, bin));
}

return bin;
}

private async onVscodeConfigChange(event: ConfigurationChangeEvent): Promise<void> {
let isConfigChanged = false;

Expand Down
2 changes: 1 addition & 1 deletion editors/vscode/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export async function activate(context: ExtensionContext) {
);

async function findBinary(): Promise<string> {
let bin = configService.vsCodeConfig.binPath;
let bin = configService.getUserServerBinPath();
if (bin) {
try {
await fsPromises.access(bin);
Expand Down
37 changes: 37 additions & 0 deletions editors/vscode/tests/ConfigService.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { strictEqual } from 'assert';
import { workspace } from 'vscode';
import { ConfigService } from '../client/ConfigService.js';
import { testSingleFolderMode, WORKSPACE_FOLDER } from './test-helpers.js';

const conf = workspace.getConfiguration('oxc');

suite('ConfigService', () => {
setup(async () => {
const keys = ['path.server'];

await Promise.all(keys.map(key => conf.update(key, undefined)));
});

teardown(async () => {
const keys = ['path.server'];

await Promise.all(keys.map(key => conf.update(key, undefined)));
});

testSingleFolderMode('resolves relative server path with workspace folder', async () => {
const service = new ConfigService();
const nonDefinedServerPath = service.getUserServerBinPath();

strictEqual(nonDefinedServerPath, undefined);

await conf.update('path.server', '/absolute/binary');
const absoluteServerPath = service.getUserServerBinPath();

strictEqual(absoluteServerPath, '/absolute/binary');

await conf.update('path.server', './relative/binary');
const relativeServerPath = service.getUserServerBinPath();

strictEqual(relativeServerPath, WORKSPACE_FOLDER.uri.path + '/relative/binary');
});
});
Loading