Skip to content

Commit ca939c5

Browse files
committed
refactor(vscode): move restart & toggle lsp server to linter.ts
1 parent 0e636f0 commit ca939c5

File tree

5 files changed

+14
-26
lines changed

5 files changed

+14
-26
lines changed

editors/vscode/client/commands.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const commandPrefix = 'oxc';
22

33
export const enum OxcCommands {
4-
RestartServer = `${commandPrefix}.restartServer`,
54
ShowOutputChannel = `${commandPrefix}.showOutputChannel`,
6-
ToggleEnable = `${commandPrefix}.toggleEnable`,
75
// only for linter.ts usage
6+
RestartServer = `${commandPrefix}.restartServer`,
7+
ToggleEnable = `${commandPrefix}.toggleEnable`,
88
ApplyAllFixesFile = `${commandPrefix}.applyAllFixesFile`,
99
}

editors/vscode/client/extension.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,10 @@ export async function activate(context: ExtensionContext) {
1515
log: true,
1616
});
1717

18-
const restartCommand = commands.registerCommand(OxcCommands.RestartServer, async () => {
19-
await linter.restartClient();
20-
});
21-
2218
const showOutputCommand = commands.registerCommand(OxcCommands.ShowOutputChannel, () => {
2319
outputChannel.show();
2420
});
2521

26-
const toggleEnable = commands.registerCommand(OxcCommands.ToggleEnable, async () => {
27-
await configService.vsCodeConfig.updateEnable(!configService.vsCodeConfig.enable);
28-
29-
await linter.toggleClient(configService);
30-
});
31-
3222
const onDidChangeWorkspaceFoldersDispose = workspace.onDidChangeWorkspaceFolders(async (event) => {
3323
for (const folder of event.added) {
3424
configService.addWorkspaceConfig(folder);
@@ -41,9 +31,7 @@ export async function activate(context: ExtensionContext) {
4131
const statusBarItemHandler = new StatusBarItemHandler(context.extension.packageJSON?.version);
4232

4333
context.subscriptions.push(
44-
restartCommand,
4534
showOutputCommand,
46-
toggleEnable,
4735
configService,
4836
outputChannel,
4937
onDidChangeWorkspaceFoldersDispose,

editors/vscode/client/tools/ToolInterface.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,6 @@ export default interface ToolInterface {
2727
*/
2828
deactivate(): Promise<void>;
2929

30-
/**
31-
* Toggles the tool's active state based on configuration.
32-
*/
33-
toggleClient(configService: ConfigService): Promise<void>;
34-
35-
/**
36-
* Restart the tool.
37-
*/
38-
restartClient(): Promise<void>;
39-
4030
/**
4131
* Handles configuration changes.
4232
*/

editors/vscode/client/tools/linter.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ export default class LinterTool implements ToolInterface {
5858
? (await workspace.findFiles(`**/.oxlintrc.json`, '**/node_modules/**', 1)).length > 0
5959
: true;
6060

61+
const restartCommand = commands.registerCommand(OxcCommands.RestartServer, async () => {
62+
await this.restartClient();
63+
});
64+
65+
const toggleEnable = commands.registerCommand(OxcCommands.ToggleEnable, async () => {
66+
await configService.vsCodeConfig.updateEnable(!configService.vsCodeConfig.enable);
67+
68+
await this.toggleClient(configService);
69+
});
70+
6171
const applyAllFixesFile = commands.registerCommand(OxcCommands.ApplyAllFixesFile, async () => {
6272
if (!this.client) {
6373
window.showErrorMessage('oxc client not found');
@@ -81,7 +91,7 @@ export default class LinterTool implements ToolInterface {
8191
await this.client.sendRequest(ExecuteCommandRequest.type, params);
8292
});
8393

84-
context.subscriptions.push(applyAllFixesFile);
94+
context.subscriptions.push(restartCommand, toggleEnable, applyAllFixesFile);
8595

8696
const run: Executable = runExecutable(binaryPath, configService.vsCodeConfig.nodePath);
8797
const serverOptions: ServerOptions = {

editors/vscode/tests/commands.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ suite('commands', () => {
3636
];
3737

3838
deepStrictEqual([
39-
'oxc.restartServer',
4039
'oxc.showOutputChannel',
40+
'oxc.restartServer',
4141
'oxc.toggleEnable',
4242
'oxc.applyAllFixesFile', // TODO: only if linter tests are enabled
4343
...extraCommands,

0 commit comments

Comments
 (0)