|
1 | | -import { commands, ExtensionContext, LogOutputChannel, Terminal, Uri, window } from 'vscode'; |
| 1 | +import { commands, extensions, ExtensionContext, LogOutputChannel, Terminal, Uri, window, workspace } from 'vscode'; |
2 | 2 | import { PythonEnvironment, PythonEnvironmentApi, PythonProjectCreator } from './api'; |
3 | 3 | import { ensureCorrectVersion } from './common/extVersion'; |
4 | 4 | import { registerLogger, traceError, traceInfo } from './common/logging'; |
@@ -69,6 +69,85 @@ import { registerCondaFeatures } from './managers/conda/main'; |
69 | 69 | import { registerPoetryFeatures } from './managers/poetry/main'; |
70 | 70 | import { registerPyenvFeatures } from './managers/pyenv/main'; |
71 | 71 |
|
| 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 | + // Python extension version |
| 88 | + const pythonExtension = extensions.getExtension('ms-python.python'); |
| 89 | + const pythonVersion = pythonExtension?.packageJSON?.version || 'not installed'; |
| 90 | + info.push(`Python Extension Version: ${pythonVersion}`); |
| 91 | + |
| 92 | + // Environment managers |
| 93 | + const managers = envManagers.managers; |
| 94 | + info.push(`\nRegistered Environment Managers (${managers.length}):`); |
| 95 | + managers.forEach(manager => { |
| 96 | + info.push(` - ${manager.id} (${manager.displayName})`); |
| 97 | + }); |
| 98 | + |
| 99 | + // Available environments |
| 100 | + const allEnvironments: PythonEnvironment[] = []; |
| 101 | + for (const manager of managers) { |
| 102 | + try { |
| 103 | + const envs = await manager.getEnvironments('all'); |
| 104 | + allEnvironments.push(...envs); |
| 105 | + } catch (err) { |
| 106 | + info.push(` Error getting environments from ${manager.id}: ${err}`); |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + info.push(`\nTotal Available Environments: ${allEnvironments.length}`); |
| 111 | + if (allEnvironments.length > 0) { |
| 112 | + info.push('Environment Details:'); |
| 113 | + allEnvironments.slice(0, 10).forEach((env, index) => { |
| 114 | + info.push(` ${index + 1}. ${env.displayName} (${env.version}) - ${env.displayPath}`); |
| 115 | + }); |
| 116 | + if (allEnvironments.length > 10) { |
| 117 | + info.push(` ... and ${allEnvironments.length - 10} more environments`); |
| 118 | + } |
| 119 | + } |
| 120 | + |
| 121 | + // Python projects |
| 122 | + const projects = projectManager.getProjects(); |
| 123 | + info.push(`\nPython Projects (${projects.length}):`); |
| 124 | + for (let index = 0; index < projects.length; index++) { |
| 125 | + const project = projects[index]; |
| 126 | + info.push(` ${index + 1}. ${project.uri.fsPath}`); |
| 127 | + try { |
| 128 | + const env = await envManagers.getEnvironment(project.uri); |
| 129 | + if (env) { |
| 130 | + info.push(` Environment: ${env.displayName}`); |
| 131 | + } |
| 132 | + } catch (err) { |
| 133 | + info.push(` Error getting environment: ${err}`); |
| 134 | + } |
| 135 | + } |
| 136 | + |
| 137 | + // Current settings (non-sensitive) |
| 138 | + const config = workspace.getConfiguration('python-envs'); |
| 139 | + info.push('\nExtension Settings:'); |
| 140 | + info.push(` Default Environment Manager: ${config.get('defaultEnvManager')}`); |
| 141 | + info.push(` Default Package Manager: ${config.get('defaultPackageManager')}`); |
| 142 | + info.push(` Terminal Auto Activation: ${config.get('terminal.autoActivationType')}`); |
| 143 | + |
| 144 | + } catch (err) { |
| 145 | + info.push(`\nError collecting environment information: ${err}`); |
| 146 | + } |
| 147 | + |
| 148 | + return info.join('\n'); |
| 149 | +} |
| 150 | + |
72 | 151 | export async function activate(context: ExtensionContext): Promise<PythonEnvironmentApi> { |
73 | 152 | const start = new StopWatch(); |
74 | 153 |
|
@@ -278,6 +357,19 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron |
278 | 357 | } |
279 | 358 | }, |
280 | 359 | ), |
| 360 | + commands.registerCommand('python-envs.reportIssue', async () => { |
| 361 | + try { |
| 362 | + const issueData = await collectEnvironmentInfo(context, envManagers, projectManager); |
| 363 | + |
| 364 | + await commands.executeCommand('workbench.action.openIssueReporter', { |
| 365 | + extensionId: 'ms-python.vscode-python-envs', |
| 366 | + issueTitle: '[Python Environments] ', |
| 367 | + 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>` |
| 368 | + }); |
| 369 | + } catch (error) { |
| 370 | + window.showErrorMessage(`Failed to open issue reporter: ${error}`); |
| 371 | + } |
| 372 | + }), |
281 | 373 | terminalActivation.onDidChangeTerminalActivationState(async (e) => { |
282 | 374 | await setActivateMenuButtonContext(e.terminal, e.environment, e.activated); |
283 | 375 | }), |
|
0 commit comments