@@ -112,22 +112,22 @@ export async function promptForMissingTool(
112112 const items = [ 'Install' ] ;
113113 return vscode . window . showInformationMessage ( msg , ...opts ) . then ( selected => {
114114 if ( selected === 'Install' ) {
115- switch ( toolType ) {
116- case 'Python' :
117- installPythonTool ( tool , logger ) ;
118- break ;
119-
120- case 'VSExt' :
121- logger . info ( `Installing VS Marketplace Extension with id: ${ tool } ` ) ;
122- vscode . commands . executeCommand ( 'extension.open' , tool ) ;
123- vscode . commands . executeCommand ( 'workbench.extensions.installExtension' , tool ) ;
124- logger . info ( `Extension ${ tool } successfully installed ` ) ;
125- break ;
126-
127- default :
128- logger . error ( `Failed to install tool: ${ tool } ` ) ;
129- vscode . window . showErrorMessage ( `Failed to install tool: ${ tool } ` ) ;
130- break ;
115+ if ( toolType === 'Python' ) {
116+ pipInstall ( tool )
117+ . then ( msg => {
118+ vscode . window . showInformationMessage ( msg ) ;
119+ } )
120+ . catch ( msg => {
121+ vscode . window . showErrorMessage ( msg ) ;
122+ } ) ;
123+ } else if ( toolType === 'VSExt' ) {
124+ if ( logger ) logger . info ( `Installing VS Marketplace Extension with id: ${ tool } ` ) ;
125+ vscode . commands . executeCommand ( 'extension.open' , tool ) ;
126+ vscode . commands . executeCommand ( 'workbench.extensions.installExtension' , tool ) ;
127+ if ( logger ) logger . info ( `Extension ${ tool } successfully installed` ) ;
128+ } else {
129+ if ( logger ) logger . error ( `Failed to install tool: ${ tool } ` ) ;
130+ vscode . window . showErrorMessage ( `Failed to install tool: ${ tool } ` ) ;
131131 }
132132 } else if ( selected === "Don't Show Again" ) {
133133 action ( ) ;
@@ -140,25 +140,32 @@ export async function promptForMissingTool(
140140 * Does not explicitly check if `pip` is installed.
141141 *
142142 * @param pyPackage name of python package in PyPi
143- * @param logger `optional` logging channel for output
144143 */
145- export function installPythonTool ( pyPackage : string , logger ?: Logger ) {
146- const installProcess = cp . spawnSync (
147- 'pip' ,
148- 'install --user --upgrade ' . concat ( pyPackage ) . split ( ' ' )
144+ export async function pipInstall ( pyPackage : string ) : Promise < string > {
145+ const py = 'python3' ; // Fetches the top-most python in the Shell
146+ const args = [ '-m' , 'pip' , 'install' , '--user' , '--upgrade' , pyPackage ] ;
147+ return await shellTask ( py , args , `pip: ${ pyPackage } ` ) ;
148+ }
149+
150+ export async function shellTask ( command : string , args : string [ ] , name : string ) : Promise < string > {
151+ const task = new vscode . Task (
152+ { type : 'shell' } ,
153+ vscode . TaskScope . Workspace ,
154+ name ,
155+ 'Modern Fortran' ,
156+ new vscode . ShellExecution ( command , args )
149157 ) ;
150- if ( installProcess . error ) {
151- logger . error (
152- `Python package ${ pyPackage } failed to install with code: ${ installProcess . error } `
153- ) ;
154- }
155- if ( installProcess . stdout ) {
156- const sep = '-' . repeat ( 80 ) ;
157- logger . info (
158- `pip install --user --upgrade ${ pyPackage } :\n${ sep } \n${ installProcess . stdout } ${ sep } `
159- ) ;
160- logger . info ( `pip install was successful` ) ;
161- }
158+ // Temporay fix to https://github.com/microsoft/vscode/issues/157756
159+ ( < vscode . Task > task ) . definition = { type : 'shell' , command : command } ;
160+ const execution = await vscode . tasks . executeTask ( task ) ;
161+ return await new Promise < string > ( ( resolve , reject ) => {
162+ const disposable = vscode . tasks . onDidEndTask ( e => {
163+ if ( e . execution === execution ) {
164+ disposable . dispose ( ) ;
165+ resolve ( `${ name } : shell task completed successfully.` ) ;
166+ } else reject ( `${ name } : shell task failed.` ) ;
167+ } ) ;
168+ } ) ;
162169}
163170
164171/**
0 commit comments