mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 02:58:56 +01:00
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:
@@ -5,7 +5,7 @@
|
||||
|
||||
import { Command, Disposable, commands } from 'vscode';
|
||||
import { Model } from '../model';
|
||||
import { getRemoteSourceActions, getRemoteSourceControlHistoryItemCommands, pickRemoteSource } from '../remoteSource';
|
||||
import { getRemoteSourceActions, getRemoteSourceControlHistoryItemCommands, pickRemoteSource, provideRemoteSourceLinks } from '../remoteSource';
|
||||
import { GitBaseExtensionImpl } from './extension';
|
||||
import { API, PickRemoteSourceOptions, PickRemoteSourceResult, RemoteSourceAction, RemoteSourceProvider } from './git-base';
|
||||
|
||||
@@ -21,10 +21,14 @@ export class ApiImpl implements API {
|
||||
return getRemoteSourceActions(this._model, url);
|
||||
}
|
||||
|
||||
getRemoteSourceControlHistoryItemCommands(url: string): Promise<Command[]> {
|
||||
getRemoteSourceControlHistoryItemCommands(url: string): Promise<Command[] | undefined> {
|
||||
return getRemoteSourceControlHistoryItemCommands(this._model, url);
|
||||
}
|
||||
|
||||
provideRemoteSourceLinks(url: string, content: string): Promise<string> {
|
||||
return provideRemoteSourceLinks(this._model, url, content);
|
||||
}
|
||||
|
||||
registerRemoteSourceProvider(provider: RemoteSourceProvider): Disposable {
|
||||
return this._model.registerRemoteSourceProvider(provider);
|
||||
}
|
||||
|
||||
4
extensions/git-base/src/api/git-base.d.ts
vendored
4
extensions/git-base/src/api/git-base.d.ts
vendored
@@ -9,7 +9,8 @@ export { ProviderResult } from 'vscode';
|
||||
export interface API {
|
||||
registerRemoteSourceProvider(provider: RemoteSourceProvider): Disposable;
|
||||
getRemoteSourceActions(url: string): Promise<RemoteSourceAction[]>;
|
||||
getRemoteSourceControlHistoryItemCommands(url: string): Promise<Command[]>;
|
||||
getRemoteSourceControlHistoryItemCommands(url: string): Promise<Command[] | undefined>;
|
||||
provideRemoteSourceLinks(url: string, content: string): Promise<string | undefined>;
|
||||
pickRemoteSource(options: PickRemoteSourceOptions): Promise<string | PickRemoteSourceResult | undefined>;
|
||||
}
|
||||
|
||||
@@ -85,4 +86,5 @@ export interface RemoteSourceProvider {
|
||||
getRemoteSourceControlHistoryItemCommands?(url: string): ProviderResult<Command[]>;
|
||||
getRecentRemoteSources?(query?: string): ProviderResult<RecentRemoteSource[]>;
|
||||
getRemoteSources(query?: string): ProviderResult<RemoteSource[]>;
|
||||
provideRemoteSourceLinks?(url: string, content: string): Promise<string | undefined>;
|
||||
}
|
||||
|
||||
@@ -123,18 +123,30 @@ export async function getRemoteSourceActions(model: Model, url: string): Promise
|
||||
return remoteSourceActions;
|
||||
}
|
||||
|
||||
export async function getRemoteSourceControlHistoryItemCommands(model: Model, url: string): Promise<Command[]> {
|
||||
export async function getRemoteSourceControlHistoryItemCommands(model: Model, url: string): Promise<Command[] | undefined> {
|
||||
const providers = model.getRemoteProviders();
|
||||
|
||||
const remoteSourceCommands = [];
|
||||
for (const provider of providers) {
|
||||
const providerCommands = await provider.getRemoteSourceControlHistoryItemCommands?.(url);
|
||||
if (providerCommands?.length) {
|
||||
remoteSourceCommands.push(...providerCommands);
|
||||
}
|
||||
remoteSourceCommands.push(...(await provider.getRemoteSourceControlHistoryItemCommands?.(url) ?? []));
|
||||
}
|
||||
|
||||
return remoteSourceCommands;
|
||||
return remoteSourceCommands.length > 0 ? remoteSourceCommands : undefined;
|
||||
}
|
||||
|
||||
export async function provideRemoteSourceLinks(model: Model, url: string, content: string): Promise<string> {
|
||||
const providers = model.getRemoteProviders();
|
||||
|
||||
for (const provider of providers) {
|
||||
const parsedContent = await provider.provideRemoteSourceLinks?.(url, content);
|
||||
if (!parsedContent) {
|
||||
continue;
|
||||
}
|
||||
|
||||
content = parsedContent;
|
||||
}
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
export async function pickRemoteSource(model: Model, options: PickRemoteSourceOptions & { branch?: false | undefined }): Promise<string | undefined>;
|
||||
|
||||
Reference in New Issue
Block a user