Skip to content

Commit 32f263e

Browse files
committed
feat(devti-lang): improve directory creation logic for multiple levels #143
Additionally, spike on TypeScript rename behavior in RenameLookupManagerListener.
1 parent df38c29 commit 32f263e

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,17 @@ class WriteInsCommand(val myProject: Project, val argument: String, val content:
3434
val parentPath = filepath.substringBeforeLast(File.separator)
3535
var parentDir = projectDir.findChild(parentPath)
3636
if (parentDir == null) {
37-
parentDir = projectDir.createChildDirectory(this, parentPath)
37+
// parentDir maybe multiple level, so we need to create all parent directory
38+
val parentDirs = parentPath.split(File.separator)
39+
parentDir = projectDir
40+
for (dir in parentDirs) {
41+
if (dir.isEmpty()) continue
42+
parentDir = parentDir?.createChildDirectory(this, dir)
43+
}
44+
45+
if (parentDir == null) {
46+
return@runWriteAction "$DEVINS_ERROR: Create Directory failed: $parentPath"
47+
}
3848
}
3949

4050
createNewContent(parentDir, filepath, content)

src/main/kotlin/cc/unitmesh/devti/practise/RenameLookupManagerListener.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import com.intellij.psi.util.PsiEditorUtil
2121
import kotlinx.coroutines.*
2222
import kotlinx.coroutines.flow.*
2323

24+
// TODO: spike why TypeScript not trigger this listener when rename a class, function, but Java does
2425
class RenameLookupManagerListener(val project: Project) : LookupManagerListener {
2526
private val llm = LlmFactory.instance.create(project)
2627
private val logger = logger<RenameLookupManagerListener>()

0 commit comments

Comments
 (0)