11import type { TextEditor , Uri } from 'vscode' ;
22import { ProgressLocation } from 'vscode' ;
3+ import type { Source } from '../constants.telemetry' ;
34import type { Container } from '../container' ;
45import { GitUri } from '../git/gitUri' ;
56import { uncommitted , uncommittedStaged } from '../git/models/revision' ;
67import { showGenericErrorMessage } from '../messages' ;
7- import type { AIExplainSource } from '../plus/ai/aiProviderService' ;
88import { getBestRepositoryOrShowPicker } from '../quickpicks/repositoryPicker' ;
99import { command } from '../system/-webview/command' ;
1010import { showMarkdownPreview } from '../system/-webview/markdown' ;
@@ -21,7 +21,7 @@ import {
2121export interface ExplainWipCommandArgs {
2222 repoPath ?: string | Uri ;
2323 staged ?: boolean ;
24- source ?: AIExplainSource ;
24+ source ?: Source ;
2525 worktreePath ?: string ;
2626}
2727
@@ -36,15 +36,15 @@ export class ExplainWipCommand extends GlCommandBase {
3636 args = { ...args } ;
3737 args . repoPath = context . node . worktree . repoPath ;
3838 args . worktreePath = context . node . worktree . path ;
39- args . source = args . source ?? { source : 'view' , type : 'wip' } ;
39+ args . source = args . source ?? { source : 'view' } ;
4040 } else if ( isCommandContextViewNodeHasRepository ( context ) ) {
4141 args = { ...args } ;
4242 args . repoPath = context . node . repo . path ;
43- args . source = args . source ?? { source : 'view' , type : 'wip' } ;
43+ args . source = args . source ?? { source : 'view' } ;
4444 } else if ( isCommandContextViewNodeHasRepoPath ( context ) ) {
4545 args = { ...args } ;
4646 args . repoPath = context . node . repoPath ;
47- args . source = args . source ?? { source : 'view' , type : 'wip' } ;
47+ args . source = args . source ?? { source : 'view' } ;
4848 }
4949
5050 return this . execute ( context . editor , context . uri , args ) ;
@@ -93,10 +93,7 @@ export class ExplainWipCommand extends GlCommandBase {
9393 to = uncommitted ;
9494 }
9595
96- // If a worktree path is specified, use it for the diff
97- // const options = args?.worktreePath ? { uris: [Uri.file(args.worktreePath)] } : undefined;
98- const options = undefined ;
99- const diff = await diffService . getDiff ( to , undefined , options ) ;
96+ const diff = await diffService . getDiff ( to , undefined ) ;
10097 if ( ! diff ?. contents ) {
10198 void showGenericErrorMessage ( 'No working changes found to explain' ) ;
10299 return ;
@@ -126,7 +123,11 @@ export class ExplainWipCommand extends GlCommandBase {
126123 diff : diff . contents ,
127124 message : `${ stagedLabel } working changes${ worktreeInfo } ` ,
128125 } ,
129- args . source ?? { source : 'commandPalette' , type : 'wip' } ,
126+ {
127+ ...args . source ,
128+ source : args . source ?. source ?? 'commandPalette' ,
129+ type : 'wip' ,
130+ } ,
130131 {
131132 progress : {
132133 location : ProgressLocation . Notification ,
@@ -135,13 +136,14 @@ export class ExplainWipCommand extends GlCommandBase {
135136 } ,
136137 ) ;
137138
138- const title = `Working Changes Summary${ worktreeDisplayName } ` ;
139- let content = `# ${ title } \n\n` ;
140- if ( result != null ) {
141- content += `> Generated by ${ result . model . name } \n\n## ${ stagedLabel } Changes\n\n${ result ?. parsed . summary } \n\n${ result ?. parsed . body } ` ;
142- } else {
143- content += `> No changes found to explain.` ;
139+ if ( result == null ) {
140+ void showGenericErrorMessage ( 'Unable to explain working changes' ) ;
141+ return ;
144142 }
143+
144+ const title = `Working Changes Summary${ worktreeDisplayName } ` ;
145+ const content = `# ${ title } \n\n> Generated by ${ result . model . name } \n\n## ${ stagedLabel } Changes\n\n${ result . parsed . summary } \n\n${ result . parsed . body } ` ;
146+
145147 void showMarkdownPreview ( content ) ;
146148 } catch ( ex ) {
147149 Logger . error ( ex , 'ExplainWipCommand' , 'execute' ) ;
0 commit comments