Skip to content

Commit

Permalink
Don't set formatOnType for auto-indent experiment if it's already s…
Browse files Browse the repository at this point in the history
…et (#20710)
  • Loading branch information
debonte authored Feb 16, 2023
1 parent 995b0bc commit 2152cd9
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions src/client/activation/node/analysisOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,41 @@ 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;
let editorConfig = this.getPythonSpecificEditorSection();

const inExperiment = await this.isInAutoIndentExperiment();
// only explicitly enable formatOnType for those who are in the experiment
// 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);
if (!NodeLanguageServerAnalysisOptions.isConfigSettingSetByUser(editorConfig, FORMAT_ON_TYPE_CONFIG_SETTING)) {
const inExperiment = await this.isInAutoIndentExperiment();
if (inExperiment) {
await NodeLanguageServerAnalysisOptions.setPythonSpecificFormatOnType(editorConfig, true);

// Refresh our view of the config settings.
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<boolean> {
if (await this.experimentService.inExperiment('pylanceAutoIndent')) {
return true;
Expand Down

0 comments on commit 2152cd9

Please sign in to comment.