Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 100 additions & 10 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,29 @@
import { ConfigManager } from './configManager';
import { Logger } from './utils/logger';
import { AzureDevOpsApiManager } from './utils/azureDevOps';
import { PromptTreeDataProvider } from './ui/promptTreeProvider';

Check failure on line 7 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find module './ui/promptTreeProvider' or its corresponding type declarations.
import { PromptDetailsWebviewProvider } from './ui/promptDetailsWebview';
import { PromptCardsWebviewProvider } from './ui/promptCardsWebview';

Check failure on line 9 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find module './ui/promptCardsWebview' or its corresponding type declarations.
import { PromptCommandManager } from './ui/promptCommands';

Check failure on line 10 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find module './ui/promptCommands' or its corresponding type declarations.


let syncManager: SyncManager;
let statusBarManager: StatusBarManager;
let logger: Logger;
let promptTreeProvider: PromptTreeDataProvider;
let promptDetailsProvider: PromptDetailsWebviewProvider;
let promptCardsProvider: PromptCardsWebviewProvider;
let promptCommandManager: PromptCommandManager;

/**
* Initialize the Promptitude VS Code extension and register its services, UI providers, commands, and subscriptions.
*
* Sets up the logger, configuration and status managers, UI providers (tree, details, cards), sync and command managers,
* registers webview providers and all extension commands, initializes synchronization, and registers configuration-change
* listeners and disposables on the provided extension context.
*
* @param context - The extension context used to register subscriptions and access extension resources
*/
export function activate(context: vscode.ExtensionContext) {
logger = Logger.get('Extension');
logger.info('Promptitude Extension is activating...');
Expand All @@ -29,11 +46,39 @@

const configManager = new ConfigManager(context);
statusBarManager = new StatusBarManager();
syncManager = new SyncManager(configManager, statusBarManager);

// Initialize UI components first
promptTreeProvider = new PromptTreeDataProvider(configManager);
promptDetailsProvider = new PromptDetailsWebviewProvider(context.extensionUri, configManager);
promptCardsProvider = new PromptCardsWebviewProvider(context.extensionUri, configManager, promptTreeProvider);

// Register commands
// Initialize sync manager with tree provider access
syncManager = new SyncManager(configManager, statusBarManager, promptTreeProvider);

// Initialize command manager with sync manager for symlink operations
promptCommandManager = new PromptCommandManager(promptTreeProvider, promptDetailsProvider, configManager, syncManager);

// Register cards webview provider
vscode.window.registerWebviewViewProvider(
PromptCardsWebviewProvider.viewType,
promptCardsProvider
);

// Register details webview provider
vscode.window.registerWebviewViewProvider(
PromptDetailsWebviewProvider.viewType,
promptDetailsProvider
);

// Register prompt commands
promptCommandManager.registerCommands(context);

// Register original commands
const syncNowCommand = vscode.commands.registerCommand('promptitude.syncNow', async () => {
await syncManager.syncNow();
// Refresh prompts after sync
promptTreeProvider.refresh();
promptCardsProvider.refresh();
});

const showStatusCommand = vscode.commands.registerCommand('promptitude.showStatus', async () => {
Expand All @@ -44,6 +89,39 @@
await syncManager.openPromptsFolder();
});

const cleanupOrphanedPromptsCommand = vscode.commands.registerCommand('promptitude.cleanupOrphanedPrompts', async () => {
try {
const result = await vscode.window.showWarningMessage(
'This will remove regular files from your prompts directory that have copies in repository storage. Only symlinked prompts (active prompts) will remain. Continue?',
{ modal: true },
'Yes, Clean Up'
);

if (result === 'Yes, Clean Up') {
const cleanup = await syncManager.cleanupOrphanedPrompts();

Check failure on line 101 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build

Property 'cleanupOrphanedPrompts' does not exist on type 'SyncManager'.

if (cleanup.removed > 0) {
vscode.window.showInformationMessage(
`✅ Cleaned up ${cleanup.removed} orphaned prompt file(s). Only active (symlinked) prompts remain.`
);
} else {
vscode.window.showInformationMessage('No orphaned prompts found. Your prompts directory is clean!');
}

// Refresh UI
promptTreeProvider.refresh();
promptCardsProvider.refresh();

if (cleanup.errors.length > 0) {
logger.warn(`Cleanup completed with ${cleanup.errors.length} errors`);
}
}
} catch (error) {
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
vscode.window.showErrorMessage(`Failed to cleanup orphaned prompts: ${errorMessage}`);
}
});

// Azure DevOps PAT management commands
const addAzureDevOpsPATCommand = vscode.commands.registerCommand('promptitude.addAzureDevOpsPAT', async () => {
try {
Expand Down Expand Up @@ -153,17 +231,29 @@
});

// Add to subscriptions
context.subscriptions.push(syncNowCommand);
context.subscriptions.push(showStatusCommand);
context.subscriptions.push(openPromptsFolderCommand);
context.subscriptions.push(addAzureDevOpsPATCommand);
context.subscriptions.push(clearAzureDevOpsPATCommand);
context.subscriptions.push(clearAzureDevOpsCacheCommand);
context.subscriptions.push(statusBarManager);
context.subscriptions.push(
syncNowCommand,
showStatusCommand,
openPromptsFolderCommand,
cleanupOrphanedPromptsCommand,
addAzureDevOpsPATCommand,
clearAzureDevOpsPATCommand,
clearAzureDevOpsCacheCommand,
statusBarManager
);

// Initialize sync manager
syncManager.initialize(context);

// Set up listener for configuration changes to refresh prompts
const configDisposable = vscode.workspace.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('promptitude')) {
promptTreeProvider.refresh();
promptCardsProvider.refresh();
}
});
context.subscriptions.push(configDisposable);

logger.info('Promptitude Extension activated successfully');
}

Expand All @@ -172,4 +262,4 @@
syncManager?.dispose();
statusBarManager?.dispose();
Logger.disposeSharedChannel();
}
}
Loading
Loading