Skip to content

Commit

Permalink
Do not open "save as" window when running existing Python files (#21232)
Browse files Browse the repository at this point in the history
Closes #21209
  • Loading branch information
Kartik Raj authored May 11, 2023
1 parent b0da28c commit b3d43e5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions src/client/common/application/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -852,15 +852,15 @@ export interface IWorkspaceService {
*/
openTextDocument(options?: { language?: string; content?: string }): Thenable<TextDocument>;
/**
* 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<Uri | undefined>;
save(uri: Uri): Thenable<Uri | undefined>;
}

export const ITerminalManager = Symbol('ITerminalManager');
Expand Down
4 changes: 2 additions & 2 deletions src/client/common/application/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ export class WorkspaceService implements IWorkspaceService {
return `{${enabledSearchExcludes.join(',')}}`;
}

public async saveAs(uri: Uri): Promise<Uri | undefined> {
public async save(uri: Uri): Promise<Uri | undefined> {
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;
Expand Down
4 changes: 2 additions & 2 deletions src/client/terminals/codeExecution/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ export class CodeExecutionHelper implements ICodeExecutionHelper {

public async saveFileIfDirty(file: Uri): Promise<Resource> {
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>(IWorkspaceService);
return workspaceService.saveAs(docs[0].uri);
return workspaceService.save(docs[0].uri);
}
return undefined;
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/terminals/codeExecution/helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit b3d43e5

Please sign in to comment.