1- import { commands , extensions , ExtensionContext , LogOutputChannel , Terminal , Uri , window , workspace } from 'vscode' ;
1+ import { commands , ExtensionContext , extensions , LogOutputChannel , Terminal , Uri , window , workspace } from 'vscode' ;
22import { PythonEnvironment , PythonEnvironmentApi , PythonProjectCreator } from './api' ;
33import { ensureCorrectVersion } from './common/extVersion' ;
44import { registerLogger , traceError , traceInfo } from './common/logging' ;
@@ -75,27 +75,26 @@ import { registerPyenvFeatures } from './managers/pyenv/main';
7575async function collectEnvironmentInfo (
7676 context : ExtensionContext ,
7777 envManagers : EnvironmentManagers ,
78- projectManager : PythonProjectManager
78+ projectManager : PythonProjectManager ,
7979) : Promise < string > {
8080 const info : string [ ] = [ ] ;
81-
8281 try {
8382 // Extension version
8483 const extensionVersion = context . extension ?. packageJSON ?. version || 'unknown' ;
8584 info . push ( `Extension Version: ${ extensionVersion } ` ) ;
86-
85+
8786 // Python extension version
8887 const pythonExtension = extensions . getExtension ( 'ms-python.python' ) ;
8988 const pythonVersion = pythonExtension ?. packageJSON ?. version || 'not installed' ;
9089 info . push ( `Python Extension Version: ${ pythonVersion } ` ) ;
91-
90+
9291 // Environment managers
9392 const managers = envManagers . managers ;
9493 info . push ( `\nRegistered Environment Managers (${ managers . length } ):` ) ;
95- managers . forEach ( manager => {
94+ managers . forEach ( ( manager ) => {
9695 info . push ( ` - ${ manager . id } (${ manager . displayName } )` ) ;
9796 } ) ;
98-
97+
9998 // Available environments
10099 const allEnvironments : PythonEnvironment [ ] = [ ] ;
101100 for ( const manager of managers ) {
@@ -106,7 +105,7 @@ async function collectEnvironmentInfo(
106105 info . push ( ` Error getting environments from ${ manager . id } : ${ err } ` ) ;
107106 }
108107 }
109-
108+
110109 info . push ( `\nTotal Available Environments: ${ allEnvironments . length } ` ) ;
111110 if ( allEnvironments . length > 0 ) {
112111 info . push ( 'Environment Details:' ) ;
@@ -117,7 +116,7 @@ async function collectEnvironmentInfo(
117116 info . push ( ` ... and ${ allEnvironments . length - 10 } more environments` ) ;
118117 }
119118 }
120-
119+
121120 // Python projects
122121 const projects = projectManager . getProjects ( ) ;
123122 info . push ( `\nPython Projects (${ projects . length } ):` ) ;
@@ -133,24 +132,34 @@ async function collectEnvironmentInfo(
133132 info . push ( ` Error getting environment: ${ err } ` ) ;
134133 }
135134 }
136-
135+
137136 // Current settings (non-sensitive)
138137 const config = workspace . getConfiguration ( 'python-envs' ) ;
139138 info . push ( '\nExtension Settings:' ) ;
140139 info . push ( ` Default Environment Manager: ${ config . get ( 'defaultEnvManager' ) } ` ) ;
141140 info . push ( ` Default Package Manager: ${ config . get ( 'defaultPackageManager' ) } ` ) ;
142141 info . push ( ` Terminal Auto Activation: ${ config . get ( 'terminal.autoActivationType' ) } ` ) ;
143-
144142 } catch ( err ) {
145143 info . push ( `\nError collecting environment information: ${ err } ` ) ;
146144 }
147-
145+
148146 return info . join ( '\n' ) ;
149147}
150148
151149export async function activate ( context : ExtensionContext ) : Promise < PythonEnvironmentApi > {
152150 const start = new StopWatch ( ) ;
153151
152+ // Attempt to set setting of config.python.useEnvironmentsExtension to true
153+ try {
154+ const config = workspace . getConfiguration ( 'python' ) ;
155+ await config . update ( 'useEnvironmentsExtension' , true , true ) ;
156+ } catch ( err ) {
157+ traceError (
158+ 'Failed to set config.python.useEnvironmentsExtension to true. Please do so manually in your user settings now to ensure the Python environment extension is enabled during upcoming experimentation.' ,
159+ err ,
160+ ) ;
161+ }
162+
154163 // Logging should be set up before anything else.
155164 const outputChannel : LogOutputChannel = createLogOutputChannel ( 'Python Environments' ) ;
156165 context . subscriptions . push ( outputChannel , registerLogger ( outputChannel ) ) ;
@@ -366,11 +375,11 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
366375 commands . registerCommand ( 'python-envs.reportIssue' , async ( ) => {
367376 try {
368377 const issueData = await collectEnvironmentInfo ( context , envManagers , projectManager ) ;
369-
378+
370379 await commands . executeCommand ( 'workbench.action.openIssueReporter' , {
371380 extensionId : 'ms-python.vscode-python-envs' ,
372381 issueTitle : '[Python Environments] ' ,
373- 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>`
382+ 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>` ,
374383 } ) ;
375384 } catch ( error ) {
376385 window . showErrorMessage ( `Failed to open issue reporter: ${ error } ` ) ;
0 commit comments