|
1 | 1 | package org.jetbrains.plugins.scala.compiler.highlighting
|
2 | 2 |
|
3 | 3 | import com.intellij.codeInsight.daemon.impl.HighlightInfoType
|
4 |
| -import com.intellij.openapi.module.ModuleUtilCore |
| 4 | +import com.intellij.openapi.application.ReadAction |
5 | 5 | import com.intellij.openapi.progress.ProcessCanceledException
|
6 | 6 | import com.intellij.openapi.project.Project
|
7 | 7 | import com.intellij.openapi.vfs.VirtualFile
|
| 8 | +import com.intellij.psi.{PsiFile, PsiManager} |
| 9 | +import com.intellij.util.concurrency.annotations.RequiresBackgroundThread |
8 | 10 | import org.jetbrains.jps.incremental.scala.Client.{ClientMsg, PosInfo}
|
9 | 11 | import org.jetbrains.jps.incremental.scala.MessageKind
|
10 | 12 | import org.jetbrains.plugins.scala.compiler.highlighting.BackgroundExecutorService.executeOnBackgroundThreadInNotDisposed
|
11 | 13 | import org.jetbrains.plugins.scala.compiler.highlighting.ExternalHighlighting.RangeInfo
|
12 | 14 | import org.jetbrains.plugins.scala.compiler.{CompilerEvent, CompilerEventListener}
|
13 | 15 | import org.jetbrains.plugins.scala.extensions.PathExt
|
| 16 | +import org.jetbrains.plugins.scala.project.ProjectPsiFileExt |
14 | 17 | import org.jetbrains.plugins.scala.settings.ScalaProjectSettings
|
15 | 18 |
|
16 | 19 | private class UpdateCompilerGeneratedStateListener(project: Project) extends CompilerEventListener {
|
@@ -119,10 +122,22 @@ private class UpdateCompilerGeneratedStateListener(project: Project) extends Com
|
119 | 122 | }
|
120 | 123 |
|
121 | 124 | private def scalacOptionsForFile(virtualFile: VirtualFile): Seq[String] = {
|
122 |
| - val module = ModuleUtilCore.findModuleForFile(virtualFile, project) |
123 |
| - CompilerOptions.scalacOptions(module) |
| 125 | + val psiFileOpt = findPsiFile(virtualFile) |
| 126 | + val moduleOpt = psiFileOpt.flatMap(_.module) |
| 127 | + moduleOpt match { |
| 128 | + case Some(module) => CompilerOptions.scalacOptions(module) |
| 129 | + case None => Seq.empty |
| 130 | + } |
124 | 131 | }
|
125 | 132 |
|
| 133 | + @RequiresBackgroundThread |
| 134 | + private def findPsiFile(virtualFile: VirtualFile): Option[PsiFile] = |
| 135 | + ReadAction |
| 136 | + .nonBlocking[Option[PsiFile]](() => Option(PsiManager.getInstance(project).findFile(virtualFile))) |
| 137 | + .inSmartMode(project) |
| 138 | + .expireWhen(() => project.isDisposed) |
| 139 | + .executeSynchronously() |
| 140 | + |
126 | 141 | private def replaceOrAppendFileState(oldState: CompilerGeneratedState,
|
127 | 142 | file: VirtualFile,
|
128 | 143 | fileState: FileCompilerGeneratedState): CompilerGeneratedState = {
|
|
0 commit comments