Skip to content

Commit 7a47672

Browse files
authored
update to add all new projects to projects view (#537)
fixes #517
1 parent f622704 commit 7a47672

File tree

4 files changed

+20
-21
lines changed

4 files changed

+20
-21
lines changed

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
119119
projectCreators.registerPythonProjectCreator(new ExistingProjects(projectManager)),
120120
projectCreators.registerPythonProjectCreator(new AutoFindProjects(projectManager)),
121121
projectCreators.registerPythonProjectCreator(new NewPackageProject(envManagers, projectManager)),
122-
projectCreators.registerPythonProjectCreator(new NewScriptProject()),
122+
projectCreators.registerPythonProjectCreator(new NewScriptProject(projectManager)),
123123
);
124124

125125
setPythonApi(envManagers, projectManager, projectCreators, terminalManager, envVarManager);

src/features/creators/newPackageProject.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,8 @@ export class NewPackageProject implements PythonProjectCreator {
114114
await replaceInFilesAndNames(projectDestinationFolder, 'package_name', packageName);
115115

116116
// 4. Create virtual environment if requested
117-
let createdPackage: PythonProject | undefined;
118117
if (createVenv) {
119-
createdPackage = {
120-
name: packageName,
121-
uri: Uri.file(projectDestinationFolder),
122-
};
123-
124118
// add package to list of packages before creating the venv
125-
this.projectManager.add(createdPackage);
126119
await quickCreateNewVenv(this.envManagers, projectDestinationFolder);
127120
}
128121

@@ -156,13 +149,12 @@ export class NewPackageProject implements PythonProjectCreator {
156149
};
157150
await manageLaunchJsonFile(destRoot, JSON.stringify(launchJsonConfig));
158151

159-
if (createdPackage) {
160-
// return package if created (ie when venv is created)
161-
return createdPackage;
162-
} else {
163-
// otherwise its not a package and just a folder
164-
return Uri.file(projectDestinationFolder);
165-
}
152+
const createdPackage: PythonProject | undefined = {
153+
name: packageName,
154+
uri: Uri.file(projectDestinationFolder),
155+
};
156+
this.projectManager.add(createdPackage);
157+
return createdPackage;
166158
}
167159
return undefined;
168160
}

src/features/creators/newScriptProject.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { PythonProject, PythonProjectCreator, PythonProjectCreatorOptions } from
55
import { NEW_PROJECT_TEMPLATES_FOLDER } from '../../common/constants';
66
import { traceError } from '../../common/logging';
77
import { showInputBoxWithButtons } from '../../common/window.apis';
8+
import { PythonProjectManager } from '../../internal.api';
89
import { isCopilotInstalled, manageCopilotInstructionsFile, replaceInFilesAndNames } from './creationHelpers';
910

1011
export class NewScriptProject implements PythonProjectCreator {
@@ -13,7 +14,7 @@ export class NewScriptProject implements PythonProjectCreator {
1314
public readonly description = l10n.t('Creates a new script folder in your current workspace with PEP 723 support');
1415
public readonly tooltip = new MarkdownString(l10n.t('Create a new Python script'));
1516

16-
constructor() {}
17+
constructor(private readonly projectManager: PythonProjectManager) {}
1718

1819
async create(options?: PythonProjectCreatorOptions): Promise<PythonProject | Uri | undefined> {
1920
// quick create (needs name, will always create venv and copilot instructions)
@@ -113,7 +114,13 @@ export class NewScriptProject implements PythonProjectCreator {
113114
]);
114115
}
115116

116-
return Uri.file(scriptDestination);
117+
// Add the created script to the project manager
118+
const createdScript: PythonProject | undefined = {
119+
name: scriptFileName,
120+
uri: Uri.file(scriptDestination),
121+
};
122+
this.projectManager.add(createdScript);
123+
return createdScript;
117124
}
118125
return undefined;
119126
}

src/features/views/treeViewItems.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { TreeItem, TreeItemCollapsibleState, MarkdownString, Command, ThemeIcon } from 'vscode';
1+
import { Command, MarkdownString, ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode';
2+
import { EnvironmentGroupInfo, IconPath, Package, PythonEnvironment, PythonProject } from '../../api';
3+
import { EnvViewStrings } from '../../common/localize';
24
import { InternalEnvironmentManager, InternalPackageManager } from '../../internal.api';
3-
import { PythonEnvironment, IconPath, Package, PythonProject, EnvironmentGroupInfo } from '../../api';
4-
import { removable } from './utils';
55
import { isActivatableEnvironment } from '../common/activation';
6-
import { EnvViewStrings } from '../../common/localize';
6+
import { removable } from './utils';
77

88
export enum EnvTreeItemKind {
99
manager = 'python-env-manager',

0 commit comments

Comments
 (0)