mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-17 01:25:36 -05:00
* Fix initial build breaks from 1.67 merge (#2514) * Update yarn lock files * Update build scripts * Fix tsconfig * Build breaks * WIP * Update yarn lock files * Misc breaks * Updates to package.json * Breaks * Update yarn * Fix breaks * Breaks * Build breaks * Breaks * Breaks * Breaks * Breaks * Breaks * Missing file * Breaks * Breaks * Breaks * Breaks * Breaks * Fix several runtime breaks (#2515) * Missing files * Runtime breaks * Fix proxy ordering issue * Remove commented code * Fix breaks with opening query editor * Fix post merge break * Updates related to setup build and other breaks (#2516) * Fix bundle build issues * Update distro * Fix distro merge and update build JS files * Disable pipeline steps * Remove stats call * Update license name * Make new RPM dependencies a warning * Fix extension manager version checks * Update JS file * Fix a few runtime breaks * Fixes * Fix runtime issues * Fix build breaks * Update notebook tests (part 1) * Fix broken tests * Linting errors * Fix hygiene * Disable lint rules * Bump distro * Turn off smoke tests * Disable integration tests * Remove failing "activate" test * Remove failed test assertion * Disable other broken test * Disable query history tests * Disable extension unit tests * Disable failing tasks
200 lines
6.5 KiB
TypeScript
200 lines
6.5 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
import { QuickPickItem, window, QuickPick, QuickPickItemKind } from 'vscode';
|
|
import * as nls from 'vscode-nls';
|
|
import { RemoteSourceProvider, RemoteSource, PickRemoteSourceOptions, PickRemoteSourceResult } from './api/git-base';
|
|
import { Model } from './model';
|
|
import { throttle, debounce } from './decorators';
|
|
|
|
const localize = nls.loadMessageBundle();
|
|
|
|
async function getQuickPickResult<T extends QuickPickItem>(quickpick: QuickPick<T>): Promise<T | undefined> {
|
|
const result = await new Promise<T | undefined>(c => {
|
|
quickpick.onDidAccept(() => c(quickpick.selectedItems[0]));
|
|
quickpick.onDidHide(() => c(undefined));
|
|
quickpick.show();
|
|
});
|
|
|
|
quickpick.hide();
|
|
return result;
|
|
}
|
|
|
|
class RemoteSourceProviderQuickPick {
|
|
|
|
private quickpick: QuickPick<QuickPickItem & { remoteSource?: RemoteSource }> | undefined;
|
|
|
|
constructor(private provider: RemoteSourceProvider) { }
|
|
|
|
private ensureQuickPick() {
|
|
if (!this.quickpick) {
|
|
this.quickpick = window.createQuickPick();
|
|
this.quickpick.ignoreFocusOut = true;
|
|
if (this.provider.supportsQuery) {
|
|
this.quickpick.placeholder = this.provider.placeholder ?? localize('type to search', "Repository name (type to search)");
|
|
this.quickpick.onDidChangeValue(this.onDidChangeValue, this);
|
|
} else {
|
|
this.quickpick.placeholder = this.provider.placeholder ?? localize('type to filter', "Repository name");
|
|
}
|
|
}
|
|
}
|
|
|
|
@debounce(300)
|
|
private onDidChangeValue(): void {
|
|
this.query();
|
|
}
|
|
|
|
@throttle
|
|
private async query(): Promise<void> {
|
|
try {
|
|
const remoteSources = await this.provider.getRemoteSources(this.quickpick?.value) || [];
|
|
|
|
this.ensureQuickPick();
|
|
this.quickpick!.show();
|
|
|
|
if (remoteSources.length === 0) {
|
|
this.quickpick!.items = [{
|
|
label: localize('none found', "No remote repositories found."),
|
|
alwaysShow: true
|
|
}];
|
|
} else {
|
|
this.quickpick!.items = remoteSources.map(remoteSource => ({
|
|
label: remoteSource.icon ? `$(${remoteSource.icon}) ${remoteSource.name}` : remoteSource.name,
|
|
description: remoteSource.description || (typeof remoteSource.url === 'string' ? remoteSource.url : remoteSource.url[0]),
|
|
detail: remoteSource.detail,
|
|
remoteSource,
|
|
alwaysShow: true
|
|
}));
|
|
}
|
|
} catch (err) {
|
|
this.quickpick!.items = [{ label: localize('error', "$(error) Error: {0}", err.message), alwaysShow: true }];
|
|
console.error(err);
|
|
} finally {
|
|
this.quickpick!.busy = false;
|
|
}
|
|
}
|
|
|
|
async pick(): Promise<RemoteSource | undefined> {
|
|
await this.query();
|
|
const result = await getQuickPickResult(this.quickpick!);
|
|
return result?.remoteSource;
|
|
}
|
|
}
|
|
|
|
export async function pickRemoteSource(model: Model, options: PickRemoteSourceOptions & { branch?: false | undefined }): Promise<string | undefined>;
|
|
export async function pickRemoteSource(model: Model, options: PickRemoteSourceOptions & { branch: true }): Promise<PickRemoteSourceResult | undefined>;
|
|
export async function pickRemoteSource(model: Model, options: PickRemoteSourceOptions = {}): Promise<string | PickRemoteSourceResult | undefined> {
|
|
const quickpick = window.createQuickPick<(QuickPickItem & { provider?: RemoteSourceProvider; url?: string })>();
|
|
quickpick.ignoreFocusOut = true;
|
|
quickpick.title = options.title;
|
|
|
|
if (options.providerName) {
|
|
const provider = model.getRemoteProviders()
|
|
.filter(provider => provider.name === options.providerName)[0];
|
|
|
|
if (provider) {
|
|
return await pickProviderSource(provider, options);
|
|
}
|
|
}
|
|
|
|
const remoteProviders = model.getRemoteProviders()
|
|
.map(provider => ({ label: (provider.icon ? `$(${provider.icon}) ` : '') + (options.providerLabel ? options.providerLabel(provider) : provider.name), alwaysShow: true, provider }));
|
|
|
|
const recentSources: (QuickPickItem & { url?: string; timestamp: number })[] = [];
|
|
if (options.showRecentSources) {
|
|
for (const { provider } of remoteProviders) {
|
|
const sources = (await provider.getRecentRemoteSources?.() ?? []).map((item) => {
|
|
return {
|
|
...item,
|
|
label: (item.icon ? `$(${item.icon}) ` : '') + item.name,
|
|
url: typeof item.url === 'string' ? item.url : item.url[0],
|
|
};
|
|
});
|
|
recentSources.push(...sources);
|
|
}
|
|
}
|
|
|
|
const items = [
|
|
{ kind: QuickPickItemKind.Separator, label: localize('remote sources', 'remote sources') },
|
|
...remoteProviders,
|
|
{ kind: QuickPickItemKind.Separator, label: localize('recently opened', 'recently opened') },
|
|
...recentSources.sort((a, b) => b.timestamp - a.timestamp)
|
|
];
|
|
|
|
quickpick.placeholder = options.placeholder ?? (remoteProviders.length === 0
|
|
? localize('provide url', "Provide repository URL")
|
|
: localize('provide url or pick', "Provide repository URL or pick a repository source."));
|
|
|
|
const updatePicks = (value?: string) => {
|
|
if (value) {
|
|
const label = (typeof options.urlLabel === 'string' ? options.urlLabel : options.urlLabel?.(value)) ?? localize('url', "URL");
|
|
quickpick.items = [{
|
|
label: label,
|
|
description: value,
|
|
alwaysShow: true,
|
|
url: value
|
|
},
|
|
...items
|
|
];
|
|
} else {
|
|
quickpick.items = items;
|
|
}
|
|
};
|
|
|
|
quickpick.onDidChangeValue(updatePicks);
|
|
updatePicks();
|
|
|
|
const result = await getQuickPickResult(quickpick);
|
|
|
|
if (result) {
|
|
if (result.url) {
|
|
return result.url;
|
|
} else if (result.provider) {
|
|
return await pickProviderSource(result.provider, options);
|
|
}
|
|
}
|
|
|
|
return undefined;
|
|
}
|
|
|
|
async function pickProviderSource(provider: RemoteSourceProvider, options: PickRemoteSourceOptions = {}): Promise<string | PickRemoteSourceResult | undefined> {
|
|
const quickpick = new RemoteSourceProviderQuickPick(provider);
|
|
const remote = await quickpick.pick();
|
|
|
|
let url: string | undefined;
|
|
|
|
if (remote) {
|
|
if (typeof remote.url === 'string') {
|
|
url = remote.url;
|
|
} else if (remote.url.length > 0) {
|
|
url = await window.showQuickPick(remote.url, { ignoreFocusOut: true, placeHolder: localize('pick url', "Choose a URL to clone from.") });
|
|
}
|
|
}
|
|
|
|
if (!url || !options.branch) {
|
|
return url;
|
|
}
|
|
|
|
if (!provider.getBranches) {
|
|
return { url };
|
|
}
|
|
|
|
const branches = await provider.getBranches(url);
|
|
|
|
if (!branches) {
|
|
return { url };
|
|
}
|
|
|
|
const branch = await window.showQuickPick(branches, {
|
|
placeHolder: localize('branch name', "Branch name")
|
|
});
|
|
|
|
if (!branch) {
|
|
return { url };
|
|
}
|
|
|
|
return { url, branch };
|
|
}
|