diff --git a/src/sql/media/icons/run-with-parameters.svg b/src/sql/media/icons/run-with-parameters.svg
index 93405cadd9..45fab0712f 100644
--- a/src/sql/media/icons/run-with-parameters.svg
+++ b/src/sql/media/icons/run-with-parameters.svg
@@ -1,4 +1,4 @@
diff --git a/src/sql/workbench/contrib/notebook/browser/notebookActions.ts b/src/sql/workbench/contrib/notebook/browser/notebookActions.ts
index cddfb2c31b..d49cb707de 100644
--- a/src/sql/workbench/contrib/notebook/browser/notebookActions.ts
+++ b/src/sql/workbench/contrib/notebook/browser/notebookActions.ts
@@ -364,8 +364,8 @@ export class RunParametersAction extends TooltipFromLabelAction {
public async openParameterizedNotebook(uri: URI): Promise {
const editor = this._notebookService.findNotebookEditor(uri);
let modelContents = JSON.stringify(editor.model.toJSON());
- let basename = path.basename(uri.fsPath);
- let untitledUri = uri.with({ authority: '', scheme: 'untitled', path: basename });
+ let untitledUriPath = this._notebookService.getUntitledUriPath(path.basename(uri.fsPath));
+ let untitledUri = uri.with({ authority: '', scheme: 'untitled', path: untitledUriPath });
this._notebookService.openNotebook(untitledUri, {
initialContent: modelContents,
preserveFocus: true
diff --git a/src/sql/workbench/contrib/notebook/test/browser/notebookService.test.ts b/src/sql/workbench/contrib/notebook/test/browser/notebookService.test.ts
index 3a5acb5544..2e2d66756e 100644
--- a/src/sql/workbench/contrib/notebook/test/browser/notebookService.test.ts
+++ b/src/sql/workbench/contrib/notebook/test/browser/notebookService.test.ts
@@ -561,6 +561,14 @@ suite.skip('NotebookService:', function (): void {
mock.verifyAll();
});
+
+ test('verify getUntitledUriPath gets the proper next title', () => {
+ let getUntitledUriPathSpy = sinon.spy(notebookService, 'getUntitledUriPath');
+ notebookService.getUntitledUriPath('title.ipynb');
+ sinon.assert.calledOnce(getUntitledUriPathSpy);
+ assert.equal(getUntitledUriPathSpy, 'title-0.ipynb');
+ });
+
});
function unRegisterProviders(notebookService: NotebookService) {
diff --git a/src/sql/workbench/contrib/notebook/test/stubs.ts b/src/sql/workbench/contrib/notebook/test/stubs.ts
index 0c1d5d0b78..d799f184cb 100644
--- a/src/sql/workbench/contrib/notebook/test/stubs.ts
+++ b/src/sql/workbench/contrib/notebook/test/stubs.ts
@@ -303,6 +303,9 @@ export class NotebookServiceStub implements INotebookService {
notifyCellExecutionStarted(): void {
throw new Error('Method not implemented.');
}
+ getUntitledUriPath(originalTitle: string): string {
+ throw new Error('Method not implemented.');
+ }
}
export class ClientSessionStub implements IClientSession {
diff --git a/src/sql/workbench/services/notebook/browser/notebookService.ts b/src/sql/workbench/services/notebook/browser/notebookService.ts
index b3fdac39ee..4211ca8ab1 100644
--- a/src/sql/workbench/services/notebook/browser/notebookService.ts
+++ b/src/sql/workbench/services/notebook/browser/notebookService.ts
@@ -143,6 +143,8 @@ export interface INotebookService {
notifyCellExecutionStarted(): void;
openNotebook(resource: UriComponents, options: INotebookShowOptions): Promise;
+
+ getUntitledUriPath(originalTitle: string): string;
}
export interface INotebookProvider {
diff --git a/src/sql/workbench/services/notebook/browser/notebookServiceImpl.ts b/src/sql/workbench/services/notebook/browser/notebookServiceImpl.ts
index 782ca5468b..029f62532d 100644
--- a/src/sql/workbench/services/notebook/browser/notebookServiceImpl.ts
+++ b/src/sql/workbench/services/notebook/browser/notebookServiceImpl.ts
@@ -224,6 +224,28 @@ export class NotebookService extends Disposable implements INotebookService {
return await this._editorService.openEditor(fileInput, editorOptions, viewColumnToEditorGroup(this._editorGroupService, options.position));
}
+ /**
+ * Will iterate the title of the parameterized notebook since the original notebook is still open
+ * @param originalTitle is the title of the original notebook that we run parameterized action from
+ * @returns the title of the parameterized notebook
+ */
+ public getUntitledUriPath(originalTitle: string): string {
+ let title = originalTitle;
+ let nextVal = 0;
+ let ext = path.extname(title);
+ while (this.listNotebookEditors().findIndex(doc => path.basename(doc.notebookParams.notebookUri.fsPath) === title) > -1) {
+ if (ext) {
+ // Need it to be `Readme-0.txt` not `Readme.txt-0`
+ let titleStart = originalTitle.slice(0, originalTitle.length - ext.length);
+ title = `${titleStart}-${nextVal}${ext}`;
+ } else {
+ title = `${originalTitle}-${nextVal}`;
+ }
+ nextVal++;
+ }
+ return title;
+ }
+
private updateSQLRegistrationWithConnectionProviders() {
// Update the SQL extension
let sqlNotebookKernels = this._providerToStandardKernels.get(notebookConstants.SQL);