Remove ApiWrapper from mssql extension (#11336)

This commit is contained in:
Charles Gagnon
2020-07-14 10:59:55 -07:00
committed by GitHub
parent cbf3cd7445
commit 1b616acfdb
13 changed files with 76 additions and 216 deletions

View File

@@ -8,7 +8,6 @@ import * as azdata from 'azdata';
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
import { ApiWrapper } from '../apiWrapper';
import { TreeNode } from './treeNodes';
import { QuestionTypes, IPrompter, IQuestion } from '../prompts/question';
import * as utils from '../utils';
@@ -63,12 +62,12 @@ export abstract class Command extends vscode.Disposable {
super(() => this.dispose());
if (typeof command === 'string') {
this.disposable = this.apiWrapper.registerCommand(command, (...args: any[]) => this._execute(command, ...args), this);
this.disposable = vscode.commands.registerCommand(command, (...args: any[]) => this._execute(command, ...args), this);
return;
}
const subscriptions = command.map(cmd => this.apiWrapper.registerCommand(cmd, (...args: any[]) => this._execute(cmd, ...args), this));
const subscriptions = command.map(cmd => vscode.commands.registerCommand(cmd, (...args: any[]) => this._execute(cmd, ...args), this));
this.disposable = vscode.Disposable.from(...subscriptions);
}
@@ -78,10 +77,6 @@ export abstract class Command extends vscode.Disposable {
}
}
protected get apiWrapper(): ApiWrapper {
return this.appContext.apiWrapper;
}
protected async preExecute(...args: any[]): Promise<any> {
return this.execute(...args);
}
@@ -138,12 +133,12 @@ export abstract class ProgressCommand extends Command {
): Promise<void> {
let disposables: vscode.Disposable[] = [];
const tokenSource = new vscode.CancellationTokenSource();
const statusBarItem = this.apiWrapper.createStatusBarItem(vscode.StatusBarAlignment.Left);
const statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
disposables.push(vscode.Disposable.from(statusBarItem));
statusBarItem.text = localize('progress', "$(sync~spin) {0}...", label);
if (isCancelable) {
const cancelCommandId = `cancelProgress${ProgressCommand.progressId++}`;
disposables.push(this.apiWrapper.registerCommand(cancelCommandId, async () => {
disposables.push(vscode.commands.registerCommand(cancelCommandId, async () => {
if (await this.confirmCancel()) {
tokenSource.cancel();
}
@@ -177,7 +172,7 @@ export abstract class ProgressCommand extends Command {
}
export function registerSearchServerCommand(appContext: AppContext): void {
appContext.apiWrapper.registerCommand('mssql.searchServers', () => {
vscode.commands.registerCommand('mssql.searchServers', () => {
vscode.window.showInputBox({
placeHolder: localize('mssql.searchServers', "Search Server Names")
}).then((stringSearch) => {
@@ -186,7 +181,7 @@ export function registerSearchServerCommand(appContext: AppContext): void {
}
});
});
appContext.apiWrapper.registerCommand('mssql.clearSearchServerResult', () => {
vscode.commands.registerCommand('mssql.clearSearchServerResult', () => {
vscode.commands.executeCommand('registeredServers.clearSearchServerResult');
});
}

View File

@@ -10,7 +10,6 @@ import * as fspath from 'path';
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
import { ApiWrapper } from '../apiWrapper';
import { Command, ICommandViewContext, ProgressCommand, ICommandObjectExplorerContext } from './command';
import { File, IFile, joinHdfsPath, FileType } from './fileSources';
import { FolderNode, FileNode, HdfsFileSourceNode } from './hdfsProvider';
@@ -23,9 +22,9 @@ import { TreeNode } from './treeNodes';
import { MssqlObjectExplorerNodeProvider } from './objectExplorerNodeProvider';
import { ManageAccessDialog } from '../hdfs/ui/hdfsManageAccessDialog';
async function getSaveableUri(apiWrapper: ApiWrapper, fileName: string, isPreview?: boolean): Promise<vscode.Uri> {
async function getSaveableUri(fileName: string, isPreview?: boolean): Promise<vscode.Uri> {
let root = utils.getUserHome();
let workspaceFolders = apiWrapper.workspaceFolders;
let workspaceFolders = vscode.workspace.workspaceFolders;
if (workspaceFolders && workspaceFolders.length > 0) {
root = workspaceFolders[0].uri.fsPath;
}
@@ -81,13 +80,13 @@ export class UploadFilesCommand extends ProgressCommand {
openLabel: localize('lblUploadFiles', "Upload"),
filters: filter
};
let fileUris: vscode.Uri[] = await this.apiWrapper.showOpenDialog(options);
let fileUris: vscode.Uri[] = await vscode.window.showOpenDialog(options);
if (fileUris) {
let files: IFile[] = await Promise.all(fileUris.map(uri => uri.fsPath).map(this.mapPathsToFiles()));
await this.executeWithProgress(
(cancelToken: vscode.CancellationTokenSource) => this.writeFiles(files, folderNode, cancelToken),
localize('uploading', "Uploading files to HDFS"), true,
() => this.apiWrapper.showInformationMessage(localize('uploadCanceled', "Upload operation was canceled")));
() => vscode.window.showInformationMessage(localize('uploadCanceled', "Upload operation was canceled")));
if (context.type === constants.ObjectExplorerService) {
let objectExplorerNode = await azdata.objectexplorer.getNode(context.explorerContext.connectionProfile.id, folderNode.getNodeInfo().nodePath);
await objectExplorerNode.refresh();
@@ -95,7 +94,7 @@ export class UploadFilesCommand extends ProgressCommand {
}
}
} catch (err) {
this.apiWrapper.showErrorMessage(
vscode.window.showErrorMessage(
localize('uploadError', "Error uploading files: {0}", utils.getErrorMessage(err, true)));
}
}
@@ -153,7 +152,7 @@ export class MkDirCommand extends ProgressCommand {
await this.executeWithProgress(
async (cancelToken: vscode.CancellationTokenSource) => this.mkDir(fileName, folderNode, cancelToken),
localize('makingDir', "Creating directory"), true,
() => this.apiWrapper.showInformationMessage(localize('mkdirCanceled', "Operation was canceled")));
() => vscode.window.showInformationMessage(localize('mkdirCanceled', "Operation was canceled")));
if (context.type === constants.ObjectExplorerService) {
let objectExplorerNode = await azdata.objectexplorer.getNode(context.explorerContext.connectionProfile.id, folderNode.getNodeInfo().nodePath);
await objectExplorerNode.refresh();
@@ -161,7 +160,7 @@ export class MkDirCommand extends ProgressCommand {
}
}
} catch (err) {
this.apiWrapper.showErrorMessage(
vscode.window.showErrorMessage(
localize('mkDirError', "Error on making directory: {0}", utils.getErrorMessage(err, true)));
}
}
@@ -216,10 +215,10 @@ export class DeleteFilesCommand extends Command {
await oeNodeToRefresh.refresh();
}
} else {
this.apiWrapper.showErrorMessage(LocalizedConstants.msgMissingNodeContext);
vscode.window.showErrorMessage(LocalizedConstants.msgMissingNodeContext);
}
} catch (err) {
this.apiWrapper.showErrorMessage(
vscode.window.showErrorMessage(
localize('deleteError', "Error on deleting files: {0}", utils.getErrorMessage(err, true)));
}
}
@@ -266,28 +265,28 @@ export class SaveFileCommand extends ProgressCommand {
try {
let fileNode = await getNode<FileNode>(context, this.appContext);
if (fileNode) {
let defaultUri = await getSaveableUri(this.apiWrapper, fspath.basename(fileNode.hdfsPath));
let fileUri: vscode.Uri = await this.apiWrapper.showSaveDialog({
let defaultUri = await getSaveableUri(fspath.basename(fileNode.hdfsPath));
let fileUri: vscode.Uri = await vscode.window.showSaveDialog({
defaultUri: defaultUri
});
if (fileUri) {
await this.executeWithProgress(
(cancelToken: vscode.CancellationTokenSource) => this.doSaveAndOpen(fileUri, fileNode, cancelToken),
localize('saving', "Saving HDFS Files"), true,
() => this.apiWrapper.showInformationMessage(localize('saveCanceled', "Save operation was canceled")));
() => vscode.window.showInformationMessage(localize('saveCanceled', "Save operation was canceled")));
}
} else {
this.apiWrapper.showErrorMessage(LocalizedConstants.msgMissingNodeContext);
vscode.window.showErrorMessage(LocalizedConstants.msgMissingNodeContext);
}
} catch (err) {
this.apiWrapper.showErrorMessage(
vscode.window.showErrorMessage(
localize('saveError', "Error on saving file: {0}", utils.getErrorMessage(err, true)));
}
}
private async doSaveAndOpen(fileUri: vscode.Uri, fileNode: FileNode, cancelToken: vscode.CancellationTokenSource): Promise<void> {
await fileNode.writeFileContentsToDisk(fileUri.fsPath, cancelToken);
await this.apiWrapper.executeCommand('vscode.open', fileUri);
await vscode.commands.executeCommand('vscode.open', fileUri);
}
}
@@ -311,8 +310,12 @@ export class PreviewFileCommand extends ProgressCommand {
let contents = await fileNode.getFileContentsAsString(PreviewFileCommand.DefaultMaxSize);
let fileName: string = fspath.basename(fileNode.hdfsPath);
if (fspath.extname(fileName) !== '.ipynb') {
let doc = await this.openTextDocument(fileName);
let editor = await this.apiWrapper.showTextDocument(doc, vscode.ViewColumn.Active, false);
const doc = await this.openTextDocument(fileName);
const options: vscode.TextDocumentShowOptions = {
viewColumn: vscode.ViewColumn.Active,
preserveFocus: false
};
const editor = await vscode.window.showTextDocument(doc, options);
await editor.edit(edit => {
edit.insert(new vscode.Position(0, 0), contents);
});
@@ -327,10 +330,10 @@ export class PreviewFileCommand extends ProgressCommand {
localize('previewing', "Generating preview"),
false);
} else {
this.apiWrapper.showErrorMessage(LocalizedConstants.msgMissingNodeContext);
vscode.window.showErrorMessage(LocalizedConstants.msgMissingNodeContext);
}
} catch (err) {
this.apiWrapper.showErrorMessage(
vscode.window.showErrorMessage(
localize('previewError', "Error on previewing file: {0}", utils.getErrorMessage(err, true)));
}
}
@@ -338,7 +341,7 @@ export class PreviewFileCommand extends ProgressCommand {
private async showNotebookDocument(fileName: string, connectionProfile?: azdata.IConnectionProfile,
initialContent?: string
): Promise<azdata.nb.NotebookEditor> {
let docUri: vscode.Uri = (await getSaveableUri(this.apiWrapper, fileName, true))
let docUri: vscode.Uri = (await getSaveableUri(fileName, true))
.with({ scheme: constants.UNTITLED_SCHEMA });
return await azdata.nb.showNotebookDocument(docUri, {
connectionProfile: connectionProfile,
@@ -348,10 +351,10 @@ export class PreviewFileCommand extends ProgressCommand {
}
private async openTextDocument(fileName: string): Promise<vscode.TextDocument> {
let docUri: vscode.Uri = await getSaveableUri(this.apiWrapper, fileName, true);
let docUri: vscode.Uri = await getSaveableUri(fileName, true);
if (docUri) {
docUri = docUri.with({ scheme: constants.UNTITLED_SCHEMA });
return await this.apiWrapper.openTextDocument(docUri);
return await vscode.workspace.openTextDocument(docUri);
} else {
// Can't reliably create a filename to save as so just use untitled
let language = fspath.extname(fileName);
@@ -359,7 +362,7 @@ export class PreviewFileCommand extends ProgressCommand {
// trim the '.'
language = language.substring(1);
}
return await this.apiWrapper.openTextDocument({
return await vscode.workspace.openTextDocument({
language: language
});
}
@@ -384,10 +387,10 @@ export class CopyPathCommand extends Command {
let path = node.hdfsPath;
vscode.env.clipboard.writeText(path);
} else {
this.apiWrapper.showErrorMessage(LocalizedConstants.msgMissingNodeContext);
vscode.window.showErrorMessage(LocalizedConstants.msgMissingNodeContext);
}
} catch (err) {
this.apiWrapper.showErrorMessage(
vscode.window.showErrorMessage(
localize('copyPathError', "Error on copying path: {0}", utils.getErrorMessage(err, true)));
}
}
@@ -403,12 +406,12 @@ export class ManageAccessCommand extends Command {
try {
let node = await getNode<HdfsFileSourceNode>(context, this.appContext);
if (node) {
new ManageAccessDialog(node.hdfsPath, node.fileSource, this.apiWrapper).openDialog();
new ManageAccessDialog(node.hdfsPath, node.fileSource).openDialog();
} else {
this.apiWrapper.showErrorMessage(LocalizedConstants.msgMissingNodeContext);
vscode.window.showErrorMessage(LocalizedConstants.msgMissingNodeContext);
}
} catch (err) {
this.apiWrapper.showErrorMessage(
vscode.window.showErrorMessage(
localize('manageAccessError', "An unexpected error occurred while opening the Manage Access dialog: {0}", utils.getErrorMessage(err, true)));
}
}

View File

@@ -197,7 +197,7 @@ export class MssqlObjectExplorerNodeProvider extends ProviderBase implements azd
try {
let session = this.getSqlClusterSessionForNode(node);
if (!session) {
this.appContext.apiWrapper.showErrorMessage(localize('sessionNotFound', "Session for node {0} does not exist", node.nodePathValue));
vscode.window.showErrorMessage(localize('sessionNotFound', "Session for node {0} does not exist", node.nodePathValue));
} else {
let nodeInfo = node.getNodeInfo();
let expandInfo: azdata.ExpandNodeInfo = {