Skip to content

Commit

Permalink
Make auto indent depend on formatOnType setting value (#20480)
Browse files Browse the repository at this point in the history
For #20479
  • Loading branch information
luabud authored Jan 6, 2023
1 parent e6b2752 commit 90cb829
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/client/activation/node/analysisOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,19 @@ export class NodeLanguageServerAnalysisOptions extends LanguageServerAnalysisOpt

private async isAutoIndentEnabled() {
const editorConfig = this.getPythonSpecificEditorSection();
let formatOnTypeEffectiveValue = editorConfig.get(FORMAT_ON_TYPE_CONFIG_SETTING);
const formatOnTypeInspect = editorConfig.inspect(FORMAT_ON_TYPE_CONFIG_SETTING);
const formatOnTypeSetForPython = formatOnTypeInspect?.globalLanguageValue !== undefined;

const inExperiment = await this.isInAutoIndentExperiment();

if (inExperiment !== formatOnTypeSetForPython) {
if (inExperiment) {
await NodeLanguageServerAnalysisOptions.setPythonSpecificFormatOnType(editorConfig, true);
} else if (formatOnTypeInspect?.globalLanguageValue !== false) {
await NodeLanguageServerAnalysisOptions.setPythonSpecificFormatOnType(editorConfig, undefined);
}

formatOnTypeEffectiveValue = this.getPythonSpecificEditorSection().get(FORMAT_ON_TYPE_CONFIG_SETTING);
// 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);
}

return inExperiment && formatOnTypeEffectiveValue;
const formatOnTypeEffectiveValue = this.getPythonSpecificEditorSection().get(FORMAT_ON_TYPE_CONFIG_SETTING);

return formatOnTypeEffectiveValue;
}

private async isInAutoIndentExperiment(): Promise<boolean> {
Expand Down

0 comments on commit 90cb829

Please sign in to comment.