From b3d43e5f7ee97d30c578593d52720b805d10e0f7 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Thu, 11 May 2023 15:48:43 -0700 Subject: [PATCH] Do not open "save as" window when running existing Python files (#21232) Closes https://github.com/microsoft/vscode-python/issues/21209 --- src/client/common/application/types.ts | 12 ++++++------ src/client/common/application/workspace.ts | 4 ++-- src/client/terminals/codeExecution/helper.ts | 4 ++-- src/test/terminals/codeExecution/helper.test.ts | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/client/common/application/types.ts b/src/client/common/application/types.ts index e57bac656d19..72cd357d62d8 100644 --- a/src/client/common/application/types.ts +++ b/src/client/common/application/types.ts @@ -852,15 +852,15 @@ export interface IWorkspaceService { */ openTextDocument(options?: { language?: string; content?: string }): Thenable; /** - * Saves the editor identified by the given resource to a new file name as provided by the user and - * returns the resulting resource or `undefined` if save was not successful or cancelled. + * Saves the editor identified by the given resource and returns the resulting resource or `undefined` + * if save was not successful. * - * **Note** that an editor with the provided resource must be opened in order to be saved as. + * **Note** that an editor with the provided resource must be opened in order to be saved. * - * @param uri the associated uri for the opened editor to save as. - * @return A thenable that resolves when the save-as operation has finished. + * @param uri the associated uri for the opened editor to save. + * @return A thenable that resolves when the save operation has finished. */ - saveAs(uri: Uri): Thenable; + save(uri: Uri): Thenable; } export const ITerminalManager = Symbol('ITerminalManager'); diff --git a/src/client/common/application/workspace.ts b/src/client/common/application/workspace.ts index 11ed98cf0076..a76a78777bef 100644 --- a/src/client/common/application/workspace.ts +++ b/src/client/common/application/workspace.ts @@ -113,10 +113,10 @@ export class WorkspaceService implements IWorkspaceService { return `{${enabledSearchExcludes.join(',')}}`; } - public async saveAs(uri: Uri): Promise { + public async save(uri: Uri): Promise { try { // This is a proposed API hence putting it inside try...catch. - const result = await workspace.saveAs(uri); + const result = await workspace.save(uri); return result; } catch (ex) { return undefined; diff --git a/src/client/terminals/codeExecution/helper.ts b/src/client/terminals/codeExecution/helper.ts index 0a1ae9f0be06..0d5694b4a28d 100644 --- a/src/client/terminals/codeExecution/helper.ts +++ b/src/client/terminals/codeExecution/helper.ts @@ -122,9 +122,9 @@ export class CodeExecutionHelper implements ICodeExecutionHelper { public async saveFileIfDirty(file: Uri): Promise { const docs = this.documentManager.textDocuments.filter((d) => d.uri.path === file.path); - if (docs.length === 1 && docs[0].isDirty) { + if (docs.length === 1 && (docs[0].isDirty || docs[0].isUntitled)) { const workspaceService = this.serviceContainer.get(IWorkspaceService); - return workspaceService.saveAs(docs[0].uri); + return workspaceService.save(docs[0].uri); } return undefined; } diff --git a/src/test/terminals/codeExecution/helper.test.ts b/src/test/terminals/codeExecution/helper.test.ts index 684ca22b6c75..ac47037a2344 100644 --- a/src/test/terminals/codeExecution/helper.test.ts +++ b/src/test/terminals/codeExecution/helper.test.ts @@ -383,7 +383,7 @@ suite('Terminal - Code Execution Helper', () => { const untitledUri = Uri.file('Untitled-1'); document.setup((doc) => doc.uri).returns(() => untitledUri); const expectedSavedUri = Uri.file('one.py'); - workspaceService.setup((w) => w.saveAs(TypeMoq.It.isAny())).returns(() => Promise.resolve(expectedSavedUri)); + workspaceService.setup((w) => w.save(TypeMoq.It.isAny())).returns(() => Promise.resolve(expectedSavedUri)); const savedUri = await helper.saveFileIfDirty(untitledUri);