diff --git a/src/vs/sessions/contrib/changes/browser/changesView.ts b/src/vs/sessions/contrib/changes/browser/changesView.ts index b1affdd3cba..53803af7c84 100644 --- a/src/vs/sessions/contrib/changes/browser/changesView.ts +++ b/src/vs/sessions/contrib/changes/browser/changesView.ts @@ -319,7 +319,8 @@ class ChangesViewModel extends Disposable { // Active session isolation mode this.activeSessionIsolationModeObs = derived(reader => { - return activeSessionRepositoryObs.read(reader)?.workingDirectory === undefined + const activeSessionRepository = activeSessionRepositoryObs.read(reader); + return activeSessionRepository?.workingDirectory === undefined ? IsolationMode.Workspace : IsolationMode.Worktree; }); @@ -331,7 +332,8 @@ class ChangesViewModel extends Disposable { return constObservable(undefined); } - const workingDirectory = activeSessionRepositoryObs.read(reader)?.workingDirectory; + const activeSessionRepository = activeSessionRepositoryObs.read(reader); + const workingDirectory = activeSessionRepository?.workingDirectory ?? activeSessionRepository?.uri; if (!workingDirectory) { return constObservable(undefined); } @@ -713,46 +715,49 @@ export class ChangesViewPane extends ViewPane { }); }); - const headCommitObs = derived(reader => { + const allChangesObs = derived(reader => { const repository = this.viewModel.activeSessionRepositoryObs.read(reader); - return repository?.state.read(reader)?.HEAD?.commit; + const firstCheckpointRef = this.viewModel.activeSessionFirstCheckpointRefObs.read(reader); + const lastCheckpointRef = this.viewModel.activeSessionLastCheckpointRefObs.read(reader); + + if (!repository || !firstCheckpointRef || !lastCheckpointRef) { + return constObservable(undefined); + } + + const diffPromise = repository.diffBetweenWithStats(firstCheckpointRef, lastCheckpointRef); + return new ObservablePromise(diffPromise).resolvedValue; }); const lastTurnChangesObs = derived(reader => { const repository = this.viewModel.activeSessionRepositoryObs.read(reader); - const headCommit = headCommitObs.read(reader); + const lastCheckpointRef = this.viewModel.activeSessionLastCheckpointRefObs.read(reader); - if (!repository || !headCommit) { + if (!repository || !lastCheckpointRef) { return constObservable(undefined); } - const lastCheckpointRef = this.viewModel.activeSessionLastCheckpointRefObs.read(reader); - - const diffPromise = lastCheckpointRef - ? repository.diffBetweenWithStats(`${lastCheckpointRef}^`, lastCheckpointRef) - : repository.diffBetweenWithStats(`${headCommit}^`, headCommit); - + const diffPromise = repository.diffBetweenWithStats(`${lastCheckpointRef}^`, lastCheckpointRef); return new ObservablePromise(diffPromise).resolvedValue; }); - const isLoadingLastTurnObs = derived(reader => { + const isLoadingChangesObs = derived(reader => { const versionMode = this.viewModel.versionModeObs.read(reader); - if (versionMode !== ChangesVersionMode.LastTurn) { + if (versionMode !== ChangesVersionMode.AllChanges && versionMode !== ChangesVersionMode.LastTurn) { return false; } - const headCommit = headCommitObs.read(reader); const repository = this.viewModel.activeSessionRepositoryObs.read(reader); - if (!repository || !headCommit) { + if (!repository) { return false; } - const result = lastTurnChangesObs.read(reader).read(reader); - return result === undefined; + const allChangesResult = allChangesObs.read(reader).read(reader); + const lastTurnChangesResult = lastTurnChangesObs.read(reader).read(reader); + return allChangesResult === undefined || lastTurnChangesResult === undefined; }); this.renderDisposables.add(autorun(reader => { - const isLoading = isLoadingLastTurnObs.read(reader); + const isLoading = isLoadingChangesObs.read(reader); if (isLoading) { this.changesProgressBar.infinite().show(200); } else { @@ -762,28 +767,21 @@ export class ChangesViewPane extends ViewPane { // Combine both entry sources for display const combinedEntriesObs = derived(reader => { - const headCommit = headCommitObs.read(reader); - const sessionFiles = sessionFilesObs.read(reader); const versionMode = this.viewModel.versionModeObs.read(reader); - let sourceEntries: IChangesFileItem[]; - if (versionMode === ChangesVersionMode.LastTurn) { - const lastTurnDiffChanges = lastTurnChangesObs.read(reader).read(reader); + const sourceEntries: IChangesFileItem[] = []; + if (versionMode === ChangesVersionMode.BranchChanges) { + const sessionFiles = sessionFilesObs.read(reader); + sourceEntries.push(...sessionFiles); + } else if (versionMode === ChangesVersionMode.AllChanges) { + const allChanges = allChangesObs.read(reader).read(reader) ?? []; + const firstCheckpointRef = this.viewModel.activeSessionFirstCheckpointRefObs.read(reader); const lastCheckpointRef = this.viewModel.activeSessionLastCheckpointRefObs.read(reader); - - const diffChanges = lastTurnDiffChanges ?? []; - - const modifiedRef = lastCheckpointRef - ? lastCheckpointRef - : headCommit; - - const originalRef = lastCheckpointRef - ? `${lastCheckpointRef}^` - : headCommit ? `${headCommit}^` : undefined; - - sourceEntries = toChangesFileItem(diffChanges, modifiedRef, originalRef); - } else { - sourceEntries = [...sessionFiles]; + sourceEntries.push(...toChangesFileItem(allChanges, lastCheckpointRef, firstCheckpointRef)); + } else if (versionMode === ChangesVersionMode.LastTurn) { + const diffChanges = lastTurnChangesObs.read(reader).read(reader) ?? []; + const lastCheckpointRef = this.viewModel.activeSessionLastCheckpointRefObs.read(undefined); + sourceEntries.push(...toChangesFileItem(diffChanges, lastCheckpointRef, lastCheckpointRef ? `${lastCheckpointRef}^` : undefined)); } const resources = new Set(); @@ -817,7 +815,7 @@ export class ChangesViewPane extends ViewPane { let lastHasChanges = false; this.renderDisposables.add(bindContextKey(ChatContextKeys.hasAgentSessionChanges, this.scopedContextKeyService, reader => { - if (isLoadingLastTurnObs.read(reader)) { + if (isLoadingChangesObs.read(reader)) { return lastHasChanges; } const { files } = topLevelStats.read(reader); @@ -956,7 +954,7 @@ export class ChangesViewPane extends ViewPane { // Update visibility and file count badge based on entries this.renderDisposables.add(autorun(reader => { - if (isLoadingLastTurnObs.read(reader)) { + if (isLoadingChangesObs.read(reader)) { return; } @@ -982,7 +980,7 @@ export class ChangesViewPane extends ViewPane { this.summaryContainer.appendChild(linesRemovedSpan); this.renderDisposables.add(autorun(reader => { - if (isLoadingLastTurnObs.read(reader)) { + if (isLoadingChangesObs.read(reader)) { return; } @@ -1140,7 +1138,7 @@ export class ChangesViewPane extends ViewPane { this.renderDisposables.add(autorun(reader => { const entries = combinedEntriesObs.read(reader); const viewMode = this.viewModel.viewModeObs.read(reader); - const isLoading = isLoadingLastTurnObs.read(reader); + const isLoading = isLoadingChangesObs.read(reader); if (!this.tree || isLoading) { return;