From b37b15b44dcb54b3ea69e7b2a1fd5d3fb04adc88 Mon Sep 17 00:00:00 2001 From: Ladislau Szomoru <3372902+lszomoru@users.noreply.github.com> Date: Tue, 31 Mar 2026 22:20:10 +0000 Subject: [PATCH] Sessions - move more code into the view model (#306951) * Sessions - move more code into the view model * Hide the path in the tree --- .../contrib/changes/browser/changesView.ts | 127 +++++++++--------- 1 file changed, 66 insertions(+), 61 deletions(-) diff --git a/src/vs/sessions/contrib/changes/browser/changesView.ts b/src/vs/sessions/contrib/changes/browser/changesView.ts index 38b3f12a3cc..2cc712ea252 100644 --- a/src/vs/sessions/contrib/changes/browser/changesView.ts +++ b/src/vs/sessions/contrib/changes/browser/changesView.ts @@ -257,6 +257,8 @@ class ChangesViewModel extends Disposable { readonly activeSessionIsolationModeObs: IObservable; readonly activeSessionRepositoryObs: IObservableWithChange; readonly activeSessionChangesObs: IObservable; + readonly activeSessionReviewCommentCountByFileObs: IObservable>; + readonly activeSessionAgentFeedbackCountByFileObs: IObservable>; readonly activeSessionHasGitRepositoryObs: IObservable; readonly activeSessionFirstCheckpointRefObs: IObservable; readonly activeSessionLastCheckpointRefObs: IObservable; @@ -279,7 +281,9 @@ class ChangesViewModel extends Disposable { } constructor( + @IAgentFeedbackService private readonly agentFeedbackService: IAgentFeedbackService, @IAgentSessionsService private readonly agentSessionsService: IAgentSessionsService, + @ICodeReviewService private readonly codeReviewService: ICodeReviewService, @IGitService private readonly gitService: IGitService, @ISessionsManagementService private readonly sessionManagementService: ISessionsManagementService, @IStorageService private readonly storageService: IStorageService, @@ -404,6 +408,62 @@ class ChangesViewModel extends Disposable { return model?.metadata?.lastCheckpointRef as string | undefined; }); + this.activeSessionReviewCommentCountByFileObs = derived(reader => { + const sessionResource = this.activeSessionResourceObs.read(reader); + const changes = [...this.activeSessionChangesObs.read(reader)]; + + if (!sessionResource) { + return new Map(); + } + + const result = new Map(); + const prReviewState = this.codeReviewService.getPRReviewState(sessionResource).read(reader); + if (prReviewState.kind === PRReviewStateKind.Loaded) { + for (const comment of prReviewState.comments) { + const uriKey = comment.uri.fsPath; + result.set(uriKey, (result.get(uriKey) ?? 0) + 1); + } + } + + if (changes.length === 0) { + return result; + } + + const reviewFiles = getCodeReviewFilesFromSessionChanges(changes as readonly IChatSessionFileChange[] | readonly IChatSessionFileChange2[]); + const reviewVersion = getCodeReviewVersion(reviewFiles); + const reviewState = this.codeReviewService.getReviewState(sessionResource).read(reader); + + if (reviewState.kind !== CodeReviewStateKind.Result || reviewState.version !== reviewVersion) { + return result; + } + + for (const comment of reviewState.comments) { + const uriKey = comment.uri.fsPath; + result.set(uriKey, (result.get(uriKey) ?? 0) + 1); + } + + return result; + }); + + this.activeSessionAgentFeedbackCountByFileObs = derived(reader => { + const sessionResource = this.activeSessionResourceObs.read(reader); + if (!sessionResource) { + return new Map(); + } + + observableSignalFromEvent(this, this.agentFeedbackService.onDidChangeFeedback).read(reader); + + const feedbackItems = this.agentFeedbackService.getFeedback(sessionResource); + const result = new Map(); + for (const item of feedbackItems) { + if (!item.sourcePRReviewCommentId) { + const uriKey = item.resourceUri.fsPath; + result.set(uriKey, (result.get(uriKey) ?? 0) + 1); + } + } + return result; + }); + // Version mode this.versionModeObs = observableValue(this, ChangesVersionMode.BranchChanges); @@ -464,7 +524,6 @@ export class ChangesViewPane extends ViewPane { @ILabelService private readonly labelService: ILabelService, @ICodeReviewService private readonly codeReviewService: ICodeReviewService, @IGitHubService private readonly gitHubService: IGitHubService, - @IAgentFeedbackService private readonly agentFeedbackService: IAgentFeedbackService, @IWorkspaceContextService private readonly workspaceContextService: IWorkspaceContextService, ) { super({ ...options, titleMenuId: MenuId.ChatEditingSessionTitleToolbar }, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, hoverService); @@ -660,66 +719,10 @@ export class ChangesViewPane extends ViewPane { private onVisible(): void { this.renderDisposables.clear(); - const reviewCommentCountByFileObs = derived(reader => { - const sessionResource = this.viewModel.activeSessionResourceObs.read(reader); - const changes = [...this.viewModel.activeSessionChangesObs.read(reader)]; - - if (!sessionResource) { - return new Map(); - } - - const result = new Map(); - const prReviewState = this.codeReviewService.getPRReviewState(sessionResource).read(reader); - if (prReviewState.kind === PRReviewStateKind.Loaded) { - for (const comment of prReviewState.comments) { - const uriKey = comment.uri.fsPath; - result.set(uriKey, (result.get(uriKey) ?? 0) + 1); - } - } - - if (changes.length === 0) { - return result; - } - - const reviewFiles = getCodeReviewFilesFromSessionChanges(changes as readonly IChatSessionFileChange[] | readonly IChatSessionFileChange2[]); - const reviewVersion = getCodeReviewVersion(reviewFiles); - const reviewState = this.codeReviewService.getReviewState(sessionResource).read(reader); - - if (reviewState.kind !== CodeReviewStateKind.Result || reviewState.version !== reviewVersion) { - return result; - } - - for (const comment of reviewState.comments) { - const uriKey = comment.uri.fsPath; - result.set(uriKey, (result.get(uriKey) ?? 0) + 1); - } - - return result; - }); - - const agentFeedbackCountByFileObs = derived(reader => { - const sessionResource = this.viewModel.activeSessionResourceObs.read(reader); - if (!sessionResource) { - return new Map(); - } - - observableSignalFromEvent(this, this.agentFeedbackService.onDidChangeFeedback).read(reader); - - const feedbackItems = this.agentFeedbackService.getFeedback(sessionResource); - const result = new Map(); - for (const item of feedbackItems) { - if (!item.sourcePRReviewCommentId) { - const uriKey = item.resourceUri.fsPath; - result.set(uriKey, (result.get(uriKey) ?? 0) + 1); - } - } - return result; - }); - // Convert session file changes to list items (cloud/background sessions) const sessionFilesObs = derived(reader => { - const reviewCommentCountByFile = reviewCommentCountByFileObs.read(reader); - const agentFeedbackCountByFile = agentFeedbackCountByFileObs.read(reader); + const reviewCommentCountByFile = this.viewModel.activeSessionReviewCommentCountByFileObs.read(reader); + const agentFeedbackCountByFile = this.viewModel.activeSessionAgentFeedbackCountByFileObs.read(reader); const changes = [...this.viewModel.activeSessionChangesObs.read(reader)]; return changes.map((entry): IChangesFileItem => { @@ -1582,7 +1585,7 @@ class ChangesTreeRenderer implements ICompressibleTreeRenderer