custom commands init

This commit is contained in:
andrepimenta
2025-07-14 21:57:33 +01:00
parent 42a5ebf763
commit 2aa7db86e7
3 changed files with 571 additions and 7 deletions

View File

@@ -296,6 +296,15 @@ class ClaudeChatProvider {
case 'deleteMCPServer':
this._deleteMCPServer(message.name);
return;
case 'getCustomSnippets':
this._sendCustomSnippets();
return;
case 'saveCustomSnippet':
this._saveCustomSnippet(message.snippet);
return;
case 'deleteCustomSnippet':
this._deleteCustomSnippet(message.snippetId);
return;
}
}
@@ -1615,6 +1624,73 @@ class ClaudeChatProvider {
}
}
private async _sendCustomSnippets(): Promise<void> {
try {
const customSnippets = this._context.globalState.get<{[key: string]: any}>('customPromptSnippets', {});
this._postMessage({
type: 'customSnippetsData',
data: customSnippets
});
} catch (error) {
console.error('Error loading custom snippets:', error);
this._postMessage({
type: 'customSnippetsData',
data: {}
});
}
}
private async _saveCustomSnippet(snippet: any): Promise<void> {
try {
const customSnippets = this._context.globalState.get<{[key: string]: any}>('customPromptSnippets', {});
customSnippets[snippet.id] = snippet;
await this._context.globalState.update('customPromptSnippets', customSnippets);
this._postMessage({
type: 'customSnippetSaved',
data: { snippet }
});
console.log('Saved custom snippet:', snippet.name);
} catch (error) {
console.error('Error saving custom snippet:', error);
this._postMessage({
type: 'error',
data: 'Failed to save custom snippet'
});
}
}
private async _deleteCustomSnippet(snippetId: string): Promise<void> {
try {
const customSnippets = this._context.globalState.get<{[key: string]: any}>('customPromptSnippets', {});
if (customSnippets[snippetId]) {
delete customSnippets[snippetId];
await this._context.globalState.update('customPromptSnippets', customSnippets);
this._postMessage({
type: 'customSnippetDeleted',
data: { snippetId }
});
console.log('Deleted custom snippet:', snippetId);
} else {
this._postMessage({
type: 'error',
data: 'Snippet not found'
});
}
} catch (error) {
console.error('Error deleting custom snippet:', error);
this._postMessage({
type: 'error',
data: 'Failed to delete custom snippet'
});
}
}
private convertToWSLPath(windowsPath: string): string {
const config = vscode.workspace.getConfiguration('claudeCodeChat');
const wslEnabled = config.get<boolean>('wsl.enabled', false);