diff --git a/extensions/notebook/src/book/bookTreeItem.ts b/extensions/notebook/src/book/bookTreeItem.ts index b633b15225..a2c8f0bcaa 100644 --- a/extensions/notebook/src/book/bookTreeItem.ts +++ b/extensions/notebook/src/book/bookTreeItem.ts @@ -67,7 +67,8 @@ export class BookTreeItem extends vscode.TreeItem { private setCommand() { if (this.book.type === BookTreeItemType.Notebook) { - let pathToNotebook = path.join(this.book.root, 'content', this._uri.concat('.ipynb')); + // The Notebook editor expects a posix path for the resource (it will still resolve to the correct fsPath based on OS) + const pathToNotebook = path.posix.join(this.book.root, 'content', this._uri.concat('.ipynb')); this.command = { command: this.book.isUntitled ? 'bookTreeView.openUntitledNotebook' : 'bookTreeView.openNotebook', title: loc.openNotebookCommand, arguments: [pathToNotebook], }; } else if (this.book.type === BookTreeItemType.Markdown) { let pathToMarkdown = path.join(this.book.root, 'content', this._uri.concat('.md')); @@ -81,8 +82,8 @@ export class BookTreeItem extends vscode.TreeItem { let i = --index; while (i > -1) { if (this.book.tableOfContents.sections[i].url) { - // TODO: Currently only navigating to notebooks. Need to add logic for markdown. - let pathToNotebook = path.join(this.book.root, 'content', this.book.tableOfContents.sections[i].url.concat('.ipynb')); + // The Notebook editor expects a posix path for the resource (it will still resolve to the correct fsPath based on OS) + let pathToNotebook = path.posix.join(this.book.root, 'content', this.book.tableOfContents.sections[i].url.concat('.ipynb')); // eslint-disable-next-line no-sync if (fs.existsSync(pathToNotebook)) { this._previousUri = pathToNotebook; @@ -97,8 +98,8 @@ export class BookTreeItem extends vscode.TreeItem { let i = ++index; while (i < this.book.tableOfContents.sections.length) { if (this.book.tableOfContents.sections[i].url) { - // TODO: Currently only navigating to notebooks. Need to add logic for markdown. - let pathToNotebook = path.join(this.book.root, 'content', this.book.tableOfContents.sections[i].url.concat('.ipynb')); + // The Notebook editor expects a posix path for the resource (it will still resolve to the correct fsPath based on OS) + let pathToNotebook = path.posix.join(this.book.root, 'content', this.book.tableOfContents.sections[i].url.concat('.ipynb')); // eslint-disable-next-line no-sync if (fs.existsSync(pathToNotebook)) { this._nextUri = pathToNotebook; diff --git a/extensions/notebook/src/book/bookTreeView.ts b/extensions/notebook/src/book/bookTreeView.ts index eddce4b4e1..ff317986de 100644 --- a/extensions/notebook/src/book/bookTreeView.ts +++ b/extensions/notebook/src/book/bookTreeView.ts @@ -10,7 +10,6 @@ import * as fs from 'fs-extra'; import { IPrompter, QuestionTypes, IQuestion } from '../prompts/question'; import CodeAdapter from '../prompts/adapter'; import { BookTreeItem } from './bookTreeItem'; -import { isEditorTitleFree } from '../common/utils'; import { BookModel } from './bookModel'; import { Deferred } from '../common/promise'; import * as loc from '../common/localizedConstants'; @@ -98,7 +97,8 @@ export class BookTreeViewProvider implements vscode.TreeDataProvider { diff --git a/src/sql/workbench/api/browser/mainThreadNotebookDocumentsAndEditors.ts b/src/sql/workbench/api/browser/mainThreadNotebookDocumentsAndEditors.ts index 81178dcc4c..bd7c0a96f1 100644 --- a/src/sql/workbench/api/browser/mainThreadNotebookDocumentsAndEditors.ts +++ b/src/sql/workbench/api/browser/mainThreadNotebookDocumentsAndEditors.ts @@ -458,8 +458,13 @@ export class MainThreadNotebookDocumentsAndEditors extends Disposable implements }; let isUntitled: boolean = uri.scheme === Schemas.untitled; - const fileInput = isUntitled ? this._untitledEditorService.create({ untitledResource: uri, mode: 'notebook', initialValue: options.initialContent }) : - this._editorService.createInput({ resource: uri, mode: 'notebook' }); + let fileInput; + if (isUntitled && path.isAbsolute(uri.fsPath)) { + fileInput = this._untitledEditorService.create({ associatedResource: uri, mode: 'notebook', initialValue: options.initialContent }); + } else { + fileInput = isUntitled ? this._untitledEditorService.create({ untitledResource: uri, mode: 'notebook', initialValue: options.initialContent }) : + this._editorService.createInput({ resource: uri, mode: 'notebook' }); + } let input: NotebookInput; if (isUntitled) { input = this._instantiationService.createInstance(UntitledNotebookInput, path.basename(uri.fsPath), uri, fileInput as UntitledTextEditorInput); @@ -720,7 +725,7 @@ export class MainThreadNotebookDocumentsAndEditors extends Disposable implements let result = await this._proxy.$getNavigation(handle, uri); if (result) { if (result.next.scheme === Schemas.untitled) { - let untitledNbName: URI = URI.parse(`untitled:${path.basename(result.next.path)}`); + let untitledNbName: URI = URI.parse(`untitled:${result.next.path}`); let content = await this._fileService.readFile(URI.file(result.next.path)); await this.doOpenEditor(untitledNbName, { initialContent: content.value.toString(), initialDirtyState: false }); } @@ -733,7 +738,7 @@ export class MainThreadNotebookDocumentsAndEditors extends Disposable implements let result = await this._proxy.$getNavigation(handle, uri); if (result) { if (result.previous.scheme === Schemas.untitled) { - let untitledNbName: URI = URI.parse(`untitled:${path.basename(result.previous.path)}`); + let untitledNbName: URI = URI.parse(`untitled:${result.previous.path}`); let content = await this._fileService.readFile(URI.file(result.previous.path)); await this.doOpenEditor(untitledNbName, { initialContent: content.value.toString(), initialDirtyState: false }); }