2
2
// Licensed under the MIT License.
3
3
4
4
import { Uri } from 'vscode' ;
5
+ import { inject , injectable } from 'inversify' ;
5
6
import { IDisposableRegistry } from '../../common/types' ;
6
7
import { Common , ToolsExtensions } from '../../common/utils/localize' ;
7
8
import { isExtensionEnabled } from '../../common/vscodeApis/extensionsApi' ;
@@ -18,31 +19,32 @@ import { AUTOPEP8_EXTENSION, BLACK_EXTENSION, IInstallFormatterPrompt } from './
18
19
19
20
const SHOW_FORMATTER_INSTALL_PROMPT_DONOTSHOW_KEY = 'showFormatterExtensionInstallPrompt' ;
20
21
22
+ @injectable ( )
21
23
export class InstallFormatterPrompt implements IInstallFormatterPrompt {
22
24
private shownThisSession = false ;
23
25
24
- constructor ( private readonly serviceContainer : IServiceContainer ) { }
26
+ constructor ( @ inject ( IServiceContainer ) private readonly serviceContainer : IServiceContainer ) { }
25
27
26
- public async showInstallFormatterPrompt ( resource ?: Uri ) : Promise < void > {
28
+ public async showInstallFormatterPrompt ( resource ?: Uri ) : Promise < boolean > {
27
29
if ( ! inFormatterExtensionExperiment ( this . serviceContainer ) ) {
28
- return ;
30
+ return false ;
29
31
}
30
32
31
33
const promptState = doNotShowPromptState ( SHOW_FORMATTER_INSTALL_PROMPT_DONOTSHOW_KEY , this . serviceContainer ) ;
32
34
if ( this . shownThisSession || promptState . value ) {
33
- return ;
35
+ return false ;
34
36
}
35
37
36
38
const config = getConfiguration ( 'python' , resource ) ;
37
39
const formatter = config . get < string > ( 'formatting.provider' , 'none' ) ;
38
40
if ( ! [ 'autopep8' , 'black' ] . includes ( formatter ) ) {
39
- return ;
41
+ return false ;
40
42
}
41
43
42
44
const editorConfig = getConfiguration ( 'editor' , { uri : resource , languageId : 'python' } ) ;
43
45
const defaultFormatter = editorConfig . get < string > ( 'defaultFormatter' , '' ) ;
44
46
if ( [ BLACK_EXTENSION , AUTOPEP8_EXTENSION ] . includes ( defaultFormatter ) ) {
45
- return ;
47
+ return false ;
46
48
}
47
49
48
50
const black = isExtensionEnabled ( BLACK_EXTENSION ) ;
@@ -111,12 +113,14 @@ export class InstallFormatterPrompt implements IInstallFormatterPrompt {
111
113
} else if ( selection === Common . doNotShowAgain ) {
112
114
await promptState . updateValue ( true ) ;
113
115
}
116
+
117
+ return this . shownThisSession ;
114
118
}
115
119
}
116
120
117
121
export function registerInstallFormatterPrompt ( serviceContainer : IServiceContainer ) : void {
118
122
const disposables = serviceContainer . get < IDisposableRegistry > ( IDisposableRegistry ) ;
119
- const installFormatterPrompt = new InstallFormatterPrompt ( serviceContainer ) ;
123
+ const installFormatterPrompt = serviceContainer . get < IInstallFormatterPrompt > ( IInstallFormatterPrompt ) ;
120
124
disposables . push (
121
125
onDidSaveTextDocument ( async ( e ) => {
122
126
const editorConfig = getConfiguration ( 'editor' , { uri : e . uri , languageId : 'python' } ) ;
0 commit comments