Skip to content

Commit

Permalink
microsoft#4511: Streamline untitled notebook count (microsoft#4727)
Browse files Browse the repository at this point in the history
  • Loading branch information
rajmusuku authored Mar 27, 2019
1 parent 102b48c commit dd8922c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
11 changes: 5 additions & 6 deletions extensions/mssql/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const statusView = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.L
const jupyterNotebookProviderId = 'jupyter';
const msgSampleCodeDataFrame = localize('msgSampleCodeDataFrame', 'This sample code loads the file into a data frame and shows the first 10 results.');

let untitledCounter = 0;

export async function activate(context: vscode.ExtensionContext): Promise<MssqlExtensionApi> {
// lets make sure we support this platform first
Expand Down Expand Up @@ -181,18 +180,18 @@ function saveProfileAndCreateNotebook(profile: azdata.IConnectionProfile): Promi
}

function findNextUntitledEditorName(): string {
let nextVal = untitledCounter;
let nextVal = 0;
// 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 title = `Notebook-${nextVal}`;
let hasNotebookDoc = azdata.nb.notebookDocuments.findIndex(doc => doc.isUntitled && doc.fileName === title) > -1;
if (!hasTextDoc && !hasNotebookDoc) {
untitledCounter = nextVal;
if (!hasNotebookDoc) {
return title;
}
nextVal++;
}
}

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
Expand Down
13 changes: 6 additions & 7 deletions extensions/notebook/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ 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 untitledCounter = 0;

export let controller: JupyterController;

Expand Down Expand Up @@ -72,16 +71,15 @@ function newNotebook(connectionProfile: azdata.IConnectionProfile) {
}

function findNextUntitledEditorName(): string {
let nextVal = untitledCounter;
let nextVal = 0;
// 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 title = `Notebook-${nextVal}`;
let hasNotebookDoc = azdata.nb.notebookDocuments.findIndex(doc => doc.isUntitled && doc.fileName === title) > -1;
if (!hasTextDoc && !hasNotebookDoc) {
untitledCounter = nextVal;
if (!hasNotebookDoc) {
return title;
}
nextVal++;
}
}

Expand Down Expand Up @@ -137,7 +135,8 @@ 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-${untitledCounter++}`);
let title = findNextUntitledEditorName();
let untitledUri = vscode.Uri.parse(`untitled:${title}`);

let editor = await azdata.nb.showNotebookDocument(untitledUri, {
connectionProfile: oeContext ? oeContext.connectionProfile : undefined,
Expand Down

0 comments on commit dd8922c

Please sign in to comment.