-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathextension.ts
More file actions
75 lines (61 loc) · 2.55 KB
/
extension.ts
File metadata and controls
75 lines (61 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import * as vscode from 'vscode';
import { registerCommands } from './commands';
import { handleStartNotification, processNotification, handleOutdatedConfigFilesNotification } from './notifications';
import { registerDocumentListeners } from './documents';
import { registerCodeLens } from './code-lens';
import { createStatusBar, statusBarLoop, updateStatusBar } from './status-bar';
import { registerCodeActions } from './code-actions';
import { updateGlobalState } from './state';
import { VersionPreference } from './enums';
import { registerMcpServer } from './mcp';
import { registerTaskProvider } from './task-provider';
import { promptForWorkspaceRecommendation } from './utils';
// Global variable to track the interval
let statusBarInterval: NodeJS.Timeout | undefined;
export const activate = async (context: vscode.ExtensionContext): Promise<vscode.ExtensionContext> => {
const configuration = vscode.workspace.getConfiguration('dev-proxy-toolkit');
const versionPreference = configuration.get('version') as VersionPreference;
const statusBar = createStatusBar(context);
await updateGlobalState(context, versionPreference);
const collection = vscode.languages.createDiagnosticCollection('dev-proxy-toolkit');
// Add collection to subscriptions for automatic disposal
context.subscriptions.push(collection);
registerDocumentListeners(context, collection);
registerCodeActions(context);
registerCodeLens(context);
registerCommands(context, configuration);
registerMcpServer(context);
registerTaskProvider(context);
const notification = handleStartNotification(context);
processNotification(notification);
// Prompt for workspace recommendations
promptForWorkspaceRecommendation(context);
handleOutdatedConfigFilesNotification(context);
updateStatusBar(context, statusBar);
// Store the interval reference for proper cleanup
statusBarInterval = setInterval(() => {
// Add error handling to prevent uncaught exceptions
try {
statusBarLoop(context, statusBar, versionPreference);
} catch (error) {
console.error('Error in statusBarLoop:', error);
}
}, 5000);
// Add the interval to subscriptions for automatic cleanup
context.subscriptions.push({
dispose: () => {
if (statusBarInterval) {
clearInterval(statusBarInterval);
statusBarInterval = undefined;
}
}
});
return context;
};
export const deactivate = () => {
// Clean up the interval if it's still running
if (statusBarInterval) {
clearInterval(statusBarInterval);
statusBarInterval = undefined;
}
};