mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-02 09:35:40 -05:00
Add more notebook extension tests (#11143)
* more tests * More tests * More tests * Add prompt tests
This commit is contained in:
@@ -69,6 +69,14 @@ export class ApiWrapper {
|
||||
return azdata.nb.notebookDocuments;
|
||||
}
|
||||
|
||||
public getActiveNotebookEditor(): azdata.nb.NotebookEditor {
|
||||
return azdata.nb.activeNotebookEditor;
|
||||
}
|
||||
|
||||
public showNotebookDocument(uri: vscode.Uri, showOptions?: azdata.nb.NotebookShowOptions): Thenable<azdata.nb.NotebookEditor> {
|
||||
return azdata.nb.showNotebookDocument(uri, showOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the configuration for a extensionName
|
||||
* @param extensionName The string name of the extension to get the configuration for
|
||||
@@ -95,4 +103,8 @@ export class ApiWrapper {
|
||||
public createTreeView<T>(viewId: string, options: vscode.TreeViewOptions<T>): vscode.TreeView<T> {
|
||||
return vscode.window.createTreeView(viewId, options);
|
||||
}
|
||||
|
||||
public showQuickPick(items: string[] | Thenable<string[]>, options?: vscode.QuickPickOptions, token?: vscode.CancellationToken): Thenable<string | undefined> {
|
||||
return vscode.window.showQuickPick(items, options, token);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,19 +12,10 @@ import { NotebookUtils } from './notebookUtils';
|
||||
*/
|
||||
export class AppContext {
|
||||
|
||||
private serviceMap: Map<string, any> = new Map();
|
||||
public readonly notebookUtils: NotebookUtils;
|
||||
|
||||
constructor(public readonly extensionContext: vscode.ExtensionContext, public readonly apiWrapper: ApiWrapper) {
|
||||
this.apiWrapper = apiWrapper || new ApiWrapper();
|
||||
this.notebookUtils = new NotebookUtils(apiWrapper);
|
||||
}
|
||||
|
||||
public getService<T>(serviceName: string): T {
|
||||
return this.serviceMap.get(serviceName) as T;
|
||||
}
|
||||
|
||||
public registerService<T>(serviceName: string, service: T): void {
|
||||
this.serviceMap.set(serviceName, service);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,46 +64,46 @@ export class NotebookUtils {
|
||||
|
||||
public async runActiveCell(): Promise<void> {
|
||||
try {
|
||||
let notebook = azdata.nb.activeNotebookEditor;
|
||||
let notebook = this._apiWrapper.getActiveNotebookEditor();
|
||||
if (notebook) {
|
||||
await notebook.runCell();
|
||||
} else {
|
||||
throw new Error(noNotebookVisible);
|
||||
}
|
||||
} catch (err) {
|
||||
vscode.window.showErrorMessage(getErrorMessage(err));
|
||||
this._apiWrapper.showErrorMessage(getErrorMessage(err));
|
||||
}
|
||||
}
|
||||
|
||||
public async clearActiveCellOutput(): Promise<void> {
|
||||
try {
|
||||
let notebook = azdata.nb.activeNotebookEditor;
|
||||
let notebook = this._apiWrapper.getActiveNotebookEditor();
|
||||
if (notebook) {
|
||||
await notebook.clearOutput();
|
||||
} else {
|
||||
throw new Error(noNotebookVisible);
|
||||
}
|
||||
} catch (err) {
|
||||
vscode.window.showErrorMessage(getErrorMessage(err));
|
||||
this._apiWrapper.showErrorMessage(getErrorMessage(err));
|
||||
}
|
||||
}
|
||||
|
||||
public async runAllCells(startCell?: azdata.nb.NotebookCell, endCell?: azdata.nb.NotebookCell): Promise<void> {
|
||||
try {
|
||||
let notebook = azdata.nb.activeNotebookEditor;
|
||||
let notebook = this._apiWrapper.getActiveNotebookEditor();
|
||||
if (notebook) {
|
||||
await notebook.runAllCells(startCell, endCell);
|
||||
} else {
|
||||
throw new Error(noNotebookVisible);
|
||||
}
|
||||
} catch (err) {
|
||||
vscode.window.showErrorMessage(getErrorMessage(err));
|
||||
this._apiWrapper.showErrorMessage(getErrorMessage(err));
|
||||
}
|
||||
}
|
||||
|
||||
public async addCell(cellType: azdata.nb.CellType): Promise<void> {
|
||||
try {
|
||||
let notebook = azdata.nb.activeNotebookEditor;
|
||||
let notebook = this._apiWrapper.getActiveNotebookEditor();
|
||||
if (notebook) {
|
||||
await notebook.edit((editBuilder: azdata.nb.NotebookEditorEdit) => {
|
||||
// TODO should prompt and handle cell placement
|
||||
@@ -116,7 +116,7 @@ export class NotebookUtils {
|
||||
throw new Error(noNotebookVisible);
|
||||
}
|
||||
} catch (err) {
|
||||
vscode.window.showErrorMessage(getErrorMessage(err));
|
||||
this._apiWrapper.showErrorMessage(getErrorMessage(err));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ export class NotebookUtils {
|
||||
let title = this.findNextUntitledEditorName();
|
||||
let untitledUri = vscode.Uri.parse(`untitled:${title}`);
|
||||
|
||||
let editor = await azdata.nb.showNotebookDocument(untitledUri, {
|
||||
let editor = await this._apiWrapper.showNotebookDocument(untitledUri, {
|
||||
connectionProfile: oeContext ? oeContext.connectionProfile : undefined,
|
||||
providerId: JUPYTER_NOTEBOOK_PROVIDER,
|
||||
preview: false,
|
||||
@@ -142,8 +142,7 @@ export class NotebookUtils {
|
||||
if (hdfsPath.length > 0) {
|
||||
let analyzeCommand = '#' + msgSampleCodeDataFrame + os.EOL + 'df = (spark.read.option("inferSchema", "true")'
|
||||
+ os.EOL + '.option("header", "true")' + os.EOL + '.csv("{0}"))' + os.EOL + 'df.show(10)';
|
||||
|
||||
editor.edit(editBuilder => {
|
||||
await editor.edit(editBuilder => {
|
||||
editBuilder.insertCell({
|
||||
cell_type: 'code',
|
||||
source: analyzeCommand.replace('{0}', hdfsPath)
|
||||
|
||||
Reference in New Issue
Block a user