Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not open "save as" window when running existing Python files #21232

Merged
merged 1 commit into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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