mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[debugger] Clean up SourceFileChangesCollectorImpl
GitOrigin-RevId: a4afa991f064068cbc0a820cfb7739c7b3576449
This commit is contained in:
committed by
intellij-monorepo-bot
parent
e178f52515
commit
c4dfee3fe2
@@ -29,8 +29,6 @@ internal class JvmHotSwapProvider(private val debuggerSession: DebuggerSession)
|
||||
coroutineScope, listener,
|
||||
FileExtensionFilter(jvmExtensions),
|
||||
InProjectFilter(session.project),
|
||||
// TODO add another scope check
|
||||
//SearchScopeFilter(debuggerSession.searchScope),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+8
-29
@@ -3,9 +3,9 @@ package com.intellij.xdebugger.impl.hotswap
|
||||
|
||||
import com.intellij.history.LocalHistory
|
||||
import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.application.readAction
|
||||
import com.intellij.openapi.components.Service
|
||||
import com.intellij.openapi.components.service
|
||||
import com.intellij.openapi.diagnostic.debug
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.editor.Document
|
||||
import com.intellij.openapi.editor.EditorFactory
|
||||
@@ -16,7 +16,6 @@ import com.intellij.openapi.fileEditor.impl.LoadTextUtil
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.openapi.util.text.Strings
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.search.SearchScope
|
||||
import com.intellij.util.containers.DisposableWrapperList
|
||||
import com.intellij.xdebugger.hotswap.SourceFileChangesCollector
|
||||
import com.intellij.xdebugger.hotswap.SourceFileChangesListener
|
||||
@@ -77,22 +76,16 @@ private class ChangesProcessingService(private val coroutineScope: CoroutineScop
|
||||
|
||||
private suspend fun onDocumentChange(document: Document) = coroutineScope {
|
||||
val virtualFile = FileDocumentManager.getInstance().getFile(document) ?: return@coroutineScope
|
||||
if (logger.isDebugEnabled) {
|
||||
logger.debug("Document changed: ${virtualFile}")
|
||||
}
|
||||
logger.debug { "Document changed: ${virtualFile}" }
|
||||
val filteredCollectors = collectors
|
||||
.map { collector -> collector to async(Dispatchers.Default) { collector.filters.all { it.isApplicable(virtualFile) } } }
|
||||
.filter { it.second.await() }
|
||||
.map { it.first }
|
||||
if (filteredCollectors.isEmpty()) {
|
||||
if (logger.isDebugEnabled) {
|
||||
logger.debug("Document change skipped as filtered: $virtualFile")
|
||||
}
|
||||
logger.debug { "Document change skipped as filtered: $virtualFile" }
|
||||
return@coroutineScope
|
||||
}
|
||||
if (logger.isDebugEnabled) {
|
||||
logger.debug("Document change processing: $virtualFile")
|
||||
}
|
||||
logger.debug { "Document change processing: $virtualFile" }
|
||||
val contentHash = Strings.stringHashCode(document.immutableCharSequence)
|
||||
val groupedByTimeStamp = filteredCollectors.groupBy { it.lastResetTimeStamp }
|
||||
dropUnusedTimestamps(groupedByTimeStamp.keys)
|
||||
@@ -106,7 +99,7 @@ private class ChangesProcessingService(private val coroutineScope: CoroutineScop
|
||||
lastSearchTimeNs = System.nanoTime() - timeStartNs
|
||||
}
|
||||
for (collector in collectors) {
|
||||
collector.processDocumentChange(hasChanges, virtualFile, document)
|
||||
collector.processDocumentChange(hasChanges, virtualFile)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -168,10 +161,7 @@ class SourceFileChangesCollectorImpl(
|
||||
currentChanges = hashSetOf()
|
||||
}
|
||||
|
||||
internal fun processDocumentChange(
|
||||
hasChangesSinceLastReset: Boolean,
|
||||
file: VirtualFile, document: Document,
|
||||
) = coroutineScope.launch(limitedDispatcher) {
|
||||
internal fun processDocumentChange(hasChangesSinceLastReset: Boolean, file: VirtualFile) = coroutineScope.launch(limitedDispatcher) {
|
||||
val currentChanges = currentChanges
|
||||
lock.withLock {
|
||||
if (hasChangesSinceLastReset) {
|
||||
@@ -184,15 +174,11 @@ class SourceFileChangesCollectorImpl(
|
||||
|
||||
val isEmpty = currentChanges.isEmpty()
|
||||
if (isEmpty) {
|
||||
if (logger.isDebugEnabled) {
|
||||
logger.debug("Document change reverted previous changes: $file")
|
||||
}
|
||||
logger.debug { "Document change reverted previous changes: $file" }
|
||||
listener.onChangesCanceled()
|
||||
}
|
||||
else {
|
||||
if (logger.isDebugEnabled) {
|
||||
logger.debug("Document change active: $file")
|
||||
}
|
||||
logger.debug { "Document change active: $file" }
|
||||
listener.onNewChanges()
|
||||
}
|
||||
}
|
||||
@@ -228,10 +214,3 @@ private fun getContentHashBeforeLastReset(file: VirtualFile, lastTimestamp: Long
|
||||
val content = LoadTextUtil.getTextByBinaryPresentation(bytes, file, false, false)
|
||||
return Strings.stringHashCode(content)
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
class SearchScopeFilter(private val searchScope: SearchScope) : SourceFileChangeFilter<VirtualFile> {
|
||||
override suspend fun isApplicable(change: VirtualFile): Boolean {
|
||||
return readAction { searchScope.contains(change) }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user