Skip to content

Commit 8e2e2c0

Browse files
committed
fix(compiler): adjust directory listing logic for depth control #308
Ensure files are only displayed when depth is within the default max depth, while subdirectories are always shown. This prevents unnecessary file listings in deep directories.
1 parent dc40faa commit 8e2e2c0

File tree

1 file changed

+12
-7
lines changed
  • exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/exec

1 file changed

+12
-7
lines changed

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,27 @@ class DirInsCommand(private val myProject: Project, private val dir: String) : I
6464

6565
private fun listDirectory(project: Project, directory: PsiDirectory, depth: Int) {
6666
if(isExclude(project, directory)) return
67-
if (depth > defaultMaxDepth) return
68-
67+
6968
val files = directory.files
7069
val subdirectories = directory.subdirectories
7170

72-
files.forEachIndexed { index, file ->
73-
val isLast = index == files.lastIndex && subdirectories.isEmpty()
74-
val prefix = if (isLast) "" else ""
75-
val size = StringUtilRt.formatFileSize(file.virtualFile.length)
76-
output.appendLine("${" ".repeat(depth)}$prefix── ${file.name}${size?.let { " ($it)" } ?: ""}")
71+
// 只在深度不超过默认最大深度时显示文件
72+
if (depth <= defaultMaxDepth) {
73+
files.forEachIndexed { index, file ->
74+
val isLast = index == files.lastIndex && subdirectories.isEmpty()
75+
val prefix = if (isLast) "" else ""
76+
val size = StringUtilRt.formatFileSize(file.virtualFile.length)
77+
output.appendLine("${" ".repeat(depth)}$prefix── ${file.name}${size?.let { " ($it)" } ?: ""}")
78+
}
7779
}
7880

81+
// 无论深度如何,始终显示子目录
7982
subdirectories.forEachIndexed { index, subdir ->
8083
if (isExclude(project, subdir)) return@forEachIndexed
8184
val prefix = if (index == subdirectories.lastIndex) "" else ""
8285
output.appendLine("${" ".repeat(depth)}$prefix── ${subdir.name}/")
86+
87+
// 继续递归,文件显示将受深度限制
8388
listDirectory(project, subdir, depth + 1)
8489
}
8590
}

0 commit comments

Comments
 (0)