Skip to content

Commit d006a1c

Browse files
committed
refactor(vscode): introduce ToolInterface
1 parent 559d637 commit d006a1c

File tree

6 files changed

+339
-296
lines changed

6 files changed

+339
-296
lines changed

editors/vscode/client/extension.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,11 @@ import { commands, ExtensionContext, window, workspace } from 'vscode';
22

33
import { OxcCommands } from './commands';
44
import { ConfigService } from './ConfigService';
5-
import {
6-
activate as activateLinter,
7-
deactivate as deactivateLinter,
8-
onConfigChange as onConfigChangeLinter,
9-
restartClient,
10-
toggleClient,
11-
} from './linter';
125
import StatusBarItemHandler from './StatusBarItemHandler';
6+
import Linter from './tools/linter';
137

148
const outputChannelName = 'Oxc';
9+
const linter = new Linter();
1510

1611
export async function activate(context: ExtensionContext) {
1712
const configService = new ConfigService();
@@ -21,7 +16,7 @@ export async function activate(context: ExtensionContext) {
2116
});
2217

2318
const restartCommand = commands.registerCommand(OxcCommands.RestartServer, async () => {
24-
await restartClient();
19+
await linter.restartClient();
2520
});
2621

2722
const showOutputCommand = commands.registerCommand(OxcCommands.ShowOutputChannel, () => {
@@ -31,7 +26,7 @@ export async function activate(context: ExtensionContext) {
3126
const toggleEnable = commands.registerCommand(OxcCommands.ToggleEnable, async () => {
3227
await configService.vsCodeConfig.updateEnable(!configService.vsCodeConfig.enable);
3328

34-
await toggleClient(configService);
29+
await linter.toggleClient(configService);
3530
});
3631

3732
const onDidChangeWorkspaceFoldersDispose = workspace.onDidChangeWorkspaceFolders(async (event) => {
@@ -56,14 +51,14 @@ export async function activate(context: ExtensionContext) {
5651
);
5752

5853
configService.onConfigChange = async function onConfigChange(event) {
59-
await onConfigChangeLinter(event, configService, statusBarItemHandler);
54+
await linter.onConfigChange(event, configService, statusBarItemHandler);
6055
};
6156

62-
await activateLinter(context, outputChannel, configService, statusBarItemHandler);
57+
await linter.activate(context, outputChannel, configService, statusBarItemHandler);
6358
// Show status bar item after activation
6459
statusBarItemHandler.show();
6560
}
6661

6762
export async function deactivate(): Promise<void> {
68-
await deactivateLinter();
63+
await linter.deactivate();
6964
}

editors/vscode/client/linter.ts

Lines changed: 0 additions & 283 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { ConfigurationChangeEvent, ExtensionContext, LogOutputChannel } from 'vscode';
2+
import { ConfigService } from '../ConfigService';
3+
import StatusBarItemHandler from '../StatusBarItemHandler';
4+
5+
export default interface ToolInterface {
6+
/**
7+
* Activates the tool and creates an LSP connection if necessary.
8+
*/
9+
activate(
10+
context: ExtensionContext,
11+
outputChannel: LogOutputChannel,
12+
configService: ConfigService,
13+
statusBarItemHandler: StatusBarItemHandler,
14+
): Promise<void>;
15+
16+
/**
17+
* Deactivates the tool and stops the LSP connection if necessary.
18+
*/
19+
deactivate(): Promise<void>;
20+
21+
/**
22+
* Starts or stops the LSP client.
23+
*/
24+
toggleClient(configService: ConfigService): Promise<void>;
25+
26+
/**
27+
* Restart the LSP client.
28+
*/
29+
restartClient(): Promise<void>;
30+
31+
/**
32+
* Handles configuration changes.
33+
*/
34+
onConfigChange(
35+
event: ConfigurationChangeEvent,
36+
configService: ConfigService,
37+
statusBarItemHandler: StatusBarItemHandler,
38+
): Promise<void>;
39+
}

0 commit comments

Comments
 (0)