[terminal] IJPL-190135 Improve logging of TerminalVfsSynchronizer

(cherry picked from commit 338af98cc64bf53e3d9bbf18281e79687bcae37d)

IJ-CR-168852

GitOrigin-RevId: 8f8e225ae4441be7b8b9de8b6ced921beec7b3f4
This commit is contained in:
Konstantin Hudyakov
2025-07-10 18:10:20 +03:00
committed by intellij-monorepo-bot
parent 035f46a976
commit 11cfdd98de

View File

@@ -3,6 +3,8 @@ package com.intellij.terminal.frontend
import com.intellij.ide.GeneralSettings
import com.intellij.ide.SaveAndSyncHandler
import com.intellij.openapi.application.WriteIntentReadAction
import com.intellij.openapi.diagnostic.debug
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.openapi.observable.util.addFocusListener
import com.intellij.openapi.util.Key
@@ -34,7 +36,10 @@ internal class TerminalVfsSynchronizer(
private val heuristicBasedRefresher = TerminalHeuristicsBasedCommandFinishTracker(
outputModel,
heuristicBasedRefresherScope,
onCommandFinish = { SaveAndSyncHandler.getInstance().scheduleRefresh() }
onCommandFinish = {
SaveAndSyncHandler.getInstance().scheduleRefresh()
LOG.debug { "Command finished, schedule VFS refresh." }
}
)
init {
@@ -43,6 +48,7 @@ internal class TerminalVfsSynchronizer(
sessionController.addShellIntegrationListener(disposable, object : TerminalShellIntegrationEventsListener {
override fun commandFinished(command: String, exitCode: Int, currentDirectory: String) {
SaveAndSyncHandler.getInstance().scheduleRefresh()
LOG.debug { "Command finished, schedule VFS refresh." }
}
})
@@ -51,6 +57,7 @@ internal class TerminalVfsSynchronizer(
if (GeneralSettings.getInstance().isSaveOnFrameDeactivation) {
WriteIntentReadAction.run {
FileDocumentManager.getInstance().saveAllDocuments()
LOG.debug { "Focus gained, save all documents to VFS." }
}
}
}
@@ -61,15 +68,19 @@ internal class TerminalVfsSynchronizer(
// when the focus is transferred from the built-in terminal to some other IDE place.
// To get the updates from a long-running command in the built-in terminal.
SaveAndSyncHandler.getInstance().scheduleRefresh()
LOG.debug { "Focus lost, schedule VFS refresh." }
}
}
})
coroutineScope.launch {
var shellIntegrationEnabled = false
sessionModel.terminalState.collect { state ->
if (state.isShellIntegrationEnabled) {
if (state.isShellIntegrationEnabled != shellIntegrationEnabled) {
shellIntegrationEnabled = state.isShellIntegrationEnabled
// If we have events from the shell integration, we no more need heuristic-based refresher.
heuristicBasedRefresherScope.cancel()
LOG.debug { "Shell integration initialized, cancel heuristic-based VFS refresher." }
}
}
}
@@ -84,5 +95,7 @@ internal class TerminalVfsSynchronizer(
companion object {
val KEY: Key<TerminalVfsSynchronizer> = Key.create("TerminalVfsSynchronizer")
private val LOG = logger<TerminalVfsSynchronizer>()
}
}