@@ -4,12 +4,29 @@ import { StatusBarManager } from './statusBarManager';
44import { ConfigManager } from './configManager' ;
55import { Logger } from './utils/logger' ;
66import { AzureDevOpsApiManager } from './utils/azureDevOps' ;
7+ import { PromptTreeDataProvider } from './ui/promptTreeProvider' ;
8+ import { PromptDetailsWebviewProvider } from './ui/promptDetailsWebview' ;
9+ import { PromptCardsWebviewProvider } from './ui/promptCardsWebview' ;
10+ import { PromptCommandManager } from './ui/promptCommands' ;
711
812
913let syncManager : SyncManager ;
1014let statusBarManager : StatusBarManager ;
1115let logger : Logger ;
16+ let promptTreeProvider : PromptTreeDataProvider ;
17+ let promptDetailsProvider : PromptDetailsWebviewProvider ;
18+ let promptCardsProvider : PromptCardsWebviewProvider ;
19+ let promptCommandManager : PromptCommandManager ;
1220
21+ /**
22+ * Initialize the Promptitude VS Code extension and register its services, UI providers, commands, and subscriptions.
23+ *
24+ * Sets up the logger, configuration and status managers, UI providers (tree, details, cards), sync and command managers,
25+ * registers webview providers and all extension commands, initializes synchronization, and registers configuration-change
26+ * listeners and disposables on the provided extension context.
27+ *
28+ * @param context - The extension context used to register subscriptions and access extension resources
29+ */
1330export function activate ( context : vscode . ExtensionContext ) {
1431 logger = Logger . get ( 'Extension' ) ;
1532 logger . info ( 'Promptitude Extension is activating...' ) ;
@@ -29,11 +46,39 @@ export function activate(context: vscode.ExtensionContext) {
2946
3047 const configManager = new ConfigManager ( context ) ;
3148 statusBarManager = new StatusBarManager ( ) ;
32- syncManager = new SyncManager ( configManager , statusBarManager ) ;
49+
50+ // Initialize UI components first
51+ promptTreeProvider = new PromptTreeDataProvider ( configManager ) ;
52+ promptDetailsProvider = new PromptDetailsWebviewProvider ( context . extensionUri , configManager ) ;
53+ promptCardsProvider = new PromptCardsWebviewProvider ( context . extensionUri , configManager , promptTreeProvider ) ;
3354
34- // Register commands
55+ // Initialize sync manager with tree provider access
56+ syncManager = new SyncManager ( configManager , statusBarManager , promptTreeProvider ) ;
57+
58+ // Initialize command manager with sync manager for symlink operations
59+ promptCommandManager = new PromptCommandManager ( promptTreeProvider , promptDetailsProvider , configManager , syncManager ) ;
60+
61+ // Register cards webview provider
62+ vscode . window . registerWebviewViewProvider (
63+ PromptCardsWebviewProvider . viewType ,
64+ promptCardsProvider
65+ ) ;
66+
67+ // Register details webview provider
68+ vscode . window . registerWebviewViewProvider (
69+ PromptDetailsWebviewProvider . viewType ,
70+ promptDetailsProvider
71+ ) ;
72+
73+ // Register prompt commands
74+ promptCommandManager . registerCommands ( context ) ;
75+
76+ // Register original commands
3577 const syncNowCommand = vscode . commands . registerCommand ( 'promptitude.syncNow' , async ( ) => {
3678 await syncManager . syncNow ( ) ;
79+ // Refresh prompts after sync
80+ promptTreeProvider . refresh ( ) ;
81+ promptCardsProvider . refresh ( ) ;
3782 } ) ;
3883
3984 const showStatusCommand = vscode . commands . registerCommand ( 'promptitude.showStatus' , async ( ) => {
@@ -44,6 +89,39 @@ export function activate(context: vscode.ExtensionContext) {
4489 await syncManager . openPromptsFolder ( ) ;
4590 } ) ;
4691
92+ const cleanupOrphanedPromptsCommand = vscode . commands . registerCommand ( 'promptitude.cleanupOrphanedPrompts' , async ( ) => {
93+ try {
94+ const result = await vscode . window . showWarningMessage (
95+ 'This will remove regular files from your prompts directory that have copies in repository storage. Only symlinked prompts (active prompts) will remain. Continue?' ,
96+ { modal : true } ,
97+ 'Yes, Clean Up'
98+ ) ;
99+
100+ if ( result === 'Yes, Clean Up' ) {
101+ const cleanup = await syncManager . cleanupOrphanedPrompts ( ) ;
102+
103+ if ( cleanup . removed > 0 ) {
104+ vscode . window . showInformationMessage (
105+ `✅ Cleaned up ${ cleanup . removed } orphaned prompt file(s). Only active (symlinked) prompts remain.`
106+ ) ;
107+ } else {
108+ vscode . window . showInformationMessage ( 'No orphaned prompts found. Your prompts directory is clean!' ) ;
109+ }
110+
111+ // Refresh UI
112+ promptTreeProvider . refresh ( ) ;
113+ promptCardsProvider . refresh ( ) ;
114+
115+ if ( cleanup . errors . length > 0 ) {
116+ logger . warn ( `Cleanup completed with ${ cleanup . errors . length } errors` ) ;
117+ }
118+ }
119+ } catch ( error ) {
120+ const errorMessage = error instanceof Error ? error . message : 'Unknown error' ;
121+ vscode . window . showErrorMessage ( `Failed to cleanup orphaned prompts: ${ errorMessage } ` ) ;
122+ }
123+ } ) ;
124+
47125 // Azure DevOps PAT management commands
48126 const addAzureDevOpsPATCommand = vscode . commands . registerCommand ( 'promptitude.addAzureDevOpsPAT' , async ( ) => {
49127 try {
@@ -153,17 +231,29 @@ export function activate(context: vscode.ExtensionContext) {
153231 } ) ;
154232
155233 // Add to subscriptions
156- context . subscriptions . push ( syncNowCommand ) ;
157- context . subscriptions . push ( showStatusCommand ) ;
158- context . subscriptions . push ( openPromptsFolderCommand ) ;
159- context . subscriptions . push ( addAzureDevOpsPATCommand ) ;
160- context . subscriptions . push ( clearAzureDevOpsPATCommand ) ;
161- context . subscriptions . push ( clearAzureDevOpsCacheCommand ) ;
162- context . subscriptions . push ( statusBarManager ) ;
234+ context . subscriptions . push (
235+ syncNowCommand ,
236+ showStatusCommand ,
237+ openPromptsFolderCommand ,
238+ cleanupOrphanedPromptsCommand ,
239+ addAzureDevOpsPATCommand ,
240+ clearAzureDevOpsPATCommand ,
241+ clearAzureDevOpsCacheCommand ,
242+ statusBarManager
243+ ) ;
163244
164245 // Initialize sync manager
165246 syncManager . initialize ( context ) ;
166247
248+ // Set up listener for configuration changes to refresh prompts
249+ const configDisposable = vscode . workspace . onDidChangeConfiguration ( e => {
250+ if ( e . affectsConfiguration ( 'promptitude' ) ) {
251+ promptTreeProvider . refresh ( ) ;
252+ promptCardsProvider . refresh ( ) ;
253+ }
254+ } ) ;
255+ context . subscriptions . push ( configDisposable ) ;
256+
167257 logger . info ( 'Promptitude Extension activated successfully' ) ;
168258}
169259
@@ -172,4 +262,4 @@ export function deactivate() {
172262 syncManager ?. dispose ( ) ;
173263 statusBarManager ?. dispose ( ) ;
174264 Logger . disposeSharedChannel ( ) ;
175- }
265+ }
0 commit comments