Skip to content

Commit

Permalink
1.2.6 代码优化
Browse files Browse the repository at this point in the history
  • Loading branch information
DragonKnightOfBreeze committed Nov 28, 2023
1 parent 7553f03 commit dd7b0b9
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/kotlin/icu/windea/pls/core/PluginExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.intellij.openapi.project.*
import com.intellij.openapi.util.*
import com.intellij.openapi.vfs.*
import com.intellij.psi.*
import com.intellij.testFramework.*
import icu.windea.pls.*
import icu.windea.pls.config.config.*
import icu.windea.pls.config.configGroup.*
Expand Down Expand Up @@ -134,6 +135,7 @@ tailrec fun selectRootFile(from: Any?): VirtualFile? {
return when {
from == null -> null
from is VirtualFileWindow -> selectRootFile(from.delegate) //for injected PSI
from is LightVirtualFileBase -> selectRootFile(from.originalFile)
from is VirtualFile -> from.fileInfo?.rootInfo?.gameRootFile
else -> selectRootFile(selectFile(from))
}
Expand All @@ -142,6 +144,8 @@ tailrec fun selectRootFile(from: Any?): VirtualFile? {
tailrec fun selectFile(from: Any?): VirtualFile? {
return when {
from == null -> null
from is VirtualFileWindow -> from.castOrNull() //for injected PSI (and not from.delegate)
from is LightVirtualFileBase -> selectFile(from.originalFile)
from is VirtualFile -> from
from is PsiDirectory -> from.virtualFile
from is PsiFile -> from.originalFile.virtualFile
Expand All @@ -156,6 +160,8 @@ tailrec fun selectGameType(from: Any?): ParadoxGameType? {
return when {
from == null -> null
from is ParadoxGameType -> from
from is VirtualFileWindow -> selectGameType(from.delegate) //for injected PSI
from is LightVirtualFileBase -> selectGameType(from.originalFile)
from is VirtualFile -> from.fileInfo?.rootInfo?.gameType
from is PsiDirectory -> selectGameType(selectFile(from))
from is PsiFile -> selectGameType(selectFile(from))
Expand Down

0 comments on commit dd7b0b9

Please sign in to comment.