Skip to content

Commit 3fe7324

Browse files
committed
fix(compiler): adjust text length validation and file search logic
- Change text length validation to include length 3 in LocalSearchInsCommand. - Add case sensitivity option to Project.findFile method. - Update FileInsCommand to use case-insensitive file search.
1 parent 8385219 commit 3fe7324

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/exec/FileInsCommand.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class FileInsCommand(private val myProject: Project, private val prop: String) :
3232

3333
if (virtualFile == null) {
3434
val filename = filepath.split("/").last()
35-
virtualFile = myProject.findFile(filename)
35+
virtualFile = myProject.findFile(filename, false)
3636
}
3737

3838
val contentsToByteArray = virtualFile?.contentsToByteArray()

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/exec/LocalSearchInsCommand.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class LocalSearchInsCommand(val myProject: Project, private val scope: String, v
3131
override suspend fun execute(): String {
3232
val text = (text ?: scope).trim()
3333
/// check text length if less then 3 return alert slowly
34-
if (text.length < 3) {
34+
if (text.length <= 3) {
3535
throw IllegalArgumentException("Text length should be more than 4")
3636
}
3737

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/utils/ProjectFileUtil.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ fun Project.lookupFile(path: String): VirtualFile? {
1515
return VirtualFileManager.getInstance().findFileByUrl("file://${realpath?.toAbsolutePath()}")
1616
}
1717

18-
fun Project.findFile(filename: String): VirtualFile? {
18+
fun Project.findFile(filename: String, caseSensitively: Boolean = true): VirtualFile? {
1919
ApplicationManager.getApplication().assertReadAccessAllowed()
20-
return FilenameIndex.getVirtualFilesByName(filename, ProjectScope.getProjectScope(this)).firstOrNull()
20+
return FilenameIndex.getVirtualFilesByName(filename, caseSensitively, ProjectScope.getProjectScope(this)).firstOrNull()
2121
}
2222

23+
// getVirtualFilesByNamesIgnoringCase
24+
2325
fun VirtualFile.canBeAdded(): Boolean {
2426
if (!this.isValid || this.isDirectory) return false
2527
if (this.fileType.isBinary || FileUtilRt.isTooLarge(this.length)) return false

0 commit comments

Comments
 (0)