Skip to content

Commit d670210

Browse files
AnduFalaHtangzx
authored andcommitted
Make LuaFileAdditionalResolver return file in project folder first.
1 parent 4ffb77d commit d670210

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/main/java/com/tang/intellij/lua/ext/LuaFileAdditionalResolver.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,23 @@ import com.tang.intellij.lua.project.LuaSettings
2525
class LuaFileAdditionalResolver : ILuaFileResolver {
2626
override fun find(project: Project, shortUrl: String, extNames: Array<String>): VirtualFile? {
2727
val sourcesRoot = LuaSettings.instance.additionalSourcesRoot
28+
var firstMatch: VirtualFile? = null
2829
for (sr in sourcesRoot) {
2930
for (ext in extNames) {
3031
val path = "$sr/$shortUrl$ext"
3132
val file = VirtualFileManager.getInstance().findFileByUrl(VfsUtil.pathToUrl(path))
3233
if (file != null && !file.isDirectory) {
33-
return file
34+
firstMatch = firstMatch ?: file
35+
val filePath = file.canonicalPath
36+
val projectBasePath = project.basePath
37+
// Is the file in the project folder?
38+
if(filePath != null && projectBasePath != null && filePath.startsWith(projectBasePath))
39+
return file
3440
}
3541
}
3642
}
37-
return null
43+
// If no file is found or found files do not in project folder, return the first match (maybe bull)
44+
// the same as previous behaviour
45+
return firstMatch
3846
}
3947
}

0 commit comments

Comments
 (0)