Skip to content

Commit b8d1a91

Browse files
Fix "Create New" script to open the script file after creation (#499)
When using the "Create New" functionality to create a Python script, the script file was being created successfully but not opened in the editor, requiring users to manually navigate and open the file. This PR fixes the issue by modifying the `addPythonProjectCommand` function to: 1. Capture the return value from `creator.create()` 2. Check if the result is a `Uri` (indicating a single file like a script was created) 3. Call `showTextDocument(uri)` to automatically open the script in the editor **Before:** - User selects "Create New" → Script → enters name - Script file is created but user has to manually find and open it **After:** - User selects "Create New" → Script → enters name - Script file is created AND automatically opened in the editor The implementation is minimal and surgical: - Only affects cases where creators return a `Uri` (like script files) - Projects that return `PythonProject` objects are unaffected - Uses existing `showTextDocument` utility function - Applied to both the main creator path and existing projects creator path Fixes #478. --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs. --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: eleanorjboyd <[email protected]>
1 parent 307f8ba commit b8d1a91

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/features/envCommands.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
pickWorkspaceFolder,
2828
} from '../common/pickers/managers';
2929
import { pickProject, pickProjectMany } from '../common/pickers/projects';
30-
import { activeTextEditor, showErrorMessage, showInformationMessage } from '../common/window.apis';
30+
import { activeTextEditor, showErrorMessage, showInformationMessage, showTextDocument } from '../common/window.apis';
3131
import { quoteArgs } from './execution/execUtils';
3232
import { runAsTask } from './execution/runAsTask';
3333
import { runInTerminal } from './terminal/runInTerminal';
@@ -471,7 +471,10 @@ export async function addPythonProjectCommand(
471471
}
472472

473473
try {
474-
await creator.create(options);
474+
const result = await creator.create(options);
475+
if (result instanceof Uri) {
476+
await showTextDocument(result);
477+
}
475478
} catch (ex) {
476479
if (ex === QuickInputButtons.Back) {
477480
return addPythonProjectCommand(resource, wm, em, pc);

0 commit comments

Comments
 (0)