@@ -21,7 +21,10 @@ import { Autowired } from '@opensumi/di';
2121import { InlineChatController } from '@opensumi/ide-ai-native/lib/browser/widget/inline-chat/inline-chat-controller' ;
2222import { LiveInlineDiffPreviewer } from '@opensumi/ide-ai-native/lib/browser/widget/inline-diff/inline-diff-previewer' ;
2323import { InlineDiffHandler } from '@opensumi/ide-ai-native/lib/browser/widget/inline-diff/inline-diff.handler' ;
24- import { IInlineStreamDiffSnapshotData , InlineStreamDiffHandler } from '@opensumi/ide-ai-native/lib/browser/widget/inline-stream-diff/inline-stream-diff.handler' ;
24+ import {
25+ IInlineStreamDiffSnapshotData ,
26+ InlineStreamDiffHandler ,
27+ } from '@opensumi/ide-ai-native/lib/browser/widget/inline-stream-diff/inline-stream-diff.handler' ;
2528import { AcceptPartialEditWidget } from '@opensumi/ide-ai-native/lib/browser/widget/inline-stream-diff/live-preview.component' ;
2629import { EResultKind } from '@opensumi/ide-ai-native/lib/common' ;
2730import { IMenuRegistry , MenuContribution , MenuId } from '@opensumi/ide-core-browser/lib/menu/next' ;
@@ -146,14 +149,16 @@ export class DiffViewerContribution implements ClientAppContribution, MenuContri
146149 previewer . setValue ( newContent ) ;
147150
148151 await whenReady ;
149- const diffInfo = this . getDiffInfoForUri ( uri ) ;
150- if ( diffInfo ) {
151- // 因为 onTabChange 时机早于应用上 diff 的时机,这里补发一个 onDidTabChange 事件
152- this . _onDidTabChange . fire ( {
153- currentIndex : index ,
154- diffNum : diffInfo . unresolved ,
155- newPath : filePath ,
156- } ) ;
152+ if ( previewer && previewer . isModel ( uri . toString ( ) ) ) {
153+ const diffInfo = this . computeDiffInfo ( previewer . getNode ( ) ) ;
154+ if ( diffInfo ) {
155+ // 因为 onTabChange 时机早于应用上 diff 的时机,这里补发一个 onDidTabChange 事件
156+ this . _onDidTabChange . fire ( {
157+ currentIndex : index ,
158+ diffNum : diffInfo . unresolved ,
159+ newPath : filePath ,
160+ } ) ;
161+ }
157162 }
158163
159164 previewer . layout ( ) ;
@@ -259,7 +264,7 @@ export class DiffViewerContribution implements ClientAppContribution, MenuContri
259264
260265 partialEditWidgetList . forEach ( ( v , idx ) => {
261266 if ( v . status === 'pending' ) {
262- const addedDec = snapshot . decorationSnapshotData . addedDecList [ idx ] ;
267+ const addedDec = snapshot . decorationSnapshotData . addedDecList [ idx ] ;
263268 const removedWidget = snapshot . decorationSnapshotData . removedWidgetList [ idx ] ;
264269 const addedLinesCount = addedDec ?. length || 0 ;
265270 const deletedLinesCount = removedWidget ?. height || 0 ;
@@ -290,13 +295,28 @@ export class DiffViewerContribution implements ClientAppContribution, MenuContri
290295 }
291296 }
292297
298+ computeDiffInfo ( resourceDiff : InlineStreamDiffHandler | undefined ) {
299+ if ( resourceDiff ) {
300+ const result = {
301+ unresolved : 0 ,
302+ total : 0 ,
303+ toAddedLines : 0 ,
304+ toChangedLines : 0 ,
305+ } ;
306+
307+ const snapshot = resourceDiff . createSnapshot ( ) ;
308+ const list = snapshot . decorationSnapshotData . partialEditWidgetList ;
309+ const unresolved = list . filter ( v => v . status === 'pending' ) ;
310+ result . total = list . length ;
311+ result . unresolved = unresolved . length ;
312+ const codeInfo = this . getTotalCodeInfo ( snapshot ) ;
313+ result . toAddedLines = codeInfo . unresolvedAddedLinesCount ;
314+ result . toChangedLines = codeInfo . unresolvedChangedLinesCount ;
315+ return result ;
316+ }
317+ }
318+
293319 getDiffInfoForUri = ( uri : URI ) => {
294- const result = {
295- unresolved : 0 ,
296- total : 0 ,
297- toAddedLines : 0 ,
298- toChangedLines : 0 ,
299- } ;
300320 let resourceDiff = ( this . inlineDiffHandler as any ) . _previewerNodeStore . get ( uri . toString ( ) ) as
301321 | InlineStreamDiffHandler
302322 | undefined ;
@@ -308,17 +328,12 @@ export class DiffViewerContribution implements ClientAppContribution, MenuContri
308328 }
309329 }
310330
311- if ( resourceDiff ) {
312- const snapshot = resourceDiff . createSnapshot ( ) ;
313- const list = snapshot . decorationSnapshotData . partialEditWidgetList ;
314- const unresolved = list . filter ( v => v . status === 'pending' ) ;
315- result . total = list . length ;
316- result . unresolved = unresolved . length ;
317- const codeInfo = this . getTotalCodeInfo ( snapshot ) ;
318- result . toAddedLines = codeInfo . unresolvedAddedLinesCount ;
319- result . toChangedLines = codeInfo . unresolvedChangedLinesCount ;
320- }
321- return result ;
331+ return this . computeDiffInfo ( resourceDiff ) || {
332+ unresolved : 0 ,
333+ total : 0 ,
334+ toAddedLines : 0 ,
335+ toChangedLines : 0 ,
336+ } ;
322337 } ;
323338
324339 async initialize ( ) : Promise < void > {
0 commit comments