Skip to content

Commit

Permalink
chore: revert code for #133 #142
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Nov 16, 2024
1 parent 185e4a8 commit 100394e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,13 @@ 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<Any>): String {
val defaultComment: String = getDocFromOutput(context)
val currentFile = context.currentFile ?: return defaultComment

val comment = PsiElementDataBuilder.provide(currentFile.language)
?.parseComment(project, defaultComment) ?: return defaultComment

val shireCode = extractShireCodeFromComment(comment)
if (shireCode.isNotEmpty()) {
context.pipeData["shireCode"] = shireCode
}

return comment
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,4 @@ class ShireCommenter : Commenter, SelfManagingCommenter<CommentHolder> {
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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 100394e

Please sign in to comment.