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

@@ -3,8 +3,10 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Command } from 'vscode';
import { PickRemoteSourceOptions, PickRemoteSourceResult } from './typings/git-base';
import { GitBaseApi } from './git-base';
import { Repository } from './repository';
export async function pickRemoteSource(options: PickRemoteSourceOptions & { branch?: false | undefined }): Promise<string | undefined>;
export async function pickRemoteSource(options: PickRemoteSourceOptions & { branch: true }): Promise<PickRemoteSourceResult | undefined>;
@@ -16,6 +18,35 @@ export async function getRemoteSourceActions(url: string) {
return GitBaseApi.getAPI().getRemoteSourceActions(url);
}
export async function getRemoteSourceControlHistoryItemCommands(url: string) {
return GitBaseApi.getAPI().getRemoteSourceControlHistoryItemCommands(url);
export async function getRemoteSourceControlHistoryItemCommands(repository: Repository): Promise<Command[]> {
if (repository.remotes.length === 0) {
return [];
}
const getCommands = async (repository: Repository, remoteName: string): Promise<Command[] | undefined> => {
const remote = repository.remotes.find(r => r.name === remoteName && r.fetchUrl);
return remote ? GitBaseApi.getAPI().getRemoteSourceControlHistoryItemCommands(remote.fetchUrl!) : undefined;
};
// upstream -> origin -> first
return await getCommands(repository, 'upstream')
?? await getCommands(repository, 'origin')
?? await getCommands(repository, repository.remotes[0].name)
?? [];
}
export async function provideRemoteSourceLinks(repository: Repository, content: string): Promise<string | undefined> {
if (repository.remotes.length === 0) {
return undefined;
}
const getDocumentLinks = async (repository: Repository, remoteName: string): Promise<string | undefined> => {
const remote = repository.remotes.find(r => r.name === remoteName && r.fetchUrl);
return remote ? GitBaseApi.getAPI().provideRemoteSourceLinks(remote.fetchUrl!, content) : undefined;
};
// upstream -> origin -> first
return await getDocumentLinks(repository, 'upstream')
?? await getDocumentLinks(repository, 'origin')
?? await getDocumentLinks(repository, repository.remotes[0].name);
}