mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Fixed Broken Notebook Preview (#4895)
This commit is contained in:
@@ -305,11 +305,20 @@ export class PreviewFileCommand extends ProgressCommand {
|
|||||||
await this.executeWithProgress(
|
await this.executeWithProgress(
|
||||||
async (cancelToken: vscode.CancellationTokenSource) => {
|
async (cancelToken: vscode.CancellationTokenSource) => {
|
||||||
let contents = await fileNode.getFileContentsAsString(PreviewFileCommand.DefaultMaxSize);
|
let contents = await fileNode.getFileContentsAsString(PreviewFileCommand.DefaultMaxSize);
|
||||||
let doc = await this.openTextDocument(fspath.basename(fileNode.hdfsPath));
|
let fileName: string = fspath.basename(fileNode.hdfsPath);
|
||||||
let editor = await this.apiWrapper.showTextDocument(doc, vscode.ViewColumn.Active, false);
|
if (fspath.extname(fileName) !== '.ipynb') {
|
||||||
await editor.edit(edit => {
|
let doc = await this.openTextDocument(fileName);
|
||||||
edit.insert(new vscode.Position(0, 0), contents);
|
let editor = await this.apiWrapper.showTextDocument(doc, vscode.ViewColumn.Active, false);
|
||||||
});
|
await editor.edit(edit => {
|
||||||
|
edit.insert(new vscode.Position(0, 0), contents);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
let connectionProfile: azdata.IConnectionProfile = undefined;
|
||||||
|
if (context.type === constants.ObjectExplorerService) {
|
||||||
|
connectionProfile = context.explorerContext.connectionProfile;
|
||||||
|
}
|
||||||
|
await this.showNotebookDocument(fileName, connectionProfile, contents);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
localize('previewing', 'Generating preview'),
|
localize('previewing', 'Generating preview'),
|
||||||
false);
|
false);
|
||||||
@@ -322,6 +331,18 @@ export class PreviewFileCommand extends ProgressCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async showNotebookDocument(fileName: string, connectionProfile?: azdata.IConnectionProfile,
|
||||||
|
initialContent?: string
|
||||||
|
): Promise<azdata.nb.NotebookEditor> {
|
||||||
|
let docUri: vscode.Uri = getSaveableUri(this.apiWrapper, fileName, true)
|
||||||
|
.with({ scheme: constants.UNTITLED_SCHEMA });
|
||||||
|
return await azdata.nb.showNotebookDocument(docUri, {
|
||||||
|
connectionProfile: connectionProfile,
|
||||||
|
preview: false,
|
||||||
|
initialContent: initialContent
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private async openTextDocument(fileName: string): Promise<vscode.TextDocument> {
|
private async openTextDocument(fileName: string): Promise<vscode.TextDocument> {
|
||||||
let docUri: vscode.Uri = getSaveableUri(this.apiWrapper, fileName, true);
|
let docUri: vscode.Uri = getSaveableUri(this.apiWrapper, fileName, true);
|
||||||
if (docUri) {
|
if (docUri) {
|
||||||
|
|||||||
5
src/sql/azdata.proposed.d.ts
vendored
5
src/sql/azdata.proposed.d.ts
vendored
@@ -4155,6 +4155,11 @@ declare module 'azdata' {
|
|||||||
* Default kernel for notebook
|
* Default kernel for notebook
|
||||||
*/
|
*/
|
||||||
defaultKernel?: nb.IKernelSpec;
|
defaultKernel?: nb.IKernelSpec;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional content used to give an initial notebook state
|
||||||
|
*/
|
||||||
|
initialContent?: nb.INotebookContents | string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -169,6 +169,13 @@ export class ExtHostNotebookDocumentsAndEditors implements ExtHostNotebookDocume
|
|||||||
options.providerId = showOptions.providerId;
|
options.providerId = showOptions.providerId;
|
||||||
options.connectionProfile = showOptions.connectionProfile;
|
options.connectionProfile = showOptions.connectionProfile;
|
||||||
options.defaultKernel = showOptions.defaultKernel;
|
options.defaultKernel = showOptions.defaultKernel;
|
||||||
|
if (showOptions.initialContent) {
|
||||||
|
if (typeof (showOptions.initialContent) !== 'string') {
|
||||||
|
options.initialContent = JSON.stringify(showOptions.initialContent);
|
||||||
|
} else {
|
||||||
|
options.initialContent = showOptions.initialContent;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let id = await this._proxy.$tryShowNotebookDocument(uri, options);
|
let id = await this._proxy.$tryShowNotebookDocument(uri, options);
|
||||||
let editor = this.getEditor(id);
|
let editor = this.getEditor(id);
|
||||||
|
|||||||
@@ -404,7 +404,7 @@ export class MainThreadNotebookDocumentsAndEditors extends Disposable implements
|
|||||||
};
|
};
|
||||||
let isUntitled: boolean = uri.scheme === Schemas.untitled;
|
let isUntitled: boolean = uri.scheme === Schemas.untitled;
|
||||||
|
|
||||||
const fileInput = isUntitled ? this._untitledEditorService.createOrGet(uri, notebookModeId) :
|
const fileInput = isUntitled ? this._untitledEditorService.createOrGet(uri, notebookModeId, options.initialContent) :
|
||||||
this._editorService.createInput({ resource: uri, language: notebookModeId });
|
this._editorService.createInput({ resource: uri, language: notebookModeId });
|
||||||
let input = this._instantiationService.createInstance(NotebookInput, path.basename(uri.fsPath), uri, fileInput);
|
let input = this._instantiationService.createInstance(NotebookInput, path.basename(uri.fsPath), uri, fileInput);
|
||||||
input.isTrusted = isUntitled;
|
input.isTrusted = isUntitled;
|
||||||
|
|||||||
@@ -854,6 +854,7 @@ export interface INotebookShowOptions {
|
|||||||
providerId?: string;
|
providerId?: string;
|
||||||
connectionProfile?: azdata.IConnectionProfile;
|
connectionProfile?: azdata.IConnectionProfile;
|
||||||
defaultKernel?: azdata.nb.IKernelSpec;
|
defaultKernel?: azdata.nb.IKernelSpec;
|
||||||
|
initialContent?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ExtHostNotebookDocumentsAndEditorsShape {
|
export interface ExtHostNotebookDocumentsAndEditorsShape {
|
||||||
|
|||||||
Reference in New Issue
Block a user