From 167e010841969e8f1c51ff913868cda34c444fc2 Mon Sep 17 00:00:00 2001 From: Erik De Bonte Date: Wed, 15 Feb 2023 14:48:44 -0800 Subject: [PATCH 1/2] Don't set formatOnType if user has set it --- src/client/activation/node/analysisOptions.ts | 38 ++++++++++++++----- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/src/client/activation/node/analysisOptions.ts b/src/client/activation/node/analysisOptions.ts index 4e2320b42331..1cda7bad5517 100644 --- a/src/client/activation/node/analysisOptions.ts +++ b/src/client/activation/node/analysisOptions.ts @@ -43,22 +43,40 @@ export class NodeLanguageServerAnalysisOptions extends LanguageServerAnalysisOpt } private async isAutoIndentEnabled() { - const editorConfig = this.getPythonSpecificEditorSection(); - const formatOnTypeInspect = editorConfig.inspect(FORMAT_ON_TYPE_CONFIG_SETTING); - const formatOnTypeSetForPython = formatOnTypeInspect?.globalLanguageValue !== undefined; - - const inExperiment = await this.isInAutoIndentExperiment(); - // only explicitly enable formatOnType for those who are in the experiment - // but have not explicitly given a value for the setting - if (!formatOnTypeSetForPython && inExperiment) { - await NodeLanguageServerAnalysisOptions.setPythonSpecificFormatOnType(editorConfig, true); + let editorConfig = this.getPythonSpecificEditorSection(); + + if (!NodeLanguageServerAnalysisOptions.isConfigSettingSetByUser(editorConfig, FORMAT_ON_TYPE_CONFIG_SETTING)) { + const inExperiment = await this.isInAutoIndentExperiment(); + + // only explicitly enable formatOnType for those who are in the experiment + // but have not explicitly given a value for the setting + if (inExperiment) { + await NodeLanguageServerAnalysisOptions.setPythonSpecificFormatOnType(editorConfig, true); + editorConfig = this.getPythonSpecificEditorSection(); + } } - const formatOnTypeEffectiveValue = this.getPythonSpecificEditorSection().get(FORMAT_ON_TYPE_CONFIG_SETTING); + const formatOnTypeEffectiveValue = editorConfig.get(FORMAT_ON_TYPE_CONFIG_SETTING); return formatOnTypeEffectiveValue; } + private static isConfigSettingSetByUser(configuration: WorkspaceConfiguration, setting: string): boolean { + const inspect = configuration.inspect(setting); + if (inspect === undefined) { + return false; + } + + return ( + inspect.globalValue !== undefined || + inspect.workspaceValue !== undefined || + inspect.workspaceFolderValue !== undefined || + inspect.globalLanguageValue !== undefined || + inspect.workspaceLanguageValue !== undefined || + inspect.workspaceFolderLanguageValue !== undefined + ); + } + private async isInAutoIndentExperiment(): Promise { if (await this.experimentService.inExperiment('pylanceAutoIndent')) { return true; From 3beb0e7e3bd4963b54ae6803a5e88ccc5c1de809 Mon Sep 17 00:00:00 2001 From: Erik De Bonte Date: Thu, 16 Feb 2023 10:04:43 -0800 Subject: [PATCH 2/2] Update comments --- src/client/activation/node/analysisOptions.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/client/activation/node/analysisOptions.ts b/src/client/activation/node/analysisOptions.ts index 1cda7bad5517..f717a8e2f3f1 100644 --- a/src/client/activation/node/analysisOptions.ts +++ b/src/client/activation/node/analysisOptions.ts @@ -45,13 +45,14 @@ export class NodeLanguageServerAnalysisOptions extends LanguageServerAnalysisOpt private async isAutoIndentEnabled() { let editorConfig = this.getPythonSpecificEditorSection(); + // Only explicitly enable formatOnType for those who are in the experiment + // but have not explicitly given a value for the setting if (!NodeLanguageServerAnalysisOptions.isConfigSettingSetByUser(editorConfig, FORMAT_ON_TYPE_CONFIG_SETTING)) { const inExperiment = await this.isInAutoIndentExperiment(); - - // only explicitly enable formatOnType for those who are in the experiment - // but have not explicitly given a value for the setting if (inExperiment) { await NodeLanguageServerAnalysisOptions.setPythonSpecificFormatOnType(editorConfig, true); + + // Refresh our view of the config settings. editorConfig = this.getPythonSpecificEditorSection(); } }