Skip to content

Commit

Permalink
try fix for debug
Browse files Browse the repository at this point in the history
  • Loading branch information
CppCXY committed Nov 13, 2024
1 parent e16fa03 commit 0d4fec3
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/main/java/com/tang/intellij/lua/psi/LuaFileUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VfsUtil
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.vfs.VirtualFileManager
import com.intellij.psi.search.FilenameIndex
import com.intellij.psi.search.ProjectAndLibrariesScope
import java.io.File

/**
Expand Down Expand Up @@ -59,7 +61,7 @@ object LuaFileUtil {
// Check if the fixedShortUrl already has an extension
val hasExtension = fixedShortUrl.contains(".")
if (hasExtension) {
val virtualFile = VfsUtil.findRelativeFile(fixedShortUrl, project.baseDir)
val virtualFile = findVirtualFile(project, fixedShortUrl);
if (virtualFile != null && virtualFile.exists()) {
return virtualFile
}
Expand All @@ -69,7 +71,7 @@ object LuaFileUtil {
val extensions = LuaFileManager.extensions
for (extension in extensions) {
val fileName = if (extension.isEmpty()) fixedShortUrl else "$fixedShortUrl$extension"
val virtualFile = VfsUtil.findRelativeFile(fileName, project.baseDir)
val virtualFile = findVirtualFile(project, fileName)
if (virtualFile != null && virtualFile.exists()) {
return virtualFile
}
Expand All @@ -78,6 +80,25 @@ object LuaFileUtil {
return null
}

fun findVirtualFile(project: Project, filename: String): VirtualFile? {
val files = FilenameIndex.getVirtualFilesByName(filename, ProjectAndLibrariesScope(project))
var perfect: VirtualFile? = null
var perfectMatch = Int.MAX_VALUE
for (file in files) {
val path = file.canonicalPath
if (path != null && perfectMatch > path.length && path.endsWith(filename)) {
perfect = file
perfectMatch = path.length
}
}

if (perfect != null) {
return perfect
}

return VfsUtil.findRelativeFile(filename, project.baseDir);
}

fun getPluginVirtualFile(path: String): String? {
val directory = pluginVirtualDirectory
if (directory != null) {
Expand Down

0 comments on commit 0d4fec3

Please sign in to comment.