[code-style] IJPL-179136 include the just-computed settings object in CodeStyleSettingsChangeEvent

CodeStyleSettingsChangeEvent sent to notify listeners that a value has just finished computing now includes the just-computed CodeStyleSettings object.

Listeners should use this object instead of fetching settings again via `CodeStyle.getSettings(project, vfile)` or similar file-specific calls.

GitOrigin-RevId: 57705c6faf8190858fe3dc962bb498935ae1c1e8
This commit is contained in:
Vojtech Balik
2025-08-18 13:02:49 +02:00
committed by intellij-monorepo-bot
parent d8eab0916a
commit b9b5457866
5 changed files with 36 additions and 3 deletions

View File

@@ -6,6 +6,8 @@ f:com.intellij.formatting.Indent$Type
- *sf:OUTDENT_SPACES:com.intellij.formatting.Indent$Type
c:com.intellij.openapi.editor.EditorModificationUtilEx
- *s:calcAfterLineEnd(com.intellij.openapi.editor.Editor,I,com.intellij.openapi.editor.LogicalPosition,com.intellij.openapi.editor.VisualPosition):I
f:com.intellij.psi.codeStyle.CodeStyleSettingsChangeEvent
- *:getSettings():com.intellij.psi.codeStyle.CodeStyleSettings
*:com.intellij.psi.codeStyle.CommentStyleSettings
- a:isBlockCommentIncludesSpace():Z
- a:isLineCommentFollowedWithSpace():Z

View File

@@ -13,11 +13,18 @@ import org.jetbrains.annotations.Nullable;
public final class CodeStyleSettingsChangeEvent {
private final @NotNull Project myProject;
private final @Nullable VirtualFile myFile;
private final @Nullable CodeStyleSettings mySettings;
@ApiStatus.Internal
public CodeStyleSettingsChangeEvent(@NotNull Project project, @Nullable VirtualFile file) {
this(project, file, null);
}
@ApiStatus.Internal
public CodeStyleSettingsChangeEvent(@NotNull Project project, @Nullable VirtualFile file, @Nullable CodeStyleSettings settings) {
myFile = file;
myProject = project;
mySettings = settings;
}
/**
@@ -33,4 +40,19 @@ public final class CodeStyleSettingsChangeEvent {
public @NotNull Project getProject() {
return myProject;
}
/**
* Non-null value if the reason for the event is that async computation of code style settings just finished.
* Non-null value also implies {@link #getVirtualFile()} is not null.
* <p>
* If non-null, the value should be used directly when handling the event instead of
* {@link com.intellij.application.options.CodeStyle#getSettings(Project, VirtualFile)},
* or similar file-specific calls.
*
* @return The current code style settings for {@link #getVirtualFile()}
*/
@ApiStatus.Experimental
public @Nullable CodeStyleSettings getSettings() {
return mySettings;
}
}

View File

@@ -386,12 +386,17 @@ public class CodeStyleSettingsManager implements PersistentStateComponentWithMod
getMessageBus().connect().subscribe(CodeStyleSettingsListener.TOPIC, listener);
}
public void fireCodeStyleSettingsChanged(@NotNull VirtualFile file) {
@ApiStatus.Internal
public void fireCodeStyleSettingsChanged(@NotNull VirtualFile file, @Nullable CodeStyleSettings settings) {
if (getProject() != null) {
fireCodeStyleSettingsChanged(new CodeStyleSettingsChangeEvent(getProject(), file));
fireCodeStyleSettingsChanged(new CodeStyleSettingsChangeEvent(getProject(), file, settings));
}
}
public void fireCodeStyleSettingsChanged(@NotNull VirtualFile file) {
fireCodeStyleSettingsChanged(file, null);
}
public void fireCodeStyleSettingsChanged() {
if (getProject() != null) {
fireCodeStyleSettingsChanged(new CodeStyleSettingsChangeEvent(getProject(), null));

View File

@@ -283,7 +283,8 @@ internal class CodeStyleCachedValueProvider(val fileSupplier: Supplier<VirtualFi
*/
if (!TooFrequentCodeStyleComputationWatcher.getInstance(project).isTooHighEvictionRateDetected()
&& !Registry.`is`("disable.codeStyleSettingsChanged.events.on.settings.cached")) {
settingsManager.fireCodeStyleSettingsChanged(file)
val eventSettings = if (Registry.`is`("code.style.cache.change.events.include.settings")) currentResult else null
settingsManager.fireCodeStyleSettingsChanged(file, eventSettings)
}
}
computation.reset()

View File

@@ -118,6 +118,9 @@
description="Maximum size of the code style settings cache (>= 1)."
key="code.style.cache.maximum.size"
restartRequired="true" />
<registryKey defaultValue="true"
description="Include code style settings in change events if the reason is computation of the settings has just finished."
key="code.style.cache.change.events.include.settings" />"
<!-- endregion -->
<projectService serviceInterface="com.intellij.util.indexing.IndexableFilesIndex"