Skip to content

Commit

Permalink
Fix isConstantFile and isVarFile checks
Browse files Browse the repository at this point in the history
  • Loading branch information
waleedyaseen committed Aug 28, 2024
1 parent 0e3c905 commit 747e298
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,14 @@ package io.runescript.plugin.symbollang.psi

import com.intellij.openapi.vfs.VirtualFile

fun VirtualFile.isConstantFile() = name == "constant.sym"
fun VirtualFile.isVarFile() = name == "varp.sym" || name == "varc.sym"
fun VirtualFile.isSymbolFileOfTypeLiteral(typeLiteral: String): Boolean {
val parent = parent
return if (parent != null && parent.name == typeLiteral) true else nameWithoutExtension == typeLiteral
}

fun VirtualFile.isConstantFile() = isSymbolFileOfTypeLiteral("constant")
fun VirtualFile.isVarFile() = when {
isSymbolFileOfTypeLiteral("varp") -> true
isSymbolFileOfTypeLiteral("varc") -> true
else -> false
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.intellij.psi.stubs.StubIndex
import com.intellij.psi.stubs.StubIndexKey
import io.runescript.plugin.lang.psi.type.RsPrimitiveType
import io.runescript.plugin.symbollang.psi.RsSymSymbol
import io.runescript.plugin.symbollang.psi.isSymbolFileOfTypeLiteral
import io.runescript.plugin.symbollang.psi.stub.types.RsSymFileStubType


Expand All @@ -25,14 +26,7 @@ class RsSymbolIndex : StringStubIndexExtension<RsSymSymbol>() {
val scope = GlobalSearchScope.allScope(project)
val configs = StubIndex.getElements(KEY, name, project, scope, RsSymSymbol::class.java)
return configs.singleOrNull {
// TODO: Only include if the file is within the symbols directory.
val containingFile = it.containingFile
val parent = containingFile.parent
if (parent != null && parent.name == lookupType.literal) {
true
} else {
containingFile.nameWithoutExtension == lookupType.literal
}
it.containingFile.virtualFile.isSymbolFileOfTypeLiteral(lookupType.literal)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import io.runescript.plugin.symbollang.psi.stub.RsSymFileStub

object RsSymFileStubType : IStubFileElementType<RsSymFileStub>(RuneScriptSymbol) {

override fun getStubVersion() = 0
override fun getStubVersion() = 1

override fun serialize(stub: RsSymFileStub, dataStream: StubOutputStream) {

Expand Down

0 comments on commit 747e298

Please sign in to comment.