Skip to content

Commit 19cf9da

Browse files
committed
allow slow operations on EAP
1 parent 87d3ff4 commit 19cf9da

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

ide-common/src/main/kotlin/org/digma/intellij/plugin/codelens/CodeLensServiceDocumentChangeListener.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ import com.intellij.openapi.vfs.VirtualFile
1313
import com.intellij.psi.PsiDocumentManager
1414
import com.intellij.psi.PsiManager
1515
import com.intellij.util.Alarm
16-
import com.intellij.util.AlarmFactory
16+
import org.digma.intellij.plugin.common.allowSlowOperation
1717
import org.digma.intellij.plugin.common.isProjectValid
1818
import org.digma.intellij.plugin.common.isValidVirtualFile
1919
import org.digma.intellij.plugin.common.runInReadAccessWithResult
2020
import org.digma.intellij.plugin.errorreporting.ErrorReporter
2121
import org.digma.intellij.plugin.log.Log
2222
import org.digma.intellij.plugin.psi.LanguageService
2323
import org.digma.intellij.plugin.psi.PsiUtils
24+
import java.util.function.Supplier
2425

2526
//any change in the current editor needs a code lens refresh.
2627
//there is a listener for CodeLensChanged events, but its not enough. the file in the editor may change
@@ -46,7 +47,10 @@ class CodeLensServiceDocumentChangeListener(private val project: Project) : File
4647
}
4748

4849

49-
val languageService = LanguageService.findLanguageServiceByFile(project, file)
50+
val languageService = allowSlowOperation(Supplier {
51+
LanguageService.findLanguageServiceByFile(project, file)
52+
})
53+
5054

5155
//only some languages need code vision support
5256
if (!languageService.isCodeVisionSupported) {
@@ -64,9 +68,9 @@ class CodeLensServiceDocumentChangeListener(private val project: Project) : File
6468

6569
private fun installDocumentListener(file: VirtualFile, languageService: LanguageService) {
6670

67-
val psiFile = PsiManager.getInstance(project).findFile(file)
68-
if (PsiUtils.isValidPsiFile(psiFile) && languageService.isRelevant(file)) {
69-
val document = PsiDocumentManager.getInstance(project).getDocument(psiFile!!)
71+
val psiFile = allowSlowOperation(Supplier { PsiManager.getInstance(project).findFile(file) })
72+
if (psiFile != null && PsiUtils.isValidPsiFile(psiFile) && languageService.isRelevant(file)) {
73+
val document = PsiDocumentManager.getInstance(project).getDocument(psiFile)
7074
if (document != null) {
7175

7276
val parentDisposable = Disposer.newDisposable()
@@ -75,7 +79,7 @@ class CodeLensServiceDocumentChangeListener(private val project: Project) : File
7579

7680
document.addDocumentListener(object : DocumentListener {
7781

78-
private val documentChangeAlarm = AlarmFactory.getInstance().create(
82+
private val documentChangeAlarm = Alarm(
7983
Alarm.ThreadToUse.POOLED_THREAD, parentDisposable
8084
)
8185

@@ -108,7 +112,8 @@ class CodeLensServiceDocumentChangeListener(private val project: Project) : File
108112

109113
} catch (e: Throwable) {
110114
Log.warnWithException(logger, e, "Exception in documentChanged")
111-
ErrorReporter.getInstance().reportError(project, "${this::class.simpleName}.DocumentListener.documentChanged", e)
115+
ErrorReporter.getInstance()
116+
.reportError(project, "CodeLensServiceDocumentChangeListener.DocumentListener.documentChanged", e)
112117
}
113118
}
114119
}, parentDisposable)

jvm-common/src/main/kotlin/org/digma/intellij/plugin/idea/navigation/DocumentsChangeListenerForJvmNavigationDiscovery.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ import com.intellij.openapi.vfs.VirtualFile
1212
import com.intellij.psi.PsiDocumentManager
1313
import com.intellij.psi.PsiManager
1414
import com.intellij.util.Alarm
15-
import com.intellij.util.AlarmFactory
15+
import org.digma.intellij.plugin.common.allowSlowOperation
1616
import org.digma.intellij.plugin.common.isProjectValid
1717
import org.digma.intellij.plugin.common.isValidVirtualFile
1818
import org.digma.intellij.plugin.errorreporting.ErrorReporter
1919
import org.digma.intellij.plugin.idea.psi.JvmLanguageService
2020
import org.digma.intellij.plugin.log.Log
2121
import org.digma.intellij.plugin.psi.LanguageService
2222
import org.digma.intellij.plugin.psi.PsiUtils
23+
import java.util.function.Supplier
2324

2425
/**
2526
* a listener for document change that updates navigation discovery on document changed events.
@@ -44,7 +45,9 @@ class DocumentsChangeListenerForJvmNavigationDiscovery(private val project: Proj
4445
return
4546
}
4647

47-
val languageService = LanguageService.findLanguageServiceByFile(project, file)
48+
val languageService = allowSlowOperation(Supplier {
49+
LanguageService.findLanguageServiceByFile(project, file)
50+
})
4851

4952
//only jvm languages are supported here
5053
if (!JvmLanguageService::class.java.isAssignableFrom(languageService.javaClass)) {
@@ -55,16 +58,16 @@ class DocumentsChangeListenerForJvmNavigationDiscovery(private val project: Proj
5558

5659
} catch (e: Throwable) {
5760
Log.warnWithException(logger, e, "Exception in fileOpened")
58-
ErrorReporter.getInstance().reportError(project, "${this::class.simpleName}.fileOpened", e)
61+
ErrorReporter.getInstance().reportError(project, "DocumentsChangeListenerForJvmNavigationDiscovery.fileOpened", e)
5962
}
6063
}
6164

6265

6366
private fun installDocumentListener(file: VirtualFile, languageService: LanguageService) {
6467

65-
val psiFile = PsiManager.getInstance(project).findFile(file)
66-
if (PsiUtils.isValidPsiFile(psiFile) && languageService.isRelevant(file)) {
67-
val document = PsiDocumentManager.getInstance(project).getDocument(psiFile!!)
68+
val psiFile = allowSlowOperation(Supplier { PsiManager.getInstance(project).findFile(file) })
69+
if (psiFile != null && PsiUtils.isValidPsiFile(psiFile) && languageService.isRelevant(file)) {
70+
val document = PsiDocumentManager.getInstance(project).getDocument(psiFile)
6871
if (document != null) {
6972

7073
val parentDisposable = Disposer.newDisposable()
@@ -73,7 +76,7 @@ class DocumentsChangeListenerForJvmNavigationDiscovery(private val project: Proj
7376

7477
document.addDocumentListener(object : DocumentListener {
7578

76-
private val documentChangeAlarm = AlarmFactory.getInstance().create(
79+
private val documentChangeAlarm = Alarm(
7780
Alarm.ThreadToUse.POOLED_THREAD, parentDisposable
7881
)
7982

0 commit comments

Comments
 (0)