From 7bb3d776f82f54c4d376859b0a68386e86f12b12 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Thu, 2 May 2024 11:34:41 +0800 Subject: [PATCH] feat(compiler): add support for DevInUsed in WriteInsCommand and fixed #172 This commit adds support for `DevInUsed` in `WriteInsCommand`, improving the handling of line info arguments. --- .../devti/language/compiler/DevInsCompiler.kt | 2 +- .../devti/language/compiler/exec/WriteInsCommand.kt | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/DevInsCompiler.kt b/exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/DevInsCompiler.kt index 57c654010b..4babe45bbf 100644 --- a/exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/DevInsCompiler.kt +++ b/exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/DevInsCompiler.kt @@ -181,7 +181,7 @@ class DevInsCompiler( if (devInCode == null) { PrintInsCommand("/" + commandNode.commandName + ":" + prop) } else { - WriteInsCommand(myProject, prop, devInCode.text) + WriteInsCommand(myProject, prop, devInCode.text, used) } } diff --git a/exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/exec/WriteInsCommand.kt b/exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/exec/WriteInsCommand.kt index 882e899c09..50f8233310 100644 --- a/exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/exec/WriteInsCommand.kt +++ b/exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/exec/WriteInsCommand.kt @@ -2,6 +2,7 @@ package cc.unitmesh.devti.language.compiler.exec import cc.unitmesh.devti.language.compiler.error.DEVINS_ERROR import cc.unitmesh.devti.language.compiler.model.LineInfo +import cc.unitmesh.devti.language.psi.DevInUsed import cc.unitmesh.devti.language.utils.lookupFile import cc.unitmesh.devti.util.parser.Code import com.intellij.openapi.application.runReadAction @@ -16,13 +17,14 @@ import com.intellij.psi.PsiDocumentManager import com.intellij.psi.PsiFile import com.intellij.psi.PsiManager -class WriteInsCommand(val myProject: Project, val argument: String, val content: String) : InsCommand { +class WriteInsCommand(val myProject: Project, val argument: String, val content: String, val used: DevInUsed) : + InsCommand { private val pathSeparator = "/" override suspend fun execute(): String? { val content = Code.parse(content).text - val range: LineInfo? = LineInfo.fromString(argument) + val range: LineInfo? = LineInfo.fromString(used.text) val filepath = argument.split("#")[0] val projectDir = myProject.guessProjectDir() ?: return "$DEVINS_ERROR: Project directory not found" @@ -39,12 +41,11 @@ class WriteInsCommand(val myProject: Project, val argument: String, val content: parentDir = projectDir for (dir in parentDirs) { if (dir.isEmpty()) continue - + //check child folder if exist? if not, create it - if(parentDir?.findChild(dir) == null) { + if (parentDir?.findChild(dir) == null) { parentDir = runWriteAction { parentDir?.createChildDirectory(this, dir) } - } - else { + } else { parentDir = parentDir?.findChild(dir) } }