@@ -2,6 +2,8 @@ import type { CancellationToken, ProgressOptions } from 'vscode';
22import { ProgressLocation } from 'vscode' ;
33import type { Source } from '../constants.telemetry' ;
44import type { Container } from '../container' ;
5+ import type { MarkdownContentMetadata } from '../documents/markdown' ;
6+ import { getMarkdownHeaderContent } from '../documents/markdown' ;
57import type { GitRepositoryService } from '../git/gitRepositoryService' ;
68import type { GitReference } from '../git/models/reference' ;
79import { uncommitted } from '../git/models/revision' ;
@@ -176,11 +178,15 @@ export async function generateRebase(
176178 const diffInfo = extractRebaseDiffInfo ( result . commits , result . diff , result . hunkMap ) ;
177179
178180 // Generate the markdown content that shows each commit and its diffs
179- const markdownContent = generateRebaseMarkdown ( result , title ) ;
181+ const { content , metadata } = generateRebaseMarkdown ( result , title ) ;
180182
183+ let generateType : 'commits' | 'rebase' = 'rebase' ;
184+ let headRefSlug = head . ref ;
181185 const shas = await repo . git . patch ?. createUnreachableCommitsFromPatches ( base . ref , diffInfo ) ;
182186 if ( shas ?. length ) {
183187 if ( head . ref === uncommitted ) {
188+ generateType = 'commits' ;
189+ headRefSlug = 'uncommitted' ;
184190 // stash the working changes
185191 await svc . stash ?. saveStash ( undefined , undefined , { includeUntracked : true } ) ;
186192 // await repo.git.checkout?.(shas[shas.length - 1]);
@@ -191,7 +197,14 @@ export async function generateRebase(
191197 }
192198 }
193199
194- showMarkdownPreview ( markdownContent ) ;
200+ const documentUri = container . markdown . openDocument (
201+ content ,
202+ `/generate/${ generateType } /${ headRefSlug } /${ result . model . id } ` ,
203+ metadata . header . title ,
204+ metadata ,
205+ ) ;
206+
207+ showMarkdownPreview ( documentUri ) ;
195208 } catch ( ex ) {
196209 Logger . error ( ex , 'GenerateRebaseCommand' , 'execute' ) ;
197210 void showGenericErrorMessage ( 'Unable to parse rebase result' ) ;
@@ -256,18 +269,28 @@ export function extractRebaseDiffInfo(
256269/**
257270 * Formats the reorganized commits into a readable markdown document with proper git diff format
258271 */
259- function generateRebaseMarkdown ( result : AIRebaseResult , title = 'Rebase Commits' ) : string {
260- let markdown = `# ${ title } \n\n> Generated by ${ result . model . name } \n\n` ;
261-
262- const { commits, diff : originalDiff , hunkMap } = result ;
263-
264- if ( commits . length === 0 ) {
265- markdown += `No commits generated\n\n` ;
266- return markdown ;
272+ function generateRebaseMarkdown (
273+ result : AIRebaseResult ,
274+ title = 'Rebase Commits' ,
275+ ) : { content : string ; metadata : MarkdownContentMetadata } {
276+ const metadata = {
277+ header : {
278+ title : title ,
279+ aiModel : result . model . name ,
280+ subtitle : 'Explanation' ,
281+ } ,
282+ } ;
283+
284+ let markdown = '' ;
285+ if ( result . commits . length === 0 ) {
286+ markdown = 'No Commits Generated' ;
287+
288+ return { content : `${ getMarkdownHeaderContent ( metadata ) } \n\n${ markdown } ` , metadata : metadata } ;
267289 }
290+ const { commits, diff : originalDiff , hunkMap } = result ;
268291
269292 let explanations =
270- "## Explanation\n\nOkay , here's the breakdown of the commits I'd create from the provided diff , along with explanations for each:\n\n" ;
293+ "Okay , here's the breakdown of the commits created from the provided changes , along with explanations for each:\n\n" ;
271294
272295 let changes = '## Commits\n\n' ;
273296 for ( let i = 0 ; i < commits . length ; i ++ ) {
@@ -329,7 +352,7 @@ function generateRebaseMarkdown(result: AIRebaseResult, title = 'Rebase Commits'
329352 // markdown += `\n\n----\n\n## Raw commits\n\n\`\`\`${escapeMarkdownCodeBlocks(JSON.stringify(commits))}\`\`\``;
330353 // markdown += `\n\n----\n\n## Original Diff\n\n\`\`\`${escapeMarkdownCodeBlocks(originalDiff)}\`\`\`\n`;
331354
332- return markdown ;
355+ return { content : ` ${ getMarkdownHeaderContent ( metadata ) } \n\n ${ markdown } ` , metadata : metadata } ;
333356}
334357
335358/**
0 commit comments