Skip to content

Commit d71250e

Browse files
authored
Remove path from untitled files when using VSC NB (#12430)
For #10496 We don't need the fully qualified path for untitled notebooks. However auto saving in untitiled nb doesn't work, VSC Master has a fix but we're waiting for insiders to get updated.
1 parent 98a9b50 commit d71250e

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

src/client/datascience/common.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,20 @@ export function translateKernelLanguageToMonaco(kernelLanguage: string): string
132132
return kernelLanguage.toLowerCase();
133133
}
134134

135-
export function generateNewNotebookUri(counter: number, title?: string): Uri {
136-
// Because of this bug here:
137-
// https://github.com/microsoft/vscode/issues/93441
138-
// We can't create 'untitled' files anymore. The untitled scheme will just be ignored.
139-
// Instead we need to create untitled files in the temp folder and force a saveas whenever they're
140-
// saved.
141-
135+
export function generateNewNotebookUri(counter: number, title?: string, forVSCodeNotebooks?: boolean): Uri {
142136
// However if there are files already on disk, we should be able to overwrite them because
143137
// they will only ever be used by 'open' editors. So just use the current counter for our untitled count.
144138
const fileName = title ? `${title}-${counter}.ipynb` : `${DataScience.untitledNotebookFileName()}-${counter}.ipynb`;
145-
const filePath = Uri.file(path.join(os.tmpdir(), fileName));
146139
// Turn this back into an untitled
147-
return filePath.with({ scheme: 'untitled', path: filePath.fsPath });
140+
if (forVSCodeNotebooks) {
141+
return Uri.file(fileName).with({ scheme: 'untitled', path: fileName });
142+
} else {
143+
// Because of this bug here:
144+
// https://github.com/microsoft/vscode/issues/93441
145+
// We can't create 'untitled' files anymore. The untitled scheme will just be ignored.
146+
// Instead we need to create untitled files in the temp folder and force a saveas whenever they're
147+
// saved.
148+
const filePath = Uri.file(path.join(os.tmpdir(), fileName));
149+
return filePath.with({ scheme: 'untitled', path: filePath.fsPath });
150+
}
148151
}

src/client/datascience/interactive-ipynb/notebookStorageProvider.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { getNextUntitledCounter } from './nativeEditorStorage';
1515

1616
export const INotebookStorageProvider = Symbol.for('INotebookStorageProvider');
1717
export interface INotebookStorageProvider extends INotebookStorage {
18-
createNew(contents?: string): Promise<INotebookModel>;
18+
createNew(contents?: string, forVSCodeNotebook?: boolean): Promise<INotebookModel>;
1919
}
2020
@injectable()
2121
export class NotebookStorageProvider implements INotebookStorageProvider {
@@ -80,16 +80,16 @@ export class NotebookStorageProvider implements INotebookStorageProvider {
8080
}
8181
}
8282

83-
public async createNew(contents?: string): Promise<INotebookModel> {
83+
public async createNew(contents?: string, forVSCodeNotebooks?: boolean): Promise<INotebookModel> {
8484
// Create a new URI for the dummy file using our root workspace path
85-
const uri = this.getNextNewNotebookUri();
85+
const uri = this.getNextNewNotebookUri(forVSCodeNotebooks);
8686

8787
// Always skip loading from the hot exit file. When creating a new file we want a new file.
8888
return this.load(uri, contents, true);
8989
}
9090

91-
private getNextNewNotebookUri(): Uri {
92-
return generateNewNotebookUri(NotebookStorageProvider.untitledCounter);
91+
private getNextNewNotebookUri(forVSCodeNotebooks?: boolean): Uri {
92+
return generateNewNotebookUri(NotebookStorageProvider.untitledCounter, undefined, forVSCodeNotebooks);
9393
}
9494

9595
private trackModel(model: INotebookModel): INotebookModel {

src/client/datascience/notebook/notebookEditorProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export class NotebookEditorProvider implements INotebookEditorProvider {
131131
return;
132132
}
133133
public async createNew(contents?: string): Promise<INotebookEditor> {
134-
const model = await this.storage.createNew(contents);
134+
const model = await this.storage.createNew(contents, true);
135135
return this.open(model.file);
136136
}
137137
private onEditorOpened(editor: INotebookEditor): void {

0 commit comments

Comments
 (0)