Skip to content

Commit 5a29274

Browse files
committed
refactor(vscode): move restart & toggle lsp server to linter.ts
1 parent 5ccbd9e commit 5a29274

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(
3323
async (event) => {
3424
for (const folder of event.added) {
@@ -43,9 +33,7 @@ export async function activate(context: ExtensionContext) {
4333
const statusBarItemHandler = new StatusBarItemHandler(context.extension.packageJSON?.version);
4434

4535
context.subscriptions.push(
46-
restartCommand,
4736
showOutputCommand,
48-
toggleEnable,
4937
configService,
5038
outputChannel,
5139
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
@@ -78,6 +78,16 @@ export default class LinterTool implements ToolInterface {
7878
? (await workspace.findFiles(`**/.oxlintrc.json`, "**/node_modules/**", 1)).length > 0
7979
: true;
8080

81+
const restartCommand = commands.registerCommand(OxcCommands.RestartServer, async () => {
82+
await this.restartClient();
83+
});
84+
85+
const toggleEnable = commands.registerCommand(OxcCommands.ToggleEnable, async () => {
86+
await configService.vsCodeConfig.updateEnable(!configService.vsCodeConfig.enable);
87+
88+
await this.toggleClient(configService);
89+
});
90+
8191
const applyAllFixesFile = commands.registerCommand(OxcCommands.ApplyAllFixesFile, async () => {
8292
if (!this.client) {
8393
window.showErrorMessage("oxc client not found");
@@ -101,7 +111,7 @@ export default class LinterTool implements ToolInterface {
101111
await this.client.sendRequest(ExecuteCommandRequest.type, params);
102112
});
103113

104-
context.subscriptions.push(applyAllFixesFile);
114+
context.subscriptions.push(restartCommand, toggleEnable, applyAllFixesFile);
105115

106116
const run: Executable = runExecutable(binaryPath, configService.vsCodeConfig.nodePath);
107117
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)