@@ -2,7 +2,6 @@ import * as os from 'os';
2
2
import * as vscode from 'vscode' ;
3
3
import * as assert from 'assert' ;
4
4
import * as cp from 'child_process' ;
5
- import { Logger } from '../services/logging' ;
6
5
import { isString , isArrayOfString } from './helper' ;
7
6
8
7
export const LS_NAME = 'fortls' ;
@@ -98,36 +97,31 @@ export function getOuterMostWorkspaceFolder(
98
97
* @param msg message for installing said package
99
98
* @param toolType type of tool, supports `Python` (through pip) and 'VSExt'
100
99
* @param opts options for the prompt. "Install" and "Don't Show Again" are coded
101
- * @param logger log channel output
102
100
* @param action a void function for an action to perform when "Don't Show Again" is pressed
103
101
*/
104
102
export async function promptForMissingTool (
105
103
tool : string ,
106
104
msg : string ,
107
105
toolType : string ,
108
106
opts : string [ ] ,
109
- logger ?: Logger ,
110
107
action ?: ( ) => void
111
108
) {
112
109
const items = [ 'Install' ] ;
113
- return vscode . window . showInformationMessage ( msg , ...opts ) . then ( selected => {
110
+ return vscode . window . showInformationMessage ( msg , ...opts ) . then ( async selected => {
114
111
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 ;
112
+ if ( toolType === 'Python' ) {
113
+ try {
114
+ const inst_msg = await pipInstall ( tool ) ;
115
+ vscode . window . showInformationMessage ( inst_msg ) ;
116
+ } catch ( error ) {
117
+ vscode . window . showErrorMessage ( error ) ;
118
+ }
119
+ } else if ( toolType === 'VSExt' ) {
120
+ // Installing VS Marketplace Extension
121
+ vscode . commands . executeCommand ( 'extension.open' , tool ) ;
122
+ vscode . commands . executeCommand ( 'workbench.extensions.installExtension' , tool ) ;
123
+ } else {
124
+ vscode . window . showErrorMessage ( `Failed to install tool: ${ tool } ` ) ;
131
125
}
132
126
} else if ( selected === "Don't Show Again" ) {
133
127
action ( ) ;
@@ -140,25 +134,35 @@ export async function promptForMissingTool(
140
134
* Does not explicitly check if `pip` is installed.
141
135
*
142
136
* @param pyPackage name of python package in PyPi
143
- * @param logger `optional` logging channel for output
144
137
*/
145
- export function installPythonTool ( pyPackage : string , logger ?: Logger ) {
146
- const installProcess = cp . spawnSync (
147
- 'pip' ,
148
- 'install --user --upgrade ' . concat ( pyPackage ) . split ( ' ' )
138
+ export async function pipInstall ( pyPackage : string ) : Promise < string > {
139
+ const py = 'python3' ; // Fetches the top-most python in the Shell
140
+ const args = [ '-m' , 'pip' , 'install' , '--user' , '--upgrade' , pyPackage ] ;
141
+ return await shellTask ( py , args , `pip: ${ pyPackage } ` ) ;
142
+ }
143
+
144
+ export async function shellTask ( command : string , args : string [ ] , name : string ) : Promise < string > {
145
+ const task = new vscode . Task (
146
+ { type : 'shell' } ,
147
+ vscode . TaskScope . Workspace ,
148
+ name ,
149
+ 'Modern Fortran' ,
150
+ new vscode . ShellExecution ( command , args )
149
151
) ;
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
- }
152
+ // Temporay fix to https://github.com/microsoft/vscode/issues/157756
153
+ ( < vscode . Task > task ) . definition = { type : 'shell' , command : command } ;
154
+ const execution = await vscode . tasks . executeTask ( task ) ;
155
+ return await new Promise < string > ( ( resolve , reject ) => {
156
+ const disposable = vscode . tasks . onDidEndTaskProcess ( e => {
157
+ if ( e . execution === execution ) {
158
+ disposable . dispose ( ) ;
159
+ if ( e . exitCode !== 0 ) {
160
+ reject ( `ERROR: ${ e . execution . task . name } failed with code ${ e . exitCode } ` ) ;
161
+ }
162
+ resolve ( `${ name } : shell task completed successfully.` ) ;
163
+ }
164
+ } ) ;
165
+ } ) ;
162
166
}
163
167
164
168
/**
0 commit comments