mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-28 12:33:35 +01:00
Chat - add support to attach a history item change range to chat (#266022)
* Chat - add ISCMHistoryItemChangeRangeVariableEntry * Chat - add content provider for ISCMHistoryItemChangeRangeVariableEntry
This commit is contained in:
@@ -3053,9 +3053,27 @@ export class Repository {
|
||||
return commits[0];
|
||||
}
|
||||
|
||||
async showCommit(ref: string): Promise<string> {
|
||||
async showChanges(ref: string): Promise<string> {
|
||||
try {
|
||||
const result = await this.exec(['show', ref]);
|
||||
const result = await this.exec(['log', '-p', '-n1', ref, '--']);
|
||||
return result.stdout.trim();
|
||||
} catch (err) {
|
||||
if (/^fatal: bad revision '.+'/.test(err.stderr || '')) {
|
||||
err.gitErrorCode = GitErrorCodes.BadRevision;
|
||||
}
|
||||
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
async showChangesBetween(ref1: string, ref2: string, path?: string): Promise<string> {
|
||||
try {
|
||||
const args = ['log', '-p', `${ref1}..${ref2}`, '--'];
|
||||
if (path) {
|
||||
args.push(this.sanitizeRelativePath(path));
|
||||
}
|
||||
|
||||
const result = await this.exec(args);
|
||||
return result.stdout.trim();
|
||||
} catch (err) {
|
||||
if (/^fatal: bad revision '.+'/.test(err.stderr || '')) {
|
||||
|
||||
@@ -408,8 +408,8 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
|
||||
|
||||
async resolveHistoryItemChatContext(historyItemId: string): Promise<string | undefined> {
|
||||
try {
|
||||
const commitDetails = await this.repository.showCommit(historyItemId);
|
||||
return commitDetails;
|
||||
const changes = await this.repository.showChanges(historyItemId);
|
||||
return changes;
|
||||
} catch (err) {
|
||||
this.logger.error(`[GitHistoryProvider][resolveHistoryItemChatContext] Failed to resolve history item '${historyItemId}': ${err}`);
|
||||
}
|
||||
@@ -417,6 +417,22 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
|
||||
return undefined;
|
||||
}
|
||||
|
||||
async resolveHistoryItemChangeRangeChatContext(historyItemId: string, historyItemParentId: string, path: string, token: CancellationToken): Promise<string | undefined> {
|
||||
try {
|
||||
const changes = await this.repository.showChangesBetween(historyItemParentId, historyItemId, path);
|
||||
|
||||
if (token.isCancellationRequested) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return `Output of git log -p ${historyItemParentId}..${historyItemId} -- ${path}:\n\n${changes}`;
|
||||
} catch (err) {
|
||||
this.logger.error(`[GitHistoryProvider][resolveHistoryItemChangeRangeChatContext] Failed to resolve history item change range '${historyItemId}' for '${path}': ${err}`);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
async resolveHistoryItemRefsCommonAncestor(historyItemRefs: string[]): Promise<string | undefined> {
|
||||
try {
|
||||
if (historyItemRefs.length === 0) {
|
||||
|
||||
@@ -1813,8 +1813,12 @@ export class Repository implements Disposable {
|
||||
return await this.repository.getCommit(ref);
|
||||
}
|
||||
|
||||
async showCommit(ref: string): Promise<string> {
|
||||
return await this.run(Operation.Show, () => this.repository.showCommit(ref));
|
||||
async showChanges(ref: string): Promise<string> {
|
||||
return await this.run(Operation.Log(false), () => this.repository.showChanges(ref));
|
||||
}
|
||||
|
||||
async showChangesBetween(ref1: string, ref2: string, path?: string): Promise<string> {
|
||||
return await this.run(Operation.Log(false), () => this.repository.showChangesBetween(ref1, ref2, path));
|
||||
}
|
||||
|
||||
async getEmptyTree(): Promise<string> {
|
||||
|
||||
Reference in New Issue
Block a user