IJPL-846 cleanup, prefer serviceAsync

GitOrigin-RevId: 219325e0230cb61fec5e3dd09ac37e88320635f0
This commit is contained in:
Vladimir Krivosheev
2024-03-23 16:58:40 +00:00
committed by intellij-monorepo-bot
parent 9e09062dc3
commit 8c51490eae
5 changed files with 62 additions and 64 deletions
@@ -271,7 +271,7 @@ public class HighlightingMarkupGrave {
}
HighlightInfo info = HighlightInfo.fromRangeHighlighter(highlighter);
if (info != null &&
(info.getSeverity().compareTo(HighlightSeverity.INFORMATION) > 0 // either warning/error or symbol type (e.g. field text attribute)
(info.getSeverity().compareTo(HighlightSeverity.INFORMATION) > 0 // either warning/error or symbol type (e.g., field text attribute)
|| info.getSeverity() == HighlightInfoType.SYMBOL_TYPE_SEVERITY)) {
return true;
}
@@ -362,9 +362,9 @@ public class HighlightingMarkupGrave {
}
private void writeTextAttributesKey(@NotNull DataOutput out) throws IOException {
boolean attributesKeyExists = textAttributesKey != null;
out.writeBoolean(attributesKeyExists);
if (attributesKeyExists) {
boolean attributeKeyExists = textAttributesKey != null;
out.writeBoolean(attributeKeyExists);
if (attributeKeyExists) {
IOUtil.writeUTF(out, textAttributesKey.getExternalName());
}
}
@@ -413,7 +413,7 @@ public class HighlightingMarkupGrave {
return STORE_NEW;
}
if (oldMarkup == null) {
// no a limb to put in grave
// no, a limb to put in grave
return KEEP_OLD;
}
if (oldMarkup.contentHash() != newMarkup.contentHash() && !newMarkup.isEmpty()) {
@@ -429,7 +429,7 @@ public class HighlightingMarkupGrave {
return KEEP_OLD;
}
if (isNewMoreRelevant == null) {
// should never happen. file is closed without being opened before
// should never happen. the file is closed without being opened before
return STORE_NEW;
}
if (isNewMoreRelevant) {
@@ -482,6 +482,6 @@ public class HighlightingMarkupGrave {
}
private void logFusStatistic(@NotNull VirtualFileWithId file, @NotNull MarkupGraveEvent event, int restoredCount) {
FileEditorCollector.logEditorMarkupGrave(myProject, (VirtualFile) file, event, restoredCount);
FileEditorCollector.INSTANCE.logEditorMarkupGrave(myProject, (VirtualFile) file, event, restoredCount);
}
}
@@ -1,4 +1,4 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.featureStatistics.fusCollectors
import com.intellij.internal.statistic.eventLog.EventLogGroup
@@ -22,17 +22,17 @@ object FileEditorCollector : CounterUsagesCollector() {
EventFields.Enum<MarkupGraveEvent>("markup_grave_event"),
EventFields.Int("restored_highlighters"))
@JvmStatic
fun logAlternativeFileEditorSelected(project: Project, file: VirtualFile, editor: FileEditor) {
ALTERNATIVE_FILE_EDITOR_SELECTED.log(project, FILE_EDITOR_FIELD.with(editor.javaClass), EventFields.AnonymizedPath.with(file.path))
ALTERNATIVE_FILE_EDITOR_SELECTED.log(
project = project,
pairs = listOf(FILE_EDITOR_FIELD.with(editor.javaClass), EventFields.AnonymizedPath.with(file.path)),
)
}
@JvmStatic
fun logEditorEmptyState(project: Project, cause: EmptyStateCause) {
EDITOR_EMPTY_STATE_SHOWN.log(project, cause)
}
@JvmStatic
fun logEditorMarkupGrave(project: Project, file: VirtualFile, graveEvent: MarkupGraveEvent, restoredCount: Int) {
EDITOR_MARKUP_RESTORED.log(project, file.path, graveEvent, restoredCount)
}
@@ -91,7 +91,7 @@ private const val IDE_FINGERPRINT: @NonNls String = "ideFingerprint"
@DirtyUI
open class EditorsSplitters internal constructor(
val manager: FileEditorManagerImpl,
internal val coroutineScope: CoroutineScope,
@JvmField internal val coroutineScope: CoroutineScope,
) : JPanel(BorderLayout()), UISettingsListener {
companion object {
const val SPLITTER_KEY: @NonNls String = "EditorsSplitters"
@@ -103,7 +103,6 @@ open class EditorsSplitters internal constructor(
}
}
@JvmStatic
fun findDefaultComponentInSplitters(project: Project?): JComponent? {
return getSplittersToFocus(project)?.currentWindow?.selectedComposite?.preferredFocusedComponent
}
@@ -91,7 +91,6 @@ import com.intellij.util.messages.impl.MessageListenerList
import com.intellij.util.ui.EDT
import com.intellij.util.ui.UIUtil
import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet
import kotlinx.collections.immutable.persistentSetOf
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.*
@@ -220,37 +219,38 @@ open class FileEditorManagerImpl(
}
.stateIn(coroutineScope, SharingStarted.Eagerly, null)
val publisher = project.messageBus.syncPublisher(FileEditorManagerListener.FILE_EDITOR_MANAGER)
coroutineScope.launch {
val publisher = project.messageBus.syncPublisher(FileEditorManagerListener.FILE_EDITOR_MANAGER)
// not using collectLatest() to ensure that the listeners miss no selection update
selectionFlow
.zipWithNext { oldState, state ->
val oldEditorWithProvider = oldState?.fileEditorProvider
val newEditorWithProvider = state?.fileEditorProvider
if (oldEditorWithProvider == newEditorWithProvider) {
return@zipWithNext
}
// not using collectLatest() to ensure that the listeners miss no selection update
selectionFlow
.zipWithNext { oldState, state ->
val oldEditorWithProvider = oldState?.fileEditorProvider
val newEditorWithProvider = state?.fileEditorProvider
if (oldEditorWithProvider == newEditorWithProvider) {
return@zipWithNext
}
// expected in EDT
withContext(Dispatchers.EDT) {
blockingContext {
kotlin.runCatching {
fireSelectionChanged(newComposite = state?.composite,
oldEditorWithProvider = oldEditorWithProvider,
newEditorWithProvider = newEditorWithProvider,
publisher = publisher)
// expected in EDT
withContext(Dispatchers.EDT) {
runCatching {
fireSelectionChanged(
newComposite = state?.composite,
oldEditorWithProvider = oldEditorWithProvider,
newEditorWithProvider = newEditorWithProvider,
publisher = publisher,
)
}.getOrLogException(LOG)
}
}
}
.launchIn(coroutineScope)
.collect()
}
currentFileEditorFlow = selectionFlow
.map { it?.fileEditorProvider?.fileEditor }
.stateIn(coroutineScope, SharingStarted.Eagerly, null)
val dumbModeFinishedScope = coroutineScope.childScope()
dumbModeFinishedScope.launch(start = CoroutineStart.UNDISPATCHED) {
coroutineScope.launch {
dumbModeFinishedFlow.collectLatest {
dumbModeFinished(project)
}
@@ -424,7 +424,7 @@ open class FileEditorManagerImpl(
getAllSplitters()
}
val providerManager = FileEditorProviderManager.getInstance()
val providerManager = serviceAsync<FileEditorProviderManager>()
// predictable order of iteration
val fileToNewProviders = openedComposites.groupByTo(LinkedHashMap()) { it.file }.entries.mapNotNull { entry ->
val composites = entry.value
@@ -435,13 +435,15 @@ open class FileEditorManagerImpl(
null
}
else {
file to composites.map { composite -> composite to newProviders }
file to composites.map { it to newProviders }
}
}
for ((file, toOpen) in fileToNewProviders) {
withContext(Dispatchers.EDT) {
for ((composite, providers) in toOpen) {
if (!openedComposites.contains(composite)) continue
if (!openedComposites.contains(composite)) {
continue
}
for (provider in providers) {
val editor = provider.createEditor(project, file)
@@ -472,10 +474,11 @@ open class FileEditorManagerImpl(
fun getAllSplitters(): Set<EditorsSplitters> {
// ordered
var result = persistentSetOf(mainSplitters)
val result = LinkedHashSet<EditorsSplitters>()
result.add(mainSplitters)
for (container in DockManager.getInstance(project).containers) {
if (container is DockableEditorTabbedContainer) {
result = result.add(container.splitters)
result.add(container.splitters)
}
}
return result
@@ -485,10 +488,7 @@ open class FileEditorManagerImpl(
val result = CompletableDeferred<EditorsSplitters?>()
val focusManager = IdeFocusManager.getGlobalInstance()
focusManager.doWhenFocusSettlesDown {
result.complete(
if (project.isDisposed) null
else getDockContainer(focusManager.focusOwner)?.splitters ?: mainSplitters
)
result.complete(if (project.isDisposed) null else getDockContainer(focusManager.focusOwner)?.splitters ?: mainSplitters)
}
return result
}
@@ -508,8 +508,8 @@ open class FileEditorManagerImpl(
}
private fun getDockContainer(focusOwner: Component?): DockableEditorTabbedContainer? {
return DockManager.getInstance(project).getContainerFor(
focusOwner) { it is DockableEditorTabbedContainer } as DockableEditorTabbedContainer?
return DockManager.getInstance(project)
.getContainerFor(focusOwner) { it is DockableEditorTabbedContainer } as DockableEditorTabbedContainer?
}
override val preferredFocusedComponent: JComponent?
@@ -1728,23 +1728,22 @@ open class FileEditorManagerImpl(
?: allClientFileEditorManagers.firstNotNullOfOrNull { it.getComposite(editor) }
}
private fun fireSelectionChanged(newComposite: EditorComposite?,
oldEditorWithProvider: FileEditorWithProvider?,
newEditorWithProvider: FileEditorWithProvider?,
publisher: FileEditorManagerListener) {
val task = {
oldEditorWithProvider?.fileEditor?.deselectNotify()
val newEditor = newEditorWithProvider?.fileEditor
if (newEditor != null) {
private suspend fun fireSelectionChanged(
newComposite: EditorComposite?,
oldEditorWithProvider: FileEditorWithProvider?,
newEditorWithProvider: FileEditorWithProvider?,
publisher: FileEditorManagerListener,
) {
oldEditorWithProvider?.fileEditor?.deselectNotify()
val newEditor = newEditorWithProvider?.fileEditor
if (newEditor != null) {
blockingContext {
newEditor.selectNotify()
FileEditorCollector.logAlternativeFileEditorSelected(project, newComposite!!.file, newEditor)
(FileEditorProviderManager.getInstance() as FileEditorProviderManagerImpl).providerSelected(newComposite)
}
IdeDocumentHistory.getInstance(project).onSelectionChanged()
FileEditorCollector.logAlternativeFileEditorSelected(project = project, file = newComposite!!.file, editor = newEditor)
(serviceAsync<FileEditorProviderManager>() as FileEditorProviderManagerImpl).providerSelected(newComposite)
}
task()
project.serviceAsync<IdeDocumentHistory>().onSelectionChanged()
val newFile = newComposite?.file
if (newFile != null) {
@@ -1,4 +1,4 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.openapi.wm.ex;
import com.intellij.openapi.editor.impl.EditorComponentImpl;
@@ -52,7 +52,7 @@ public class IdeFocusTraversalPolicy extends LayoutFocusTraversalPolicy {
}
if (siblingComponent instanceof EditorsSplitters) {
Component defaultFocusableComponent = EditorsSplitters.findDefaultComponentInSplitters(getProject());
Component defaultFocusableComponent = EditorsSplitters.Companion.findDefaultComponentInSplitters(getProject());
if (defaultFocusableComponent != null) {
return defaultFocusableComponent;
}
@@ -164,7 +164,7 @@ public class IdeFocusTraversalPolicy extends LayoutFocusTraversalPolicy {
component instanceof JComboBox;
}
// Create our own subclass and change accept to public so that we can call accept.
// Create our own subclass and change accepts to public so that we can call accept.
private static final class SwingDefaultFocusTraversalPolicy extends DefaultFocusTraversalPolicy {
@Override
public boolean accept(Component aComponent) {