diff --git a/extensions/mssql/src/main.ts b/extensions/mssql/src/main.ts index 0ef1e49d67..cfebb419db 100644 --- a/extensions/mssql/src/main.ts +++ b/extensions/mssql/src/main.ts @@ -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 { // 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 }); } diff --git a/extensions/notebook/src/extension.ts b/extensions/notebook/src/extension.ts index 4587346484..d77e1b99d2 100644 --- a/extensions/notebook/src/extension.ts +++ b/extensions/notebook/src/extension.ts @@ -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 { try { let filter = {}; @@ -123,7 +137,7 @@ async function addCell(cellType: azdata.nb.CellType): Promise { async function analyzeNotebook(oeContext?: azdata.ObjectExplorerContext): Promise { // 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,