From 0d0cd711bbab850d0d90ed6ba8667ac905a625ec Mon Sep 17 00:00:00 2001 From: Alexey Utkin Date: Sun, 8 Jun 2025 18:57:25 +0400 Subject: [PATCH] CPP-44970 Enable ClangFormat without creating .clangformat file doesn't change status bar GitOrigin-RevId: 7f6aa50f8cde121c03a3b36416a08cb9ce0ce662 --- .../modifier/TransientCodeStyleSettings.java | 29 ++++++++++++++----- .../cache/CodeStyleCachedValueProvider.kt | 2 +- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/platform/code-style-api/src/com/intellij/psi/codeStyle/modifier/TransientCodeStyleSettings.java b/platform/code-style-api/src/com/intellij/psi/codeStyle/modifier/TransientCodeStyleSettings.java index ffef86b37645..4ebb0452eb47 100644 --- a/platform/code-style-api/src/com/intellij/psi/codeStyle/modifier/TransientCodeStyleSettings.java +++ b/platform/code-style-api/src/com/intellij/psi/codeStyle/modifier/TransientCodeStyleSettings.java @@ -4,6 +4,7 @@ package com.intellij.psi.codeStyle.modifier; import com.intellij.application.options.CodeStyle; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Key; import com.intellij.openapi.util.ModificationTracker; import com.intellij.openapi.util.TextRange; import com.intellij.openapi.vfs.VirtualFile; @@ -93,19 +94,33 @@ public final class TransientCodeStyleSettings extends CodeStyleSettings { applyIndentOptionsFromProviders(file.getProject(), file.getVirtualFile()); } + private static final Key INDENT_OPTIONS_APPLY_PROGRESS = Key.create("INDENT_OPTIONS_APPLY_PROGRESS"); + @ApiStatus.Internal public void applyIndentOptionsFromProviders(@NotNull Project project, @NotNull VirtualFile file) { - for (FileIndentOptionsProvider provider : FileIndentOptionsProvider.EP_NAME.getExtensionList()) { - if (provider.useOnFullReformat()) { - IndentOptions indentOptions = provider.getIndentOptions(project, this, file); - if (indentOptions != null) { - IndentOptions targetOptions = getIndentOptions(file.getFileType()); - if (targetOptions != indentOptions) { - targetOptions.copyFrom(indentOptions); + if (file.getUserData(INDENT_OPTIONS_APPLY_PROGRESS) != null) { + return; + } + + // ClsElementImpl.getIndentSize is called inside document generation procedure, + // which can trigger code style computation based on the document => Stack Overflow. + file.putUserData(INDENT_OPTIONS_APPLY_PROGRESS, Boolean.TRUE); + try { + for (FileIndentOptionsProvider provider : FileIndentOptionsProvider.EP_NAME.getExtensionList()) { + if (provider.useOnFullReformat()) { + IndentOptions indentOptions = provider.getIndentOptions(project, this, file); + if (indentOptions != null) { + IndentOptions targetOptions = getIndentOptions(file.getFileType()); + if (targetOptions != indentOptions) { + targetOptions.copyFrom(indentOptions); + } } } } } + finally { + file.putUserData(INDENT_OPTIONS_APPLY_PROGRESS, null); + } } public void addDependency(@NotNull ModificationTracker dependency) { diff --git a/platform/code-style-impl/src/com/intellij/application/options/codeStyle/cache/CodeStyleCachedValueProvider.kt b/platform/code-style-impl/src/com/intellij/application/options/codeStyle/cache/CodeStyleCachedValueProvider.kt index ba336fe63065..6f0bfdcf2478 100644 --- a/platform/code-style-impl/src/com/intellij/application/options/codeStyle/cache/CodeStyleCachedValueProvider.kt +++ b/platform/code-style-impl/src/com/intellij/application/options/codeStyle/cache/CodeStyleCachedValueProvider.kt @@ -197,7 +197,7 @@ internal class CodeStyleCachedValueProvider(val fileSupplier: Supplier