Skip to content

Commit ab3ec24

Browse files
committed
Fix isSourceFile() check
1 parent 33340c3 commit ab3ec24

File tree

1 file changed

+4
-17
lines changed
  • src/main/kotlin/io/runescript/plugin/lang/psi

1 file changed

+4
-17
lines changed

src/main/kotlin/io/runescript/plugin/lang/psi/psi.kt

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package io.runescript.plugin.lang.psi
22

3-
import com.intellij.openapi.project.Project
4-
import com.intellij.openapi.project.guessProjectDir
5-
import com.intellij.openapi.roots.ProjectFileIndex
3+
import com.intellij.openapi.module.ModuleUtil
64
import com.intellij.psi.PsiElement
75
import com.intellij.psi.util.parentOfType
6+
import io.runescript.plugin.ide.neptune.findNeptuneProjectRoot
87

98
val RsStatement.controlFlowHolder: RsControlFlowHolder?
109
get() = parentOfType<RsControlFlowHolder>()
@@ -72,19 +71,7 @@ fun RsLocalVariableExpression.isForArrayAccess(): Boolean {
7271
return parent is RsArrayAccessExpression && this === parent.expressionList[0]
7372
}
7473

75-
fun Project.isRsProject(): Boolean {
76-
val file = guessProjectDir()?.findChild("neptune.toml")
77-
return file != null
78-
}
79-
8074
fun PsiElement.isSourceFile(): Boolean {
81-
if (!project.isRsProject()) {
82-
return false
83-
}
84-
val containingFile = containingFile?.virtualFile ?: return false
85-
val fileIndex = ProjectFileIndex.getInstance(project)
86-
if (fileIndex.isExcluded(containingFile)) {
87-
return false
88-
}
89-
return fileIndex.isInContent(containingFile)
75+
val module = ModuleUtil.findModuleForFile(containingFile) ?: return false
76+
return module.findNeptuneProjectRoot() != null
9077
}

0 commit comments

Comments
 (0)