@@ -7,6 +7,7 @@ import { Labels } from "./labels";
77import { StringUtility } from '../utility/stringUtility' ;
88import { SnippetService } from '../service/snippetService' ;
99import { SqliteDataAccess } from '../data/sqliteDataAccess' ;
10+ import { LoggingUtility } from '../utility/loggingUtility' ;
1011
1112
1213export const enum CommandsConsts {
@@ -20,6 +21,14 @@ export const enum CommandsConsts {
2021 commonAddSnippet = "commonSnippetsCmd.addSnippet" ,
2122 commonAddSnippetFromClipboard = "commonSnippetsCmd.addSnippetFromClipboard" ,
2223 commonAddSnippetFolder = "commonSnippetsCmd.addSnippetFolder" ,
24+ // ai commands
25+ commonAskGithubCopilot = "globalSnippetsCmd.askGithubCopilot" ,
26+ commonAddToGithubCopilot = "globalSnippetsCmd.addToGithubCopilot" ,
27+ commonAddAsCodeSnippetToGithubCopilot = "globalSnippetsCmd.addAsCodeSnippetToGithubCopilot" ,
28+ commonAddToCursorAIPane = "globalSnippetsCmd.addToCursorAIPane" ,
29+ commonAddAsCodeSnippetToCursorAIPane = "globalSnippetsCmd.addAsCodeSnippetToCursorAIPane" ,
30+ commonAddToGeminiCodeAssist = "globalSnippetsCmd.addToGeminiCodeAssist" ,
31+ commonAddAsCodeSnippetToGeminiCodeAssist = "globalSnippetsCmd.addAsCodeSnippetToGeminiCodeAssist" ,
2332 // global commands
2433 globalAddSnippet = "globalSnippetsCmd.addSnippet" ,
2534 globalAddSnippetFromClipboard = "globalSnippetsCmd.addSnippetFromClipboard" ,
@@ -429,4 +438,69 @@ export async function fixSnippets(snippetsProvider: SnippetsProvider) {
429438 } ) ;
430439 progress . report ( { increment : 100 } ) ;
431440 } ) ;
441+ }
442+
443+ export async function askGithubCopilot ( snippet : Snippet | undefined , snippetService : SnippetService , wsSnippetService : SnippetService , workspaceSnippetsAvailable : boolean ) {
444+ // if command is not triggered from treeView, a snippet must be selected by final user
445+ if ( ! snippet ) {
446+ let allSnippets = snippetService . getAllSnippets ( ) ;
447+ if ( workspaceSnippetsAvailable ) {
448+ allSnippets = allSnippets . concat ( wsSnippetService . getAllSnippets ( ) ) ;
449+ }
450+ snippet = await UIUtility . requestSnippetFromUser ( allSnippets ) ;
451+ }
452+ if ( ! snippet || ! snippet . value ) {
453+ return ;
454+ }
455+ try {
456+ vscode . commands . executeCommand ( 'workbench.action.chat.open' , snippet . value ) ;
457+ } catch ( error ) {
458+ LoggingUtility . getInstance ( ) . error ( '' + error ) ;
459+ }
460+ }
461+
462+ export async function addToChat ( snippet : Snippet | undefined , snippetService : SnippetService , wsSnippetService : SnippetService , workspaceSnippetsAvailable : boolean , chatCommand : string ) {
463+ // if command is not triggered from treeView, a snippet must be selected by final user
464+ if ( ! snippet ) {
465+ let allSnippets = snippetService . getAllSnippets ( ) ;
466+ if ( workspaceSnippetsAvailable ) {
467+ allSnippets = allSnippets . concat ( wsSnippetService . getAllSnippets ( ) ) ;
468+ }
469+ snippet = await UIUtility . requestSnippetFromUser ( allSnippets ) ;
470+ }
471+ if ( ! snippet || ! snippet . value ) {
472+ return ;
473+ }
474+ try {
475+ await vscode . commands . executeCommand ( chatCommand ) ;
476+ const oldContent = await vscode . env . clipboard . readText ( ) ;
477+ vscode . env . clipboard . writeText ( snippet . value ) ;
478+ vscode . commands . executeCommand ( 'editor.action.clipboardPasteAction' ) ;
479+ vscode . env . clipboard . writeText ( oldContent ) ;
480+ } catch ( error ) {
481+ LoggingUtility . getInstance ( ) . error ( '' + error ) ;
482+ }
483+ }
484+
485+ export async function addAsCodeSnippetToChat ( snippet : Snippet | undefined , snippetService : SnippetService , wsSnippetService : SnippetService , workspaceSnippetsAvailable : boolean , chatCommand : string ) {
486+ // if command is not triggered from treeView, a snippet must be selected by final user
487+ if ( ! snippet ) {
488+ let allSnippets = snippetService . getAllSnippets ( ) ;
489+ if ( workspaceSnippetsAvailable ) {
490+ allSnippets = allSnippets . concat ( wsSnippetService . getAllSnippets ( ) ) ;
491+ }
492+ snippet = await UIUtility . requestSnippetFromUser ( allSnippets ) ;
493+ }
494+ if ( ! snippet || ! snippet . value ) {
495+ return ;
496+ }
497+ try {
498+ await vscode . commands . executeCommand ( chatCommand ) ;
499+ const oldContent = await vscode . env . clipboard . readText ( ) ;
500+ vscode . env . clipboard . writeText ( `\n\`\`\`\n${ snippet . value } \n\`\`\`\n` ) ;
501+ vscode . commands . executeCommand ( 'editor.action.clipboardPasteAction' ) ;
502+ vscode . env . clipboard . writeText ( oldContent ) ;
503+ } catch ( error ) {
504+ LoggingUtility . getInstance ( ) . error ( '' + error ) ;
505+ }
432506}
0 commit comments