@@ -43,22 +43,41 @@ export class NodeLanguageServerAnalysisOptions extends LanguageServerAnalysisOpt
43
43
}
44
44
45
45
private async isAutoIndentEnabled ( ) {
46
- const editorConfig = this . getPythonSpecificEditorSection ( ) ;
47
- const formatOnTypeInspect = editorConfig . inspect ( FORMAT_ON_TYPE_CONFIG_SETTING ) ;
48
- const formatOnTypeSetForPython = formatOnTypeInspect ?. globalLanguageValue !== undefined ;
46
+ let editorConfig = this . getPythonSpecificEditorSection ( ) ;
49
47
50
- const inExperiment = await this . isInAutoIndentExperiment ( ) ;
51
- // only explicitly enable formatOnType for those who are in the experiment
48
+ // Only explicitly enable formatOnType for those who are in the experiment
52
49
// but have not explicitly given a value for the setting
53
- if ( ! formatOnTypeSetForPython && inExperiment ) {
54
- await NodeLanguageServerAnalysisOptions . setPythonSpecificFormatOnType ( editorConfig , true ) ;
50
+ if ( ! NodeLanguageServerAnalysisOptions . isConfigSettingSetByUser ( editorConfig , FORMAT_ON_TYPE_CONFIG_SETTING ) ) {
51
+ const inExperiment = await this . isInAutoIndentExperiment ( ) ;
52
+ if ( inExperiment ) {
53
+ await NodeLanguageServerAnalysisOptions . setPythonSpecificFormatOnType ( editorConfig , true ) ;
54
+
55
+ // Refresh our view of the config settings.
56
+ editorConfig = this . getPythonSpecificEditorSection ( ) ;
57
+ }
55
58
}
56
59
57
- const formatOnTypeEffectiveValue = this . getPythonSpecificEditorSection ( ) . get ( FORMAT_ON_TYPE_CONFIG_SETTING ) ;
60
+ const formatOnTypeEffectiveValue = editorConfig . get ( FORMAT_ON_TYPE_CONFIG_SETTING ) ;
58
61
59
62
return formatOnTypeEffectiveValue ;
60
63
}
61
64
65
+ private static isConfigSettingSetByUser ( configuration : WorkspaceConfiguration , setting : string ) : boolean {
66
+ const inspect = configuration . inspect ( setting ) ;
67
+ if ( inspect === undefined ) {
68
+ return false ;
69
+ }
70
+
71
+ return (
72
+ inspect . globalValue !== undefined ||
73
+ inspect . workspaceValue !== undefined ||
74
+ inspect . workspaceFolderValue !== undefined ||
75
+ inspect . globalLanguageValue !== undefined ||
76
+ inspect . workspaceLanguageValue !== undefined ||
77
+ inspect . workspaceFolderLanguageValue !== undefined
78
+ ) ;
79
+ }
80
+
62
81
private async isInAutoIndentExperiment ( ) : Promise < boolean > {
63
82
if ( await this . experimentService . inExperiment ( 'pylanceAutoIndent' ) ) {
64
83
return true ;
0 commit comments