Skip to content

Commit 710e945

Browse files
committed
feat(devins-lang): refactor file handling logic to improve performance and add support for line info in commands.
1 parent ef0ee46 commit 710e945

File tree

4 files changed

+11
-14
lines changed

4 files changed

+11
-14
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class FileFuncInsCommand(val myProject: Project, val prop: String) : InsCommand
3030
private fun regexFunction(regex: Regex, project: Project): MutableList<VirtualFile> {
3131
val files: MutableList<VirtualFile> = mutableListOf()
3232
ProjectFileIndex.getInstance(project).iterateContent {
33-
if (canBeAdded(it)) {
33+
if (it.canBeAdded()) {
3434
if (regex.matches(it.path)) {
3535
files.add(it)
3636
}

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/completion/provider/FileReferenceLanguageProvider.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ class FileReferenceLanguageProvider : CompletionProvider<CompletionParameters>()
2727
* Recent open files
2828
*/
2929
EditorHistoryManager.getInstance(project).fileList.forEach {
30-
if (!canBeAdded(it)) return@forEach
30+
if (!it.canBeAdded()) return@forEach
3131
result.addElement(buildElement(it, basePath))
3232
}
3333

3434
/**
3535
* Project Files
3636
*/
3737
ProjectFileIndex.getInstance(project).iterateContent {
38-
if (!canBeAdded(it)) return@iterateContent true
38+
if (!it.canBeAdded()) return@iterateContent true
3939
result.addElement(buildElement(it, basePath))
4040
true
4141
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,19 @@ package cc.unitmesh.devti.language.utils
22

33
import com.intellij.openapi.project.Project
44
import com.intellij.openapi.project.guessProjectDir
5+
import com.intellij.openapi.util.io.FileUtilRt
56
import com.intellij.openapi.vfs.VirtualFile
67
import com.intellij.openapi.vfs.VirtualFileManager
78

89
fun Project.lookupFile(path: String): VirtualFile? {
910
val projectPath = this.guessProjectDir()?.toNioPath()
1011
val realpath = projectPath?.resolve(path)
1112
return VirtualFileManager.getInstance().findFileByUrl("file://${realpath?.toAbsolutePath()}")
13+
}
14+
15+
fun VirtualFile.canBeAdded(): Boolean {
16+
if (!this.isValid || this.isDirectory) return false
17+
if (this.fileType.isBinary || FileUtilRt.isTooLarge(this.length)) return false
18+
19+
return true
1220
}

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

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)