Skip to content

Commit

Permalink
feat: format output code type
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Dec 6, 2023
1 parent f07c22e commit 5a5840f
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 28 deletions.
82 changes: 82 additions & 0 deletions unit-picker/src/main/kotlin/cc/unitmesh/pick/output/Instruction.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package cc.unitmesh.pick.output

enum class InstructionType {
INLINE_CODE_COMPLETION,
IN_BLOCK_CODE_COMPLETION,
AFTER_BLOCK_CODE_COMPLETION,
RELATED_CODE_COMPLETION,
// CODE_DIFF,
// REFACTOR,
}

sealed class Instruction(
val instructionType: InstructionType,
val instruction: String,
val output: String,
) {
abstract fun input(): String
}

class InlineCodeCompletion(
instruction: String,
output: String,
val language: String,
val beforeCursorCode: String,
) : Instruction(InstructionType.INLINE_CODE_COMPLETION, instruction, output) {
override fun input(): String {
return """```$language
|$beforeCursorCode
|```""".trimMargin()
}
}

class InBlockCodeCompletion(
instruction: String,
output: String,
val language: String,
val beforeCursorCode: String,
val afterCursorCode: String,
) : Instruction(InstructionType.IN_BLOCK_CODE_COMPLETION, instruction, output) {
override fun input(): String {
return """```$language
|$beforeCursorCode
|$afterCursorCode
|```""".trimMargin()
}
}

class AfterBlockCodeCompletion(
instruction: String,
output: String,
val language: String,
val beforeCursorCode: String,
val afterCursorCode: String,
) : Instruction(InstructionType.AFTER_BLOCK_CODE_COMPLETION, instruction, output) {
override fun input(): String {
return """```$language
|$beforeCursorCode
|$afterCursorCode
|```""".trimMargin()
}
}

class RelatedCodeCompletion(
instruction: String,
output: String,
val language: String,
val beforeCursorCode: String,
val relatedCode: String,
) : Instruction(InstructionType.RELATED_CODE_COMPLETION, instruction, output) {
override fun input(): String {
return """
| Compare this snippet:
|```$language
|$relatedCode
|```
|Code:
|```$language
|$beforeCursorCode
|```""".trimMargin()
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package cc.unitmesh.pick.worker

import cc.unitmesh.pick.picker.PickJob
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.archguard.rule.common.Language

class WorkerManager {
private val workers: Map<Language, LangWorker> = mapOf(
// todo: add more language support
Language.JAVA to JavaLangWorker(),
)

fun addJob(job: PickJob) {
val language = job.language.toSupportLanguage()
// print job serial
val worker = workers[language]
worker?.addJob(job)
}
Expand Down

0 comments on commit 5a5840f

Please sign in to comment.