22// Licensed under the MIT License.
33
44import { Uri } from 'vscode' ;
5+ import { inject , injectable } from 'inversify' ;
56import { IDisposableRegistry } from '../../common/types' ;
67import { Common , ToolsExtensions } from '../../common/utils/localize' ;
78import { isExtensionEnabled } from '../../common/vscodeApis/extensionsApi' ;
@@ -18,31 +19,32 @@ import { AUTOPEP8_EXTENSION, BLACK_EXTENSION, IInstallFormatterPrompt } from './
1819
1920const SHOW_FORMATTER_INSTALL_PROMPT_DONOTSHOW_KEY = 'showFormatterExtensionInstallPrompt' ;
2021
22+ @injectable ( )
2123export class InstallFormatterPrompt implements IInstallFormatterPrompt {
2224 private shownThisSession = false ;
2325
24- constructor ( private readonly serviceContainer : IServiceContainer ) { }
26+ constructor ( @ inject ( IServiceContainer ) private readonly serviceContainer : IServiceContainer ) { }
2527
26- public async showInstallFormatterPrompt ( resource ?: Uri ) : Promise < void > {
28+ public async showInstallFormatterPrompt ( resource ?: Uri ) : Promise < boolean > {
2729 if ( ! inFormatterExtensionExperiment ( this . serviceContainer ) ) {
28- return ;
30+ return false ;
2931 }
3032
3133 const promptState = doNotShowPromptState ( SHOW_FORMATTER_INSTALL_PROMPT_DONOTSHOW_KEY , this . serviceContainer ) ;
3234 if ( this . shownThisSession || promptState . value ) {
33- return ;
35+ return false ;
3436 }
3537
3638 const config = getConfiguration ( 'python' , resource ) ;
3739 const formatter = config . get < string > ( 'formatting.provider' , 'none' ) ;
3840 if ( ! [ 'autopep8' , 'black' ] . includes ( formatter ) ) {
39- return ;
41+ return false ;
4042 }
4143
4244 const editorConfig = getConfiguration ( 'editor' , { uri : resource , languageId : 'python' } ) ;
4345 const defaultFormatter = editorConfig . get < string > ( 'defaultFormatter' , '' ) ;
4446 if ( [ BLACK_EXTENSION , AUTOPEP8_EXTENSION ] . includes ( defaultFormatter ) ) {
45- return ;
47+ return false ;
4648 }
4749
4850 const black = isExtensionEnabled ( BLACK_EXTENSION ) ;
@@ -111,12 +113,14 @@ export class InstallFormatterPrompt implements IInstallFormatterPrompt {
111113 } else if ( selection === Common . doNotShowAgain ) {
112114 await promptState . updateValue ( true ) ;
113115 }
116+
117+ return this . shownThisSession ;
114118 }
115119}
116120
117121export function registerInstallFormatterPrompt ( serviceContainer : IServiceContainer ) : void {
118122 const disposables = serviceContainer . get < IDisposableRegistry > ( IDisposableRegistry ) ;
119- const installFormatterPrompt = new InstallFormatterPrompt ( serviceContainer ) ;
123+ const installFormatterPrompt = serviceContainer . get < IInstallFormatterPrompt > ( IInstallFormatterPrompt ) ;
120124 disposables . push (
121125 onDidSaveTextDocument ( async ( e ) => {
122126 const editorConfig = getConfiguration ( 'editor' , { uri : e . uri , languageId : 'python' } ) ;
0 commit comments