@@ -15,9 +15,10 @@ import com.intellij.openapi.vfs.VirtualFile
15
15
import com.intellij.psi.PsiDocumentManager
16
16
import com.intellij.psi.PsiFile
17
17
import com.intellij.psi.PsiManager
18
- import java.io.File
19
18
20
19
class WriteInsCommand (val myProject : Project , val argument : String , val content : String ) : InsCommand {
20
+ private val pathSeparator = " /"
21
+
21
22
override suspend fun execute (): String? {
22
23
val content = Code .parse(content).text
23
24
@@ -29,13 +30,13 @@ class WriteInsCommand(val myProject: Project, val argument: String, val content:
29
30
if (virtualFile == null ) {
30
31
return runWriteAction {
31
32
// filepath maybe just a file name, so we need to create parent directory
32
- val hasChildPath = filepath.contains(File .separator )
33
+ val hasChildPath = filepath.contains(pathSeparator )
33
34
if (hasChildPath) {
34
- val parentPath = filepath.substringBeforeLast(File .separator )
35
+ val parentPath = filepath.substringBeforeLast(pathSeparator )
35
36
var parentDir = projectDir.findChild(parentPath)
36
37
if (parentDir == null ) {
37
38
// parentDir maybe multiple level, so we need to create all parent directory
38
- val parentDirs = parentPath.split(File .separator )
39
+ val parentDirs = parentPath.split(pathSeparator )
39
40
parentDir = projectDir
40
41
for (dir in parentDirs) {
41
42
if (dir.isEmpty()) continue
@@ -67,7 +68,7 @@ class WriteInsCommand(val myProject: Project, val argument: String, val content:
67
68
}
68
69
69
70
private fun createNewContent (parentDir : VirtualFile , filepath : String , content : String ): Document ? {
70
- val newFile = parentDir.createChildData(this , filepath.substringAfterLast(File .separator ))
71
+ val newFile = parentDir.createChildData(this , filepath.substringAfterLast(pathSeparator ))
71
72
val document = FileDocumentManager .getInstance().getDocument(newFile) ? : return null
72
73
73
74
document.setText(content)
0 commit comments