Skip to content

Don't set formatOnType for auto-indent experiment if it's already set #20710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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