mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 17:43:00 -05:00
SCM - add method to resolve a source control history item (#265844)
This commit is contained in:
@@ -352,6 +352,60 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
|
||||
return historyItemChanges;
|
||||
}
|
||||
|
||||
async resolveHistoryItem(historyItemId: string, token: CancellationToken): Promise<SourceControlHistoryItem | undefined> {
|
||||
try {
|
||||
const commit = await this.repository.getCommit(historyItemId);
|
||||
|
||||
if (!commit || token.isCancellationRequested) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Avatars
|
||||
const avatarQuery = {
|
||||
commits: [{
|
||||
hash: commit.hash,
|
||||
authorName: commit.authorName,
|
||||
authorEmail: commit.authorEmail
|
||||
} satisfies AvatarQueryCommit],
|
||||
size: 20
|
||||
} satisfies AvatarQuery;
|
||||
|
||||
const commitAvatars = await provideSourceControlHistoryItemAvatar(
|
||||
this.historyItemDetailProviderRegistry, this.repository, avatarQuery);
|
||||
|
||||
await ensureEmojis();
|
||||
|
||||
const message = emojify(commit.message);
|
||||
const messageWithLinks = await provideSourceControlHistoryItemMessageLinks(
|
||||
this.historyItemDetailProviderRegistry, this.repository, message) ?? message;
|
||||
|
||||
const newLineIndex = message.indexOf('\n');
|
||||
const subject = newLineIndex !== -1
|
||||
? `${truncate(message, newLineIndex, false)}`
|
||||
: message;
|
||||
|
||||
const avatarUrl = commitAvatars?.get(commit.hash);
|
||||
const references = this._resolveHistoryItemRefs(commit);
|
||||
|
||||
return {
|
||||
id: commit.hash,
|
||||
parentIds: commit.parents,
|
||||
subject,
|
||||
message: messageWithLinks,
|
||||
author: commit.authorName,
|
||||
authorEmail: commit.authorEmail,
|
||||
authorIcon: avatarUrl ? Uri.parse(avatarUrl) : new ThemeIcon('account'),
|
||||
displayId: truncate(commit.hash, this.commitShortHashLength, false),
|
||||
timestamp: commit.authorDate?.getTime(),
|
||||
statistics: commit.shortStat ?? { files: 0, insertions: 0, deletions: 0 },
|
||||
references: references.length !== 0 ? references : undefined
|
||||
} satisfies SourceControlHistoryItem;
|
||||
} catch (err) {
|
||||
this.logger.error(`[GitHistoryProvider][resolveHistoryItem] Failed to resolve history item '${historyItemId}': ${err}`);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
async resolveHistoryItemChatContext(historyItemId: string): Promise<string | undefined> {
|
||||
try {
|
||||
const commitDetails = await this.repository.showCommit(historyItemId);
|
||||
|
||||
@@ -195,6 +195,11 @@ class MainThreadSCMHistoryProvider implements ISCMHistoryProvider {
|
||||
|
||||
constructor(private readonly proxy: ExtHostSCMShape, private readonly handle: number) { }
|
||||
|
||||
async resolveHistoryItem(historyItemId: string, token?: CancellationToken): Promise<ISCMHistoryItem | undefined> {
|
||||
const historyItem = await this.proxy.$resolveHistoryItem(this.handle, historyItemId, token ?? CancellationToken.None);
|
||||
return historyItem ? toISCMHistoryItem(historyItem) : undefined;
|
||||
}
|
||||
|
||||
async resolveHistoryItemChatContext(historyItemId: string, token?: CancellationToken): Promise<string | undefined> {
|
||||
return this.proxy.$resolveHistoryItemChatContext(this.handle, historyItemId, token ?? CancellationToken.None);
|
||||
}
|
||||
|
||||
@@ -2597,6 +2597,7 @@ export interface ExtHostSCMShape {
|
||||
$provideHistoryItemRefs(sourceControlHandle: number, historyItemRefs: string[] | undefined, token: CancellationToken): Promise<SCMHistoryItemRefDto[] | undefined>;
|
||||
$provideHistoryItems(sourceControlHandle: number, options: ISCMHistoryOptions, token: CancellationToken): Promise<SCMHistoryItemDto[] | undefined>;
|
||||
$provideHistoryItemChanges(sourceControlHandle: number, historyItemId: string, historyItemParentId: string | undefined, token: CancellationToken): Promise<SCMHistoryItemChangeDto[] | undefined>;
|
||||
$resolveHistoryItem(sourceControlHandle: number, historyItemId: string, token: CancellationToken): Promise<SCMHistoryItemDto | undefined>;
|
||||
$resolveHistoryItemChatContext(sourceControlHandle: number, historyItemId: string, token: CancellationToken): Promise<string | undefined>;
|
||||
$resolveHistoryItemRefsCommonAncestor(sourceControlHandle: number, historyItemRefs: string[], token: CancellationToken): Promise<string | undefined>;
|
||||
}
|
||||
|
||||
@@ -1089,6 +1089,19 @@ export class ExtHostSCM implements ExtHostSCMShape {
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
|
||||
async $resolveHistoryItem(sourceControlHandle: number, historyItemId: string, token: CancellationToken): Promise<SCMHistoryItemDto | undefined> {
|
||||
try {
|
||||
const historyProvider = this._sourceControls.get(sourceControlHandle)?.historyProvider;
|
||||
const historyItem = await historyProvider?.resolveHistoryItem(historyItemId, token);
|
||||
|
||||
return historyItem ? toSCMHistoryItemDto(historyItem) : undefined;
|
||||
}
|
||||
catch (err) {
|
||||
this.logService.error('ExtHostSCM#$resolveHistoryItem', err);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
async $resolveHistoryItemChatContext(sourceControlHandle: number, historyItemId: string, token: CancellationToken): Promise<string | undefined> {
|
||||
try {
|
||||
const historyProvider = this._sourceControls.get(sourceControlHandle)?.historyProvider;
|
||||
|
||||
@@ -25,6 +25,7 @@ export interface ISCMHistoryProvider {
|
||||
provideHistoryItemRefs(historyItemsRefs?: string[], token?: CancellationToken): Promise<ISCMHistoryItemRef[] | undefined>;
|
||||
provideHistoryItems(options: ISCMHistoryOptions, token?: CancellationToken): Promise<ISCMHistoryItem[] | undefined>;
|
||||
provideHistoryItemChanges(historyItemId: string, historyItemParentId: string | undefined, token?: CancellationToken): Promise<ISCMHistoryItemChange[] | undefined>;
|
||||
resolveHistoryItem(historyItemId: string, token?: CancellationToken): Promise<ISCMHistoryItem | undefined>;
|
||||
resolveHistoryItemChatContext(historyItemId: string, token?: CancellationToken): Promise<string | undefined>;
|
||||
resolveHistoryItemRefsCommonAncestor(historyItemRefs: string[], token?: CancellationToken): Promise<string | undefined>;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ declare module 'vscode' {
|
||||
provideHistoryItems(options: SourceControlHistoryOptions, token: CancellationToken): ProviderResult<SourceControlHistoryItem[]>;
|
||||
provideHistoryItemChanges(historyItemId: string, historyItemParentId: string | undefined, token: CancellationToken): ProviderResult<SourceControlHistoryItemChange[]>;
|
||||
|
||||
resolveHistoryItem(historyItemId: string, token: CancellationToken): ProviderResult<SourceControlHistoryItem>;
|
||||
resolveHistoryItemChatContext(historyItemId: string, token: CancellationToken): ProviderResult<string>;
|
||||
resolveHistoryItemRefsCommonAncestor(historyItemRefs: string[], token: CancellationToken): ProviderResult<string>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user