@@ -21,17 +21,21 @@ const SHOW_FORMATTER_INSTALL_PROMPT_DONOTSHOW_KEY = 'showFormatterExtensionInsta
21
21
22
22
@injectable ( )
23
23
export class InstallFormatterPrompt implements IInstallFormatterPrompt {
24
- private shownThisSession = false ;
24
+ private currentlyShown = false ;
25
25
26
26
constructor ( @inject ( IServiceContainer ) private readonly serviceContainer : IServiceContainer ) { }
27
27
28
+ /*
29
+ * This method is called when the user saves a python file or a cell.
30
+ * Returns true if an extension was selected. Otherwise returns false.
31
+ */
28
32
public async showInstallFormatterPrompt ( resource ?: Uri ) : Promise < boolean > {
29
33
if ( ! inFormatterExtensionExperiment ( this . serviceContainer ) ) {
30
34
return false ;
31
35
}
32
36
33
37
const promptState = doNotShowPromptState ( SHOW_FORMATTER_INSTALL_PROMPT_DONOTSHOW_KEY , this . serviceContainer ) ;
34
- if ( this . shownThisSession || promptState . value ) {
38
+ if ( this . currentlyShown || promptState . value ) {
35
39
return false ;
36
40
}
37
41
@@ -53,7 +57,7 @@ export class InstallFormatterPrompt implements IInstallFormatterPrompt {
53
57
let selection : string | undefined ;
54
58
55
59
if ( black || autopep8 ) {
56
- this . shownThisSession = true ;
60
+ this . currentlyShown = true ;
57
61
if ( black && autopep8 ) {
58
62
selection = await showInformationMessage (
59
63
ToolsExtensions . selectMultipleFormattersPrompt ,
@@ -81,15 +85,15 @@ export class InstallFormatterPrompt implements IInstallFormatterPrompt {
81
85
}
82
86
}
83
87
} else if ( formatter === 'black' && ! black ) {
84
- this . shownThisSession = true ;
88
+ this . currentlyShown = true ;
85
89
selection = await showInformationMessage (
86
90
ToolsExtensions . installBlackFormatterPrompt ,
87
91
'Black' ,
88
92
'Autopep8' ,
89
93
Common . doNotShowAgain ,
90
94
) ;
91
95
} else if ( formatter === 'autopep8' && ! autopep8 ) {
92
- this . shownThisSession = true ;
96
+ this . currentlyShown = true ;
93
97
selection = await showInformationMessage (
94
98
ToolsExtensions . installAutopep8FormatterPrompt ,
95
99
'Black' ,
@@ -98,23 +102,32 @@ export class InstallFormatterPrompt implements IInstallFormatterPrompt {
98
102
) ;
99
103
}
100
104
105
+ let userSelectedAnExtension = false ;
101
106
if ( selection === 'Black' ) {
102
107
if ( black ) {
108
+ userSelectedAnExtension = true ;
103
109
await updateDefaultFormatter ( BLACK_EXTENSION , resource ) ;
104
110
} else {
111
+ userSelectedAnExtension = true ;
105
112
await installFormatterExtension ( BLACK_EXTENSION , resource ) ;
106
113
}
107
114
} else if ( selection === 'Autopep8' ) {
108
115
if ( autopep8 ) {
116
+ userSelectedAnExtension = true ;
109
117
await updateDefaultFormatter ( AUTOPEP8_EXTENSION , resource ) ;
110
118
} else {
119
+ userSelectedAnExtension = true ;
111
120
await installFormatterExtension ( AUTOPEP8_EXTENSION , resource ) ;
112
121
}
113
122
} else if ( selection === Common . doNotShowAgain ) {
123
+ userSelectedAnExtension = false ;
114
124
await promptState . updateValue ( true ) ;
125
+ } else {
126
+ userSelectedAnExtension = false ;
115
127
}
116
128
117
- return this . shownThisSession ;
129
+ this . currentlyShown = false ;
130
+ return userSelectedAnExtension ;
118
131
}
119
132
}
120
133
0 commit comments