mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Introduces decorators to handle multiple authorities for URIs (#10507)
* Introduces decorators to handle multiple authorities for URIs * Check for undefined first * Add result type checking
This commit is contained in:
@@ -32,8 +32,6 @@ import { find } from 'vs/base/common/arrays';
|
||||
import { INativeEnvironmentService } from 'vs/platform/environment/node/environmentService';
|
||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
|
||||
const connectAuthority = 'connect';
|
||||
|
||||
export interface SqlArgs {
|
||||
_?: string[];
|
||||
authenticationType?: string
|
||||
@@ -44,6 +42,25 @@ export interface SqlArgs {
|
||||
provider?: string;
|
||||
}
|
||||
|
||||
//#region decorators
|
||||
|
||||
type PathHandler = (uri: URI) => Promise<boolean>;
|
||||
|
||||
const pathMappings: { [key: string]: PathHandler } = {};
|
||||
|
||||
interface PathHandlerOptions {
|
||||
path: string
|
||||
}
|
||||
|
||||
function pathHandler({ path }: PathHandlerOptions) {
|
||||
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
|
||||
const method: PathHandler = descriptor.value;
|
||||
|
||||
pathMappings[path] = method;
|
||||
};
|
||||
}
|
||||
//#endregion
|
||||
|
||||
export class CommandLineWorkbenchContribution implements IWorkbenchContribution, IURLHandler {
|
||||
|
||||
constructor(
|
||||
@@ -152,9 +169,27 @@ export class CommandLineWorkbenchContribution implements IWorkbenchContribution,
|
||||
}
|
||||
|
||||
public async handleURL(uri: URI): Promise<boolean> {
|
||||
// Catch file URLs
|
||||
let authority = uri.authority.toLowerCase();
|
||||
if (authority === connectAuthority) {
|
||||
let key = uri.authority.toLowerCase();
|
||||
|
||||
let method = pathMappings[key];
|
||||
|
||||
if (!method) {
|
||||
return false;
|
||||
}
|
||||
method = method.bind(this);
|
||||
const result = await method(uri);
|
||||
|
||||
if (typeof result !== 'boolean') {
|
||||
throw new Error('Invalid URL Handler used in commandLine code.');
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@pathHandler({
|
||||
path: 'connect'
|
||||
})
|
||||
public async handleConnect(uri: URI): Promise<boolean> {
|
||||
try {
|
||||
let args = this.parseProtocolArgs(uri);
|
||||
if (!args.server) {
|
||||
@@ -172,9 +207,6 @@ export class CommandLineWorkbenchContribution implements IWorkbenchContribution,
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private async confirmConnect(args: SqlArgs): Promise<boolean> {
|
||||
let detail = args && args.server ? localize('connectServerDetail', "This will connect to server {0}", args.server) : '';
|
||||
const result = await this.dialogService.confirm({
|
||||
|
||||
Reference in New Issue
Block a user