Minor: extract common parts
This commit is contained in:
+19
-13
@@ -110,12 +110,7 @@ class ScriptDependenciesUpdater(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun runScriptDependenciesUpdateIfNeeded(file: VirtualFile) {
|
private fun runScriptDependenciesUpdateIfNeeded(file: VirtualFile) {
|
||||||
if (file.fileType != KotlinFileType.INSTANCE || !file.isValid) return
|
if (!shouldStartUpdate(file)) return
|
||||||
val ktFile = PsiManager.getInstance(project).findFile(file) as? KtFile ?: return
|
|
||||||
|
|
||||||
if (ApplicationManager.getApplication().isUnitTestMode && ApplicationManager.getApplication().isScriptDependenciesUpdaterDisabled == true) return
|
|
||||||
|
|
||||||
if (!ProjectRootsUtil.isInProjectSource(ktFile, includeScriptsOutsideSourceRoots = true)) return
|
|
||||||
|
|
||||||
updateDependencies(file)
|
updateDependencies(file)
|
||||||
makeRootsChangeIfNeeded()
|
makeRootsChangeIfNeeded()
|
||||||
@@ -124,9 +119,6 @@ class ScriptDependenciesUpdater(
|
|||||||
|
|
||||||
EditorFactory.getInstance().eventMulticaster.addDocumentListener(object : DocumentListener {
|
EditorFactory.getInstance().eventMulticaster.addDocumentListener(object : DocumentListener {
|
||||||
override fun documentChanged(event: DocumentEvent) {
|
override fun documentChanged(event: DocumentEvent) {
|
||||||
if (project.isDisposed) return
|
|
||||||
|
|
||||||
if (ApplicationManager.getApplication().isUnitTestMode && ApplicationManager.getApplication().isScriptDependenciesUpdaterDisabled == true) return
|
|
||||||
|
|
||||||
val document = event.document
|
val document = event.document
|
||||||
val file = FileDocumentManager.getInstance().getFile(document)?.takeIf { it.isInLocalFileSystem } ?: return
|
val file = FileDocumentManager.getInstance().getFile(document)?.takeIf { it.isInLocalFileSystem } ?: return
|
||||||
@@ -135,15 +127,13 @@ class ScriptDependenciesUpdater(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!shouldStartUpdate(file)) return
|
||||||
|
|
||||||
// only update dependencies for scripts that were touched recently
|
// only update dependencies for scripts that were touched recently
|
||||||
if (cache[file] == null) {
|
if (cache[file] == null) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val ktFile = PsiManager.getInstance(project).findFile(file) as? KtFile ?: return
|
|
||||||
|
|
||||||
if (!ProjectRootsUtil.isInProjectSource(ktFile, includeScriptsOutsideSourceRoots = true)) return
|
|
||||||
|
|
||||||
scriptsQueue.cancelAllRequests()
|
scriptsQueue.cancelAllRequests()
|
||||||
|
|
||||||
scriptsQueue.addRequest(
|
scriptsQueue.addRequest(
|
||||||
@@ -159,6 +149,22 @@ class ScriptDependenciesUpdater(
|
|||||||
}, project.messageBus.connect())
|
}, project.messageBus.connect())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun shouldStartUpdate(file: VirtualFile): Boolean {
|
||||||
|
if (project.isDisposed || !file.isValid || file.fileType != KotlinFileType.INSTANCE) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
ApplicationManager.getApplication().isUnitTestMode &&
|
||||||
|
ApplicationManager.getApplication().isScriptDependenciesUpdaterDisabled == true
|
||||||
|
) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
val ktFile = PsiManager.getInstance(project).findFile(file) as? KtFile ?: return false
|
||||||
|
return ProjectRootsUtil.isInProjectSource(ktFile, includeScriptsOutsideSourceRoots = true)
|
||||||
|
}
|
||||||
|
|
||||||
private fun areDependenciesCached(file: VirtualFile): Boolean {
|
private fun areDependenciesCached(file: VirtualFile): Boolean {
|
||||||
return cache[file] != null || file.scriptDependencies != null
|
return cache[file] != null || file.scriptDependencies != null
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user