Skip to content

Commit 61e9591

Browse files
Copiloteleanorjboyd
andcommitted
Add Python Environments report issue command
Co-authored-by: eleanorjboyd <[email protected]>
1 parent 53df853 commit 61e9591

File tree

3 files changed

+94
-1
lines changed

3 files changed

+94
-1
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,11 @@
256256
"title": "%python-envs.terminal.revertStartupScriptChanges.title%",
257257
"category": "Python Envs",
258258
"icon": "$(discard)"
259+
},
260+
{
261+
"command": "python-envs.reportIssue",
262+
"title": "%python-envs.reportIssue.title%",
263+
"category": "Python Environments"
259264
}
260265
],
261266
"menus": {

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"python-envs.terminal.autoActivationType.shellStartup": "Activation by modifying the terminal shell startup script. To use this feature we will need to modify your shell startup scripts.",
1212
"python-envs.terminal.autoActivationType.off": "No automatic activation of environments.",
1313
"python-envs.terminal.revertStartupScriptChanges.title": "Revert Shell Startup Script Changes",
14+
"python-envs.reportIssue.title": "Report Issue",
1415
"python-envs.setEnvManager.title": "Set Environment Manager",
1516
"python-envs.setPkgManager.title": "Set Package Manager",
1617
"python-envs.addPythonProject.title": "Add Python Project",

src/extension.ts

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { commands, ExtensionContext, LogOutputChannel, Terminal, Uri, window } from 'vscode';
1+
import { commands, ExtensionContext, LogOutputChannel, Terminal, Uri, window, workspace } from 'vscode';
22
import { PythonEnvironment, PythonEnvironmentApi, PythonProjectCreator } from './api';
33
import { ensureCorrectVersion } from './common/extVersion';
44
import { registerLogger, traceError, traceInfo } from './common/logging';
@@ -69,6 +69,80 @@ import { registerCondaFeatures } from './managers/conda/main';
6969
import { registerPoetryFeatures } from './managers/poetry/main';
7070
import { registerPyenvFeatures } from './managers/pyenv/main';
7171

72+
/**
73+
* Collects relevant Python environment information for issue reporting
74+
*/
75+
async function collectEnvironmentInfo(
76+
context: ExtensionContext,
77+
envManagers: EnvironmentManagers,
78+
projectManager: PythonProjectManager
79+
): Promise<string> {
80+
const info: string[] = [];
81+
82+
try {
83+
// Extension version
84+
const extensionVersion = context.extension?.packageJSON?.version || 'unknown';
85+
info.push(`Extension Version: ${extensionVersion}`);
86+
87+
// Environment managers
88+
const managers = envManagers.managers;
89+
info.push(`\nRegistered Environment Managers (${managers.length}):`);
90+
managers.forEach(manager => {
91+
info.push(` - ${manager.id} (${manager.displayName})`);
92+
});
93+
94+
// Available environments
95+
const allEnvironments: PythonEnvironment[] = [];
96+
for (const manager of managers) {
97+
try {
98+
const envs = await manager.getEnvironments('all');
99+
allEnvironments.push(...envs);
100+
} catch (err) {
101+
info.push(` Error getting environments from ${manager.id}: ${err}`);
102+
}
103+
}
104+
105+
info.push(`\nTotal Available Environments: ${allEnvironments.length}`);
106+
if (allEnvironments.length > 0) {
107+
info.push('Environment Details:');
108+
allEnvironments.slice(0, 10).forEach((env, index) => {
109+
info.push(` ${index + 1}. ${env.displayName} (${env.version}) - ${env.displayPath}`);
110+
});
111+
if (allEnvironments.length > 10) {
112+
info.push(` ... and ${allEnvironments.length - 10} more environments`);
113+
}
114+
}
115+
116+
// Python projects
117+
const projects = projectManager.getProjects();
118+
info.push(`\nPython Projects (${projects.length}):`);
119+
for (let index = 0; index < projects.length; index++) {
120+
const project = projects[index];
121+
info.push(` ${index + 1}. ${project.uri.fsPath}`);
122+
try {
123+
const env = await envManagers.getEnvironment(project.uri);
124+
if (env) {
125+
info.push(` Environment: ${env.displayName}`);
126+
}
127+
} catch (err) {
128+
info.push(` Error getting environment: ${err}`);
129+
}
130+
}
131+
132+
// Current settings (non-sensitive)
133+
const config = workspace.getConfiguration('python-envs');
134+
info.push('\nExtension Settings:');
135+
info.push(` Default Environment Manager: ${config.get('defaultEnvManager')}`);
136+
info.push(` Default Package Manager: ${config.get('defaultPackageManager')}`);
137+
info.push(` Terminal Auto Activation: ${config.get('terminal.autoActivationType')}`);
138+
139+
} catch (err) {
140+
info.push(`\nError collecting environment information: ${err}`);
141+
}
142+
143+
return info.join('\n');
144+
}
145+
72146
export async function activate(context: ExtensionContext): Promise<PythonEnvironmentApi> {
73147
const start = new StopWatch();
74148

@@ -278,6 +352,19 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
278352
}
279353
},
280354
),
355+
commands.registerCommand('python-envs.reportIssue', async () => {
356+
try {
357+
const issueData = await collectEnvironmentInfo(context, envManagers, projectManager);
358+
359+
await commands.executeCommand('workbench.action.openIssueReporter', {
360+
extensionId: 'ms-python.vscode-python-envs',
361+
issueTitle: '[Python Environments] ',
362+
issueBody: `<!-- Please describe the issue you're experiencing -->\n\n<!-- The following information was automatically generated -->\n\n<details>\n<summary>Environment Information</summary>\n\n\`\`\`\n${issueData}\n\`\`\`\n\n</details>`
363+
});
364+
} catch (error) {
365+
window.showErrorMessage(`Failed to open issue reporter: ${error}`);
366+
}
367+
}),
281368
terminalActivation.onDidChangeTerminalActivationState(async (e) => {
282369
await setActivateMenuButtonContext(e.terminal, e.environment, e.activated);
283370
}),

0 commit comments

Comments
 (0)