Skip to content

Commit 2152cd9

Browse files
authored
Don't set formatOnType for auto-indent experiment if it's already set (#20710)
1 parent 995b0bc commit 2152cd9

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

src/client/activation/node/analysisOptions.ts

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,41 @@ export class NodeLanguageServerAnalysisOptions extends LanguageServerAnalysisOpt
4343
}
4444

4545
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();
4947

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
5249
// 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+
}
5558
}
5659

57-
const formatOnTypeEffectiveValue = this.getPythonSpecificEditorSection().get(FORMAT_ON_TYPE_CONFIG_SETTING);
60+
const formatOnTypeEffectiveValue = editorConfig.get(FORMAT_ON_TYPE_CONFIG_SETTING);
5861

5962
return formatOnTypeEffectiveValue;
6063
}
6164

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+
6281
private async isInAutoIndentExperiment(): Promise<boolean> {
6382
if (await this.experimentService.inExperiment('pylanceAutoIndent')) {
6483
return true;

0 commit comments

Comments
 (0)