22
33import { inject , injectable , named } from 'inversify' ;
44import * as os from 'os' ;
5- import { OutputChannel , Uri } from 'vscode' ;
5+ import { CancellationToken , OutputChannel , Uri } from 'vscode' ;
66import '../../common/extensions' ;
77import * as localize from '../../common/utils/localize' ;
88import { IServiceContainer } from '../../ioc/types' ;
@@ -40,7 +40,7 @@ export abstract class BaseInstaller {
4040 this . productService = serviceContainer . get < IProductService > ( IProductService ) ;
4141 }
4242
43- public promptToInstall ( product : Product , resource ?: InterpreterUri ) : Promise < InstallerResponse > {
43+ public promptToInstall ( product : Product , resource ?: InterpreterUri , cancel ?: CancellationToken ) : Promise < InstallerResponse > {
4444 // If this method gets called twice, while previous promise has not been resolved, then return that same promise.
4545 // E.g. previous promise is not resolved as a message has been displayed to the user, so no point displaying
4646 // another message.
@@ -49,15 +49,15 @@ export abstract class BaseInstaller {
4949 if ( BaseInstaller . PromptPromises . has ( key ) ) {
5050 return BaseInstaller . PromptPromises . get ( key ) ! ;
5151 }
52- const promise = this . promptToInstallImplementation ( product , resource ) ;
52+ const promise = this . promptToInstallImplementation ( product , resource , cancel ) ;
5353 BaseInstaller . PromptPromises . set ( key , promise ) ;
5454 promise . then ( ( ) => BaseInstaller . PromptPromises . delete ( key ) ) . ignoreErrors ( ) ;
5555 promise . catch ( ( ) => BaseInstaller . PromptPromises . delete ( key ) ) . ignoreErrors ( ) ;
5656
5757 return promise ;
5858 }
5959
60- public async install ( product : Product , resource ?: InterpreterUri ) : Promise < InstallerResponse > {
60+ public async install ( product : Product , resource ?: InterpreterUri , cancel ?: CancellationToken ) : Promise < InstallerResponse > {
6161 if ( product === Product . unittest ) {
6262 return InstallerResponse . Installed ;
6363 }
@@ -70,7 +70,7 @@ export abstract class BaseInstaller {
7070
7171 const moduleName = translateProductToModule ( product , ModuleNamePurpose . install ) ;
7272 const logger = this . serviceContainer . get < ILogger > ( ILogger ) ;
73- await installer . installModule ( moduleName , resource )
73+ await installer . installModule ( moduleName , resource , cancel )
7474 . catch ( logger . logError . bind ( logger , `Error in installing the module '${ moduleName } '` ) ) ;
7575
7676 return this . isInstalled ( product , resource )
@@ -98,7 +98,7 @@ export abstract class BaseInstaller {
9898 }
9999 }
100100
101- protected abstract promptToInstallImplementation ( product : Product , resource ?: InterpreterUri ) : Promise < InstallerResponse > ;
101+ protected abstract promptToInstallImplementation ( product : Product , resource ?: InterpreterUri , cancel ?: CancellationToken ) : Promise < InstallerResponse > ;
102102 protected getExecutableNameFromSettings ( product : Product , resource ?: Uri ) : string {
103103 const productType = this . productService . getProductType ( product ) ;
104104 const productPathService = this . serviceContainer . get < IProductPathService > ( IProductPathService , productType ) ;
@@ -132,14 +132,14 @@ export class CTagsInstaller extends BaseInstaller {
132132 }
133133 return InstallerResponse . Ignore ;
134134 }
135- protected async promptToInstallImplementation ( product : Product , resource ?: Uri ) : Promise < InstallerResponse > {
135+ protected async promptToInstallImplementation ( product : Product , resource ?: Uri , _cancel ?: CancellationToken ) : Promise < InstallerResponse > {
136136 const item = await this . appShell . showErrorMessage ( 'Install CTags to enable Python workspace symbols?' , 'Yes' , 'No' ) ;
137137 return item === 'Yes' ? this . install ( product , resource ) : InstallerResponse . Ignore ;
138138 }
139139}
140140
141141export class FormatterInstaller extends BaseInstaller {
142- protected async promptToInstallImplementation ( product : Product , resource ?: Uri ) : Promise < InstallerResponse > {
142+ protected async promptToInstallImplementation ( product : Product , resource ?: Uri , cancel ?: CancellationToken ) : Promise < InstallerResponse > {
143143 // Hard-coded on purpose because the UI won't necessarily work having
144144 // another formatter.
145145 const formatters = [ Product . autopep8 , Product . black , Product . yapf ] ;
@@ -160,14 +160,14 @@ export class FormatterInstaller extends BaseInstaller {
160160
161161 const item = await this . appShell . showErrorMessage ( message , ...options ) ;
162162 if ( item === yesChoice ) {
163- return this . install ( product , resource ) ;
163+ return this . install ( product , resource , cancel ) ;
164164 } else if ( typeof item === 'string' ) {
165165 for ( const formatter of formatters ) {
166166 const formatterName = ProductNames . get ( formatter ) ! ;
167167
168168 if ( item . endsWith ( formatterName ) ) {
169169 await this . configService . updateSetting ( 'formatting.provider' , formatterName , resource ) ;
170- return this . install ( formatter , resource ) ;
170+ return this . install ( formatter , resource , cancel ) ;
171171 }
172172 }
173173 }
@@ -177,7 +177,7 @@ export class FormatterInstaller extends BaseInstaller {
177177}
178178
179179export class LinterInstaller extends BaseInstaller {
180- protected async promptToInstallImplementation ( product : Product , resource ?: Uri ) : Promise < InstallerResponse > {
180+ protected async promptToInstallImplementation ( product : Product , resource ?: Uri , cancel ?: CancellationToken ) : Promise < InstallerResponse > {
181181 const isPylint = product === Product . pylint ;
182182
183183 const productName = ProductNames . get ( product ) ! ;
@@ -202,7 +202,7 @@ export class LinterInstaller extends BaseInstaller {
202202 const response = await this . appShell . showErrorMessage ( message , ...options ) ;
203203 if ( response === install ) {
204204 sendTelemetryEvent ( EventName . LINTER_NOT_INSTALLED_PROMPT , undefined , { tool : productName as LinterId , action : 'install' } ) ;
205- return this . install ( product , resource ) ;
205+ return this . install ( product , resource , cancel ) ;
206206 } else if ( response === disableInstallPrompt ) {
207207 await this . setStoredResponse ( disableLinterInstallPromptKey , true ) ;
208208 sendTelemetryEvent ( EventName . LINTER_NOT_INSTALLED_PROMPT , undefined , { tool : productName as LinterId , action : 'disablePrompt' } ) ;
@@ -250,7 +250,7 @@ export class LinterInstaller extends BaseInstaller {
250250}
251251
252252export class TestFrameworkInstaller extends BaseInstaller {
253- protected async promptToInstallImplementation ( product : Product , resource ?: Uri ) : Promise < InstallerResponse > {
253+ protected async promptToInstallImplementation ( product : Product , resource ?: Uri , cancel ?: CancellationToken ) : Promise < InstallerResponse > {
254254 const productName = ProductNames . get ( product ) ! ;
255255
256256 const options : string [ ] = [ ] ;
@@ -263,23 +263,23 @@ export class TestFrameworkInstaller extends BaseInstaller {
263263 }
264264
265265 const item = await this . appShell . showErrorMessage ( message , ...options ) ;
266- return item === 'Yes' ? this . install ( product , resource ) : InstallerResponse . Ignore ;
266+ return item === 'Yes' ? this . install ( product , resource , cancel ) : InstallerResponse . Ignore ;
267267 }
268268}
269269
270270export class RefactoringLibraryInstaller extends BaseInstaller {
271- protected async promptToInstallImplementation ( product : Product , resource ?: Uri ) : Promise < InstallerResponse > {
271+ protected async promptToInstallImplementation ( product : Product , resource ?: Uri , cancel ?: CancellationToken ) : Promise < InstallerResponse > {
272272 const productName = ProductNames . get ( product ) ! ;
273273 const item = await this . appShell . showErrorMessage ( `Refactoring library ${ productName } is not installed. Install?` , 'Yes' , 'No' ) ;
274- return item === 'Yes' ? this . install ( product , resource ) : InstallerResponse . Ignore ;
274+ return item === 'Yes' ? this . install ( product , resource , cancel ) : InstallerResponse . Ignore ;
275275 }
276276}
277277
278278export class DataScienceInstaller extends BaseInstaller {
279- protected async promptToInstallImplementation ( product : Product , resource ?: InterpreterUri ) : Promise < InstallerResponse > {
279+ protected async promptToInstallImplementation ( product : Product , resource ?: InterpreterUri , cancel ?: CancellationToken ) : Promise < InstallerResponse > {
280280 const productName = ProductNames . get ( product ) ! ;
281281 const item = await this . appShell . showErrorMessage ( localize . DataScience . libraryNotInstalled ( ) . format ( productName ) , 'Yes' , 'No' ) ;
282- return item === 'Yes' ? this . install ( product , resource ) : InstallerResponse . Ignore ;
282+ return item === 'Yes' ? this . install ( product , resource , cancel ) : InstallerResponse . Ignore ;
283283 }
284284}
285285
@@ -294,11 +294,11 @@ export class ProductInstaller implements IInstaller {
294294
295295 // tslint:disable-next-line:no-empty
296296 public dispose ( ) { }
297- public async promptToInstall ( product : Product , resource ?: InterpreterUri ) : Promise < InstallerResponse > {
298- return this . createInstaller ( product ) . promptToInstall ( product , resource ) ;
297+ public async promptToInstall ( product : Product , resource ?: InterpreterUri , cancel ?: CancellationToken ) : Promise < InstallerResponse > {
298+ return this . createInstaller ( product ) . promptToInstall ( product , resource , cancel ) ;
299299 }
300- public async install ( product : Product , resource ?: InterpreterUri ) : Promise < InstallerResponse > {
301- return this . createInstaller ( product ) . install ( product , resource ) ;
300+ public async install ( product : Product , resource ?: InterpreterUri , cancel ?: CancellationToken ) : Promise < InstallerResponse > {
301+ return this . createInstaller ( product ) . install ( product , resource , cancel ) ;
302302 }
303303 public async isInstalled ( product : Product , resource ?: InterpreterUri ) : Promise < boolean | undefined > {
304304 return this . createInstaller ( product ) . isInstalled ( product , resource ) ;
0 commit comments