GitHub - link provider for various hovers (#237961)

* Initial implementation

* Refactor code, add link to blame decoration

* Add links to timeline hover

* Saving my work

* Update remote order for "Open on GitHub" action

* Bug fixes

* Add link provider for graph hover

* Rename method
This commit is contained in:
Ladislau Szomoru
2025-01-15 16:30:43 +01:00
committed by GitHub
parent 96e03e0d94
commit 57e8c28877
15 changed files with 142 additions and 46 deletions

View File

@@ -12,6 +12,7 @@ import { Branch, LogOptions, Ref, RefType } from './api/git';
import { emojify, ensureEmojis } from './emoji';
import { Commit } from './git';
import { OperationKind, OperationResult } from './operation';
import { provideRemoteSourceLinks } from './remoteSource';
function toSourceControlHistoryItemRef(repository: Repository, ref: Ref): SourceControlHistoryItemRef {
const rootUri = Uri.file(repository.root);
@@ -264,22 +265,33 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
await ensureEmojis();
return commits.map(commit => {
const historyItems: SourceControlHistoryItem[] = [];
for (const commit of commits) {
const message = emojify(commit.message);
const messageWithLinks = await provideRemoteSourceLinks(this.repository, message) ?? message;
const newLineIndex = message.indexOf('\n');
const subject = newLineIndex !== -1
? `${message.substring(0, newLineIndex)}\u2026`
: message;
const references = this._resolveHistoryItemRefs(commit);
return {
historyItems.push({
id: commit.hash,
parentIds: commit.parents,
message: emojify(commit.message),
subject,
message: messageWithLinks,
author: commit.authorName,
authorEmail: commit.authorEmail,
icon: new ThemeIcon('git-commit'),
displayId: getCommitShortHash(Uri.file(this.repository.root), commit.hash),
timestamp: commit.authorDate?.getTime(),
statistics: commit.shortStat ?? { files: 0, insertions: 0, deletions: 0 },
references: references.length !== 0 ? references : undefined
};
});
} satisfies SourceControlHistoryItem);
}
return historyItems;
} catch (err) {
this.logger.error(`[GitHistoryProvider][provideHistoryItems] Failed to get history items with options '${JSON.stringify(options)}': ${err}`);
return [];