Skip to content

Commit b1ec746

Browse files
Copilotalexr00
andauthored
Render content-identical renames using the previous file path (#8907)
* Initial plan * Fix base path for renamed files Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Apply remaining changes Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Attestation commit --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 2464fd6 commit b1ec746

3 files changed

Lines changed: 68 additions & 12 deletions

File tree

‎src/@types/vscode.proposed.chatParticipantAdditions.d.ts‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -573,19 +573,14 @@ declare module 'vscode' {
573573
}
574574

575575
/**
576-
* Represents an auto-mode model routing resolution. Displayed as a collapsible
577-
* widget in the chat stream showing which model was selected and why.
576+
* Explains what the "Auto" model routed a turn to, as a single status line.
577+
* Push a part without a model for the in-flight state, then a resolved one.
578+
* Auto may route several times in a turn; each route gets its own row.
578579
*/
579580
export class ChatResponseAutoModeResolutionPart {
580-
/** The model ID that was selected by the router */
581-
resolvedModel: string;
582-
/** The user-facing display name of the resolved model */
583-
resolvedModelName: string;
584-
/** The router's classification label */
585-
predictedLabel: string;
586-
/** Confidence score (0-1) from the router */
587-
confidence: number;
588-
constructor(resolvedModel: string, resolvedModelName: string, predictedLabel: string, confidence: number);
581+
/** The model the router picked, or `undefined` while routing is in flight. */
582+
resolvedModel: { id: string; name: string } | undefined;
583+
constructor(resolvedModel?: { id: string; name: string });
589584
}
590585

591586
export interface ChatResponseStream {
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { default as assert } from 'assert';
7+
import { createSandbox, SinonSandbox } from 'sinon';
8+
import * as vscode from 'vscode';
9+
import { GitChangeType, InMemFileChange } from '../../common/file';
10+
import { FolderRepositoryManager } from '../../github/folderRepositoryManager';
11+
import { PullRequestModel } from '../../github/pullRequestModel';
12+
import { GitFileChangeModel } from '../../view/fileChangeModel';
13+
import { MockRepository } from '../mocks/mockRepository';
14+
15+
describe('GitFileChangeModel', function () {
16+
let sinon: SinonSandbox;
17+
18+
beforeEach(function () {
19+
sinon = createSandbox();
20+
});
21+
22+
afterEach(function () {
23+
sinon.restore();
24+
});
25+
26+
it('loads base content from the previous filename for a rename', async function () {
27+
const repository = new MockRepository();
28+
const baseCommit = 'base';
29+
const fileName = 'src/b/thing.py';
30+
const previousFileName = 'src/a/thing.py';
31+
const baseContent = 'print("unchanged")';
32+
const show = sinon.stub(repository, 'show').resolves(baseContent);
33+
const change = new InMemFileChange(
34+
baseCommit,
35+
GitChangeType.RENAME,
36+
fileName,
37+
previousFileName,
38+
'',
39+
[],
40+
'https://example.com/thing.py',
41+
);
42+
const model = new GitFileChangeModel(
43+
{ repository } as unknown as FolderRepositoryManager,
44+
{} as PullRequestModel,
45+
change,
46+
vscode.Uri.joinPath(repository.rootUri, fileName),
47+
vscode.Uri.joinPath(repository.rootUri, previousFileName),
48+
'head',
49+
);
50+
51+
assert.strictEqual(await model.showBase(), baseContent);
52+
assert.strictEqual(show.calledOnceWithExactly(
53+
baseCommit,
54+
vscode.Uri.joinPath(repository.rootUri, previousFileName).fsPath,
55+
), true);
56+
});
57+
});

‎src/view/fileChangeModel.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ export class GitFileChangeModel extends FileChangeModel {
120120
async showBase(): Promise<string | undefined> {
121121
if (!this._show && this.change.status !== GitChangeType.ADD) {
122122
const commit = ((this.change instanceof InMemFileChange || this.change instanceof SlimFileChange) ? this.change.baseCommit : this.sha!);
123-
const absolutePath = vscode.Uri.joinPath(this.folderRepoManager.repository.rootUri, this.fileName).fsPath;
123+
const fileName = (this.change.status === GitChangeType.RENAME) &&
124+
(this.change instanceof InMemFileChange || this.change instanceof SlimFileChange)
125+
? this.change.previousFileName!
126+
: this.fileName;
127+
const absolutePath = vscode.Uri.joinPath(this.folderRepoManager.repository.rootUri, fileName).fsPath;
124128
this._show = this.folderRepoManager.repository.show(commit, absolutePath);
125129
}
126130
return this._show;

0 commit comments

Comments
 (0)