Check if app is loaded



I'm creating a ToolWindow which requires parsing PsiFile and looking into idicies.

This I solved by moving that logic into ReadAction:

ReadAction.nonBlocking<JComponent> { ...parsePsi }
            .finishOnUiThread(ModalityState.defaultModalityState()) {
                val content = ContentFactory.getInstance().createContent(it, null, false)

Which works fine, problem is that at start-up I get an Exception

SEVERE - #c.i.d.LoadingState - Should be called at least in the state COMPONENTS_LOADED, the current state is: CONFIGURATION_STORE_INITIALIZED

But I don't know how to check if app is already loaded and I can run this code… LoadingState by itself is marked as ApiInternal so I cannot use that.

I tried something like

if (!ApplicationManager.getApplication().isActive) return@withContext

but that doesn't work is app is likely active before IDEA is fully loaded?


Where exactly do you execute this code? Please don't do it in CTOR.


Not sure what CTOR is, it's initially called from ToolWindowFactory

class TscnScenePreviewWindowFactory(private val coroutineScope: CoroutineScope) : ToolWindowFactory {

    override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) {
        TscnScenePreviewWindow(project, toolWindow, coroutineScope)



TscnScenePreviewWindow Handle rendering of ToolWindow content depending on currently selected file.

Getting current virtual file I've copy-paste more or less from StructureViewWindow (but some parts are marked as InternalApi so can't do it 1:1), but initial call is inside contructor:

Disposer.register(toolWindow.contentManager, this)
coroutineScope.launch {
    rebuildRequests.debounce {
        when (it) {
            RebuildDelay.NOW -> 0L
            RebuildDelay.QUEUE -> 100
            .collectLatest {


where rebuildImpl is the one calling code in initial post


Please sign in to leave a comment.