@@ -13,14 +13,15 @@ import com.intellij.openapi.vfs.VirtualFile
1313import com.intellij.psi.PsiDocumentManager
1414import com.intellij.psi.PsiManager
1515import com.intellij.util.Alarm
16- import com. intellij.util.AlarmFactory
16+ import org.digma. intellij.plugin.common.allowSlowOperation
1717import org.digma.intellij.plugin.common.isProjectValid
1818import org.digma.intellij.plugin.common.isValidVirtualFile
1919import org.digma.intellij.plugin.common.runInReadAccessWithResult
2020import org.digma.intellij.plugin.errorreporting.ErrorReporter
2121import org.digma.intellij.plugin.log.Log
2222import org.digma.intellij.plugin.psi.LanguageService
2323import 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
0 commit comments