Skip to content

Commit d5ec71f

Browse files
committed
chore(vscode): second language server connection for oxfmt
1 parent f7ff45d commit d5ec71f

File tree

9 files changed

+379
-34
lines changed

9 files changed

+379
-34
lines changed

editors/vscode/.vscode-test.mjs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,25 @@ export default defineConfig({
5858
],
5959
env: {
6060
SINGLE_FOLDER_WORKSPACE: 'true',
61-
OXLINT_LSP_TEST: 'true',
6261
SERVER_PATH_DEV: path.resolve(import.meta.dirname, `../../apps/oxlint/dist/cli.js`),
63-
SKIP_FORMATTER_TEST: 'true',
62+
SKIP_LINTER_TEST: 'true',
63+
},
64+
mocha: {
65+
timeout: 10_000,
66+
},
67+
},
68+
// Oxfmt --lsp tests
69+
{
70+
files: 'out/**/*.spec.js',
71+
workspaceFolder: './test_workspace',
72+
launchArgs: [
73+
// This disables all extensions except the one being tested
74+
'--disable-extensions',
75+
],
76+
env: {
77+
SINGLE_FOLDER_WORKSPACE: 'true',
78+
SERVER_PATH_DEV: path.resolve(import.meta.dirname, `../../apps/oxfmt/dist/cli.js`),
79+
SKIP_LINTER_TEST: 'true',
6480
},
6581
mocha: {
6682
timeout: 10_000,

editors/vscode/client/ConfigService.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ export class ConfigService implements IDisposable {
8484
return bin;
8585
}
8686

87+
public async getOxfmtServerBinPath(): Promise<string | undefined> {
88+
const files = await workspace.findFiles('**/node_modules/.bin/oxfmt', null, 1);
89+
90+
return files.length > 0 ? files[0].fsPath : undefined;
91+
}
92+
8793
private async onVscodeConfigChange(event: ConfigurationChangeEvent): Promise<void> {
8894
let isConfigChanged = false;
8995

editors/vscode/client/extension.ts

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,56 @@ import { commands, ExtensionContext, window, workspace } from 'vscode';
22

33
import { OxcCommands } from './commands';
44
import { ConfigService } from './ConfigService';
5+
import {
6+
activate as activateFormatter,
7+
deactivate as deactivateFormatter,
8+
onConfigChange as onConfigChangeFormatter,
9+
restartClient as restartFormatter,
10+
toggleClient as toggleFormatter,
11+
} from './formatter';
512
import {
613
activate as activateLinter,
714
deactivate as deactivateLinter,
815
onConfigChange as onConfigChangeLinter,
9-
restartClient,
10-
toggleClient,
16+
restartClient as restartLinter,
17+
toggleClient as toggleLinter,
1118
} from './linter';
1219

1320
const outputChannelName = 'Oxc';
1421

1522
export async function activate(context: ExtensionContext) {
1623
const configService = new ConfigService();
1724

18-
const outputChannel = window.createOutputChannel(outputChannelName, {
25+
const outputChannelLint = window.createOutputChannel(outputChannelName + ' (Lint)', {
26+
log: true,
27+
});
28+
29+
const outputChannelFormat = window.createOutputChannel(outputChannelName + ' (Fmt)', {
1930
log: true,
2031
});
2132

2233
const restartCommand = commands.registerCommand(OxcCommands.RestartServer, async () => {
23-
await restartClient();
34+
if (process.env.SKIP_LINTER_TEST !== 'true') {
35+
await restartLinter();
36+
}
37+
if (process.env.SKIP_FORMATTER_TEST !== 'true') {
38+
await restartFormatter();
39+
}
2440
});
2541

2642
const showOutputCommand = commands.registerCommand(OxcCommands.ShowOutputChannel, () => {
27-
outputChannel.show();
43+
outputChannelLint.show();
2844
});
2945

3046
const toggleEnable = commands.registerCommand(OxcCommands.ToggleEnable, async () => {
3147
await configService.vsCodeConfig.updateEnable(!configService.vsCodeConfig.enable);
3248

33-
await toggleClient(configService);
49+
if (process.env.SKIP_LINTER_TEST !== 'true') {
50+
await toggleLinter(configService);
51+
}
52+
if (process.env.SKIP_FORMATTER_TEST !== 'true') {
53+
await toggleFormatter(configService);
54+
}
3455
});
3556

3657
const onDidChangeWorkspaceFoldersDispose = workspace.onDidChangeWorkspaceFolders(async (event) => {
@@ -47,17 +68,33 @@ export async function activate(context: ExtensionContext) {
4768
showOutputCommand,
4869
toggleEnable,
4970
configService,
50-
outputChannel,
71+
outputChannelLint,
72+
outputChannelFormat,
5173
onDidChangeWorkspaceFoldersDispose,
5274
);
5375

5476
configService.onConfigChange = async function onConfigChange(event) {
55-
await onConfigChangeLinter(context, event, configService);
77+
if (process.env.SKIP_LINTER_TEST !== 'true') {
78+
await onConfigChangeLinter(context, event, configService);
79+
}
80+
if (process.env.SKIP_FORMATTER_TEST !== 'true') {
81+
await onConfigChangeFormatter(context, event, configService);
82+
}
5683
};
5784

58-
await activateLinter(context, outputChannel, configService);
85+
if (process.env.SKIP_LINTER_TEST !== 'true') {
86+
await activateLinter(context, outputChannelLint, configService);
87+
}
88+
if (process.env.SKIP_FORMATTER_TEST !== 'true') {
89+
await activateFormatter(context, outputChannelFormat, configService);
90+
}
5991
}
6092

6193
export async function deactivate(): Promise<void> {
62-
await deactivateLinter();
94+
if (process.env.SKIP_LINTER_TEST !== 'true') {
95+
await deactivateLinter();
96+
}
97+
if (process.env.SKIP_FORMATTER_TEST !== 'true') {
98+
await deactivateFormatter();
99+
}
63100
}

0 commit comments

Comments
 (0)