Fix #4505 Notebooks: New Notebook will not work if existing untitled notebooks are rehydrated (#4506)

* Fix #4505 Notebooks: New Notebook will not work if existing untitled notebooks are rehydrated
* Also fixes #4508
* Unify behavior across New Notebook entry points
- Use Notebook-{n} as the standard in both entry points
- Use SQL as default provider in both
- Ensure both check for other names and only use free number
This commit is contained in:
Kevin Cunnane
2019-03-14 14:27:08 -07:00
committed by GitHub
parent d91f4d5748
commit efaa2c0e3f
2 changed files with 33 additions and 12 deletions

View File

@@ -172,19 +172,27 @@ function saveProfileAndCreateNotebook(profile: azdata.IConnectionProfile): Promi
return handleNewNotebookTask(undefined, profile);
}
function findNextUntitledEditorName(): string {
let nextVal = untitledCounter;
// Note: this will go forever if it's coded wrong, or you have inifinite Untitled notebooks!
while (true) {
let title = `Notebook-${nextVal++}`;
let hasTextDoc = vscode.workspace.textDocuments.findIndex(doc => doc.isUntitled && doc.fileName === title) > -1;
let hasNotebookDoc = azdata.nb.notebookDocuments.findIndex(doc => doc.isUntitled && doc.fileName === title) > -1;
if (!hasTextDoc && !hasNotebookDoc) {
untitledCounter = nextVal;
return title;
}
}
}
async function handleNewNotebookTask(oeContext?: azdata.ObjectExplorerContext, profile?: azdata.IConnectionProfile): Promise<void> {
// Ensure we get a unique ID for the notebook. For now we're using a different prefix to the built-in untitled files
// to handle this. We should look into improving this in the future
let untitledUri = vscode.Uri.parse(`untitled:Notebook-${untitledCounter++}`);
let title = findNextUntitledEditorName();
let untitledUri = vscode.Uri.parse(`untitled:${title}`);
let editor = await azdata.nb.showNotebookDocument(untitledUri, {
connectionProfile: profile,
providerId: jupyterNotebookProviderId,
preview: false,
defaultKernel: {
name: 'pyspark3kernel',
display_name: 'PySpark3',
language: 'python'
}
preview: false
});
if (oeContext && oeContext.nodeInfo && oeContext.nodeInfo.nodePath) {
// Get the file path after '/HDFS'
@@ -221,7 +229,6 @@ async function handleOpenNotebookTask(profile: azdata.IConnectionProfile): Promi
} else {
await azdata.nb.showNotebookDocument(fileUri, {
connectionProfile: profile,
providerId: jupyterNotebookProviderId,
preview: false
});
}

View File

@@ -20,7 +20,7 @@ const JUPYTER_NOTEBOOK_PROVIDER = 'jupyter';
const msgSampleCodeDataFrame = localize('msgSampleCodeDataFrame', 'This sample code loads the file into a data frame and shows the first 10 results.');
const noNotebookVisible = localize('noNotebookVisible', 'No notebook editor is active');
let counter = 0;
let untitledCounter = 0;
export let controller: JupyterController;
@@ -54,7 +54,7 @@ export function activate(extensionContext: vscode.ExtensionContext) {
}
function newNotebook(connectionProfile: azdata.IConnectionProfile) {
let title = `Untitled-${counter++}`;
let title = findNextUntitledEditorName();
let untitledUri = vscode.Uri.parse(`untitled:${title}`);
let options: azdata.nb.NotebookShowOptions = connectionProfile ? {
viewColumn: null,
@@ -71,6 +71,20 @@ function newNotebook(connectionProfile: azdata.IConnectionProfile) {
});
}
function findNextUntitledEditorName(): string {
let nextVal = untitledCounter;
// Note: this will go forever if it's coded wrong, or you have infinite Untitled notebooks!
while (true) {
let title = `Notebook-${nextVal++}`;
let hasTextDoc = vscode.workspace.textDocuments.findIndex(doc => doc.isUntitled && doc.fileName === title) > -1;
let hasNotebookDoc = azdata.nb.notebookDocuments.findIndex(doc => doc.isUntitled && doc.fileName === title) > -1;
if (!hasTextDoc && !hasNotebookDoc) {
untitledCounter = nextVal;
return title;
}
}
}
async function openNotebook(): Promise<void> {
try {
let filter = {};
@@ -123,7 +137,7 @@ async function addCell(cellType: azdata.nb.CellType): Promise<void> {
async function analyzeNotebook(oeContext?: azdata.ObjectExplorerContext): Promise<void> {
// Ensure we get a unique ID for the notebook. For now we're using a different prefix to the built-in untitled files
// to handle this. We should look into improving this in the future
let untitledUri = vscode.Uri.parse(`untitled:Notebook-${counter++}`);
let untitledUri = vscode.Uri.parse(`untitled:Notebook-${untitledCounter++}`);
let editor = await azdata.nb.showNotebookDocument(untitledUri, {
connectionProfile: oeContext ? oeContext.connectionProfile : undefined,