From d670210ad0e7618726e343288c41a74e052080ba Mon Sep 17 00:00:00 2001 From: andu_falah Date: Mon, 5 Sep 2022 15:23:00 +0800 Subject: [PATCH] Make LuaFileAdditionalResolver return file in project folder first. --- .../intellij/lua/ext/LuaFileAdditionalResolver.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/tang/intellij/lua/ext/LuaFileAdditionalResolver.kt b/src/main/java/com/tang/intellij/lua/ext/LuaFileAdditionalResolver.kt index 05f058d40..3b2b7aac7 100644 --- a/src/main/java/com/tang/intellij/lua/ext/LuaFileAdditionalResolver.kt +++ b/src/main/java/com/tang/intellij/lua/ext/LuaFileAdditionalResolver.kt @@ -25,15 +25,23 @@ import com.tang.intellij.lua.project.LuaSettings class LuaFileAdditionalResolver : ILuaFileResolver { override fun find(project: Project, shortUrl: String, extNames: Array): VirtualFile? { val sourcesRoot = LuaSettings.instance.additionalSourcesRoot + var firstMatch: VirtualFile? = null for (sr in sourcesRoot) { for (ext in extNames) { val path = "$sr/$shortUrl$ext" val file = VirtualFileManager.getInstance().findFileByUrl(VfsUtil.pathToUrl(path)) if (file != null && !file.isDirectory) { - return file + firstMatch = firstMatch ?: file + val filePath = file.canonicalPath + val projectBasePath = project.basePath + // Is the file in the project folder? + if(filePath != null && projectBasePath != null && filePath.startsWith(projectBasePath)) + return file } } } - return null + // If no file is found or found files do not in project folder, return the first match (maybe bull) + // the same as previous behaviour + return firstMatch } } \ No newline at end of file