From 100394eccffb1988f900f12d5fefdb0bf7bcde5c Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Sat, 16 Nov 2024 16:52:08 +0800 Subject: [PATCH] chore: revert code for #133 #142 --- .../middleware/builtin/ParseCommentProcessor.kt | 15 --------------- .../middleware/builtin/RunCodeProcessor.kt | 17 +---------------- .../phodal/shirelang/comment/ShireCommenter.kt | 10 ---------- .../run/ShireRunLineMarkersProvider.kt | 10 ++++++++++ .../resources/messages/ShireBundle.properties | 1 + 5 files changed, 12 insertions(+), 41 deletions(-) diff --git a/core/src/main/kotlin/com/phodal/shirecore/middleware/builtin/ParseCommentProcessor.kt b/core/src/main/kotlin/com/phodal/shirecore/middleware/builtin/ParseCommentProcessor.kt index 0e394cd88..e5a32d4a7 100644 --- a/core/src/main/kotlin/com/phodal/shirecore/middleware/builtin/ParseCommentProcessor.kt +++ b/core/src/main/kotlin/com/phodal/shirecore/middleware/builtin/ParseCommentProcessor.kt @@ -42,16 +42,6 @@ class ParseCommentProcessor : PostProcessor { private fun getDocFromOutput(context: PostProcessorContext) = preHandleDoc(context.pipeData["output"] as String? ?: context.genText ?: "") - private fun extractShireCodeFromComment(comment: String): String { - val codeBlockStart = comment.indexOf("```shire") - if (codeBlockStart == -1) return "" - - val codeBlockEnd = comment.indexOf("```", codeBlockStart + 7) - if (codeBlockEnd == -1) return "" - - return comment.substring(codeBlockStart + 7, codeBlockEnd).trim() - } - override fun execute(project: Project, context: PostProcessorContext, console: ConsoleView?, args: List): String { val defaultComment: String = getDocFromOutput(context) val currentFile = context.currentFile ?: return defaultComment @@ -59,11 +49,6 @@ class ParseCommentProcessor : PostProcessor { val comment = PsiElementDataBuilder.provide(currentFile.language) ?.parseComment(project, defaultComment) ?: return defaultComment - val shireCode = extractShireCodeFromComment(comment) - if (shireCode.isNotEmpty()) { - context.pipeData["shireCode"] = shireCode - } - return comment } } diff --git a/core/src/main/kotlin/com/phodal/shirecore/middleware/builtin/RunCodeProcessor.kt b/core/src/main/kotlin/com/phodal/shirecore/middleware/builtin/RunCodeProcessor.kt index 0a63dc77a..f5b7483ac 100644 --- a/core/src/main/kotlin/com/phodal/shirecore/middleware/builtin/RunCodeProcessor.kt +++ b/core/src/main/kotlin/com/phodal/shirecore/middleware/builtin/RunCodeProcessor.kt @@ -67,22 +67,7 @@ class RunCodeProcessor : PostProcessor { } } - val shireCode = context.pipeData["shireCode"] as? String - if (shireCode != null) { - val ext = context.genTargetLanguage?.associatedFileType?.defaultExtension ?: "txt" - ApplicationManager.getApplication().invokeAndWait { - PsiFileFactory.getInstance(project).createFileFromText("temp.$ext", shireCode).let { psiFile -> - if (psiFile.virtualFile == null) { - console?.print("Failed to create file for run\n", ERROR_OUTPUT) - } else { - doExecute(console, project, psiFile.virtualFile, psiFile) - } - } - } - } else { - console?.print("No code to run\n", ERROR_OUTPUT) - } - + console?.print("No code to run\n", ERROR_OUTPUT) return "" } diff --git a/shirelang/src/main/kotlin/com/phodal/shirelang/comment/ShireCommenter.kt b/shirelang/src/main/kotlin/com/phodal/shirelang/comment/ShireCommenter.kt index 4c5f48c84..cb34830f4 100644 --- a/shirelang/src/main/kotlin/com/phodal/shirelang/comment/ShireCommenter.kt +++ b/shirelang/src/main/kotlin/com/phodal/shirelang/comment/ShireCommenter.kt @@ -106,14 +106,4 @@ class ShireCommenter : Commenter, SelfManagingCommenter { document: Document, file: PsiFile ): CommentHolder = CommentHolder(file) - - fun extractShireCodeFromComment(comment: String): String { - val codeBlockStart = comment.indexOf("```shire") - if (codeBlockStart == -1) return "" - - val codeBlockEnd = comment.indexOf("```", codeBlockStart + 7) - if (codeBlockEnd == -1) return "" - - return comment.substring(codeBlockStart + 7, codeBlockEnd).trim() - } } diff --git a/shirelang/src/main/kotlin/com/phodal/shirelang/run/ShireRunLineMarkersProvider.kt b/shirelang/src/main/kotlin/com/phodal/shirelang/run/ShireRunLineMarkersProvider.kt index 97eef5c72..ef58b1189 100644 --- a/shirelang/src/main/kotlin/com/phodal/shirelang/run/ShireRunLineMarkersProvider.kt +++ b/shirelang/src/main/kotlin/com/phodal/shirelang/run/ShireRunLineMarkersProvider.kt @@ -39,4 +39,14 @@ class ShireRunLineMarkersProvider : RunLineMarkerContributor(), DumbAware { *actions ) } + + fun extractShireCodeFromComment(comment: String): String { + val codeBlockStart = comment.indexOf("```shire") + if (codeBlockStart == -1) return "" + + val codeBlockEnd = comment.indexOf("```", codeBlockStart + 7) + if (codeBlockEnd == -1) return "" + + return comment.substring(codeBlockStart + 7, codeBlockEnd).trim() + } } diff --git a/shirelang/src/main/resources/messages/ShireBundle.properties b/shirelang/src/main/resources/messages/ShireBundle.properties index 6e38dd5f3..b710ec3ce 100644 --- a/shirelang/src/main/resources/messages/ShireBundle.properties +++ b/shirelang/src/main/resources/messages/ShireBundle.properties @@ -22,3 +22,4 @@ shire.prompt.fix.run-result=You are a top software developer in the world, which intentions.request.background.process.title=Generate File shire.toolchain.function.not.found=No match function: {0}, If you using toolchain function, visit: https://shire.phodal.com/shire/shire-toolchain-function for more. TODO for User custom. intentions.assistant.name=Shire Intention Action +shire.line.marker.run.comment=Run Shire