mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-20 09:35:38 -05:00
159 lines
5.8 KiB
TypeScript
159 lines
5.8 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 * as vscode from 'vscode';
|
|
import * as azdata from 'azdata';
|
|
|
|
/**
|
|
* Wrapper class to act as a facade over VSCode and Data APIs and allow us to test / mock callbacks into
|
|
* this API from our code
|
|
*
|
|
* @export
|
|
* ApiWrapper
|
|
*/
|
|
export class ApiWrapper {
|
|
|
|
// Data APIs
|
|
public registerConnectionProvider(provider: azdata.ConnectionProvider): vscode.Disposable {
|
|
return azdata.dataprotocol.registerConnectionProvider(provider);
|
|
}
|
|
|
|
public registerObjectExplorerProvider(provider: azdata.ObjectExplorerProvider): vscode.Disposable {
|
|
return azdata.dataprotocol.registerObjectExplorerProvider(provider);
|
|
}
|
|
|
|
public registerTaskServicesProvider(provider: azdata.TaskServicesProvider): vscode.Disposable {
|
|
return azdata.dataprotocol.registerTaskServicesProvider(provider);
|
|
}
|
|
|
|
public registerCapabilitiesServiceProvider(provider: azdata.CapabilitiesProvider): vscode.Disposable {
|
|
return azdata.dataprotocol.registerCapabilitiesServiceProvider(provider);
|
|
}
|
|
|
|
public registerTaskHandler(taskId: string, handler: (profile: azdata.IConnectionProfile) => void): void {
|
|
azdata.tasks.registerTask(taskId, handler);
|
|
}
|
|
|
|
public startBackgroundOperation(operationInfo: azdata.BackgroundOperationInfo): void {
|
|
azdata.tasks.startBackgroundOperation(operationInfo);
|
|
}
|
|
|
|
public getActiveConnections(): Thenable<azdata.connection.Connection[]> {
|
|
return azdata.connection.getActiveConnections();
|
|
}
|
|
|
|
public getCurrentConnection(): Thenable<azdata.connection.ConnectionProfile> {
|
|
return azdata.connection.getCurrentConnection();
|
|
}
|
|
|
|
// VSCode APIs
|
|
public createTerminal(name?: string, shellPath?: string, shellArgs?: string[]): vscode.Terminal {
|
|
return vscode.window.createTerminal(name, shellPath, shellArgs);
|
|
}
|
|
|
|
public createTerminalWithOptions(options: vscode.TerminalOptions): vscode.Terminal {
|
|
return vscode.window.createTerminal(options);
|
|
}
|
|
|
|
public executeCommand(command: string, ...rest: any[]): Thenable<any> {
|
|
return vscode.commands.executeCommand(command, ...rest);
|
|
}
|
|
|
|
public getFilePathRelativeToWorkspace(uri: vscode.Uri): string {
|
|
return vscode.workspace.asRelativePath(uri);
|
|
}
|
|
|
|
public getWorkspaceFolders(): readonly vscode.WorkspaceFolder[] {
|
|
return vscode.workspace.workspaceFolders;
|
|
}
|
|
|
|
public getWorkspacePathFromUri(uri: vscode.Uri): string | undefined {
|
|
let workspaceFolder = vscode.workspace.getWorkspaceFolder(uri);
|
|
return workspaceFolder ? workspaceFolder.uri.fsPath : undefined;
|
|
}
|
|
|
|
public registerCommand(command: string, callback: (...args: any[]) => any, thisArg?: any): vscode.Disposable {
|
|
return vscode.commands.registerCommand(command, callback, thisArg);
|
|
}
|
|
|
|
public registerDocumentOpenHandler(handler: (doc: vscode.TextDocument) => any): vscode.Disposable {
|
|
return vscode.workspace.onDidOpenTextDocument(handler);
|
|
}
|
|
|
|
public registerTreeDataProvider<T>(viewId: string, treeDataProvider: vscode.TreeDataProvider<T>): vscode.Disposable {
|
|
return vscode.window.registerTreeDataProvider(viewId, treeDataProvider);
|
|
}
|
|
|
|
/**
|
|
* Parse uri
|
|
*/
|
|
public parseUri(uri: string): vscode.Uri {
|
|
return vscode.Uri.parse(uri);
|
|
}
|
|
|
|
public showOpenDialog(options: vscode.OpenDialogOptions): Thenable<vscode.Uri[] | undefined> {
|
|
return vscode.window.showOpenDialog(options);
|
|
}
|
|
|
|
public showSaveDialog(options: vscode.SaveDialogOptions): Thenable<vscode.Uri> {
|
|
return vscode.window.showSaveDialog(options);
|
|
}
|
|
|
|
public createDialog(title: string): azdata.window.Dialog {
|
|
return azdata.window.createModelViewDialog(title);
|
|
}
|
|
|
|
public openDialog(dialog: azdata.window.Dialog): void {
|
|
return azdata.window.openDialog(dialog);
|
|
}
|
|
|
|
public closeDialog(dialog: azdata.window.Dialog): void {
|
|
return azdata.window.closeDialog(dialog);
|
|
}
|
|
|
|
public openTextDocument(uri: vscode.Uri): Thenable<vscode.TextDocument>;
|
|
public openTextDocument(options: { language?: string; content?: string; }): Thenable<vscode.TextDocument>;
|
|
public openTextDocument(uriOrOptions: any): Thenable<vscode.TextDocument> {
|
|
return vscode.workspace.openTextDocument(uriOrOptions);
|
|
}
|
|
|
|
public showTextDocument(document: vscode.TextDocument, column?: vscode.ViewColumn, preserveFocus?: boolean, preview?: boolean): Thenable<vscode.TextEditor> {
|
|
let options: vscode.TextDocumentShowOptions = {
|
|
viewColumn: column,
|
|
preserveFocus: preserveFocus,
|
|
preview: preview
|
|
};
|
|
return vscode.window.showTextDocument(document, options);
|
|
}
|
|
|
|
public showErrorMessage(message: string, ...items: string[]): Thenable<string | undefined> {
|
|
return vscode.window.showErrorMessage(message, ...items);
|
|
}
|
|
|
|
public showWarningMessage(message: string, ...items: string[]): Thenable<string | undefined> {
|
|
return vscode.window.showWarningMessage(message, { modal: true }, ...items);
|
|
}
|
|
|
|
public showInformationMessage(message: string, ...items: string[]): Thenable<string | undefined> {
|
|
return vscode.window.showInformationMessage(message, ...items);
|
|
}
|
|
|
|
public createStatusBarItem(alignment?: vscode.StatusBarAlignment, priority?: number): vscode.StatusBarItem {
|
|
return vscode.window.createStatusBarItem(alignment, priority);
|
|
}
|
|
|
|
public get workspaceFolders(): readonly vscode.WorkspaceFolder[] {
|
|
return vscode.workspace.workspaceFolders;
|
|
}
|
|
|
|
public createOutputChannel(name: string): vscode.OutputChannel {
|
|
return vscode.window.createOutputChannel(name);
|
|
}
|
|
|
|
public registerCompletionItemProvider(selector: vscode.DocumentSelector, provider: vscode.CompletionItemProvider, ...triggerCharacters: string[]): vscode.Disposable {
|
|
return vscode.languages.registerCompletionItemProvider(selector, provider, ...triggerCharacters);
|
|
}
|
|
}
|