diff --git a/unit-picker/src/main/kotlin/cc/unitmesh/pick/picker/CodePicker.kt b/unit-picker/src/main/kotlin/cc/unitmesh/pick/picker/CodePicker.kt index 9694685a..cb8a0199 100644 --- a/unit-picker/src/main/kotlin/cc/unitmesh/pick/picker/CodePicker.kt +++ b/unit-picker/src/main/kotlin/cc/unitmesh/pick/picker/CodePicker.kt @@ -1,6 +1,8 @@ package cc.unitmesh.pick.picker +import cc.unitmesh.pick.prompt.Instruction import cc.unitmesh.pick.prompt.InstructionBuilder +import cc.unitmesh.pick.worker.WorkerContext import cc.unitmesh.pick.worker.WorkerManager import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.channels.Channel @@ -25,9 +27,9 @@ class CodePicker(private val config: PickerConfig) { logger.info("start picker") val languageWorker = LanguageWorker() - val workerManager = WorkerManager() + val workerManager = WorkerManager(WorkerContext(config.builderTypes)) val walkdirChannel = Channel() - val summary = mutableListOf() + val summary = mutableListOf() launch { launch { @@ -43,11 +45,11 @@ class CodePicker(private val config: PickerConfig) { summary.addAll(workerManager.runAll()) } + + // todo: add summary to jsonl }.join() logger.info("stop picker") - - // 3. generate tree to jsonl } } diff --git a/unit-picker/src/main/kotlin/cc/unitmesh/pick/picker/PickerConfig.kt b/unit-picker/src/main/kotlin/cc/unitmesh/pick/picker/PickerConfig.kt index 61c5e1b5..5d713e33 100644 --- a/unit-picker/src/main/kotlin/cc/unitmesh/pick/picker/PickerConfig.kt +++ b/unit-picker/src/main/kotlin/cc/unitmesh/pick/picker/PickerConfig.kt @@ -1,8 +1,13 @@ package cc.unitmesh.pick.picker +import cc.unitmesh.pick.prompt.InstructionType + data class PickerConfig( val url: String, val branch: String = "master", - val baseDir: String = "." + val baseDir: String = ".", + val builderTypes: List = listOf( + InstructionType.RELATED_CODE_COMPLETION + ), ) { } \ No newline at end of file diff --git a/unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/LangWorker.kt b/unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/LangWorker.kt index 0607b6f2..e2866b4f 100644 --- a/unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/LangWorker.kt +++ b/unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/LangWorker.kt @@ -2,8 +2,9 @@ package cc.unitmesh.pick.worker import cc.unitmesh.pick.prompt.InstructionBuilder import cc.unitmesh.pick.picker.InstructionJob +import cc.unitmesh.pick.prompt.Instruction abstract class LangWorker { abstract fun addJob(job: InstructionJob) - abstract suspend fun start() : List + abstract suspend fun start() : Collection } \ No newline at end of file diff --git a/unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/WorkerContext.kt b/unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/WorkerContext.kt new file mode 100644 index 00000000..e051bcfe --- /dev/null +++ b/unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/WorkerContext.kt @@ -0,0 +1,7 @@ +package cc.unitmesh.pick.worker + +import cc.unitmesh.pick.prompt.InstructionType + +data class WorkerContext( + val builderType: List, +) diff --git a/unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/WorkerManager.kt b/unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/WorkerManager.kt index 5534b9e2..a1ab1cd3 100644 --- a/unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/WorkerManager.kt +++ b/unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/WorkerManager.kt @@ -2,11 +2,13 @@ package cc.unitmesh.pick.worker import cc.unitmesh.pick.prompt.InstructionBuilder import cc.unitmesh.pick.picker.InstructionJob +import cc.unitmesh.pick.prompt.Instruction +import cc.unitmesh.pick.worker.worker.JavaLangWorker import org.archguard.rule.common.Language -class WorkerManager { +class WorkerManager(workerContext: WorkerContext) { private val workers: Map = mapOf( - Language.JAVA to JavaLangWorker(), + Language.JAVA to JavaLangWorker(workerContext), ) fun addJob(job: InstructionJob) { @@ -15,7 +17,7 @@ class WorkerManager { worker?.addJob(job) } - suspend fun runAll() : List { + suspend fun runAll() : List { return workers.map { (_, worker) -> worker.start() }.flatten() diff --git a/unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/JavaLangWorker.kt b/unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/worker/JavaLangWorker.kt similarity index 87% rename from unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/JavaLangWorker.kt rename to unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/worker/JavaLangWorker.kt index c658bac7..5aa78ebc 100644 --- a/unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/JavaLangWorker.kt +++ b/unit-picker/src/main/kotlin/cc/unitmesh/pick/worker/worker/JavaLangWorker.kt @@ -1,7 +1,10 @@ -package cc.unitmesh.pick.worker +package cc.unitmesh.pick.worker.worker import cc.unitmesh.pick.prompt.InstructionBuilder import cc.unitmesh.pick.picker.InstructionJob +import cc.unitmesh.pick.prompt.Instruction +import cc.unitmesh.pick.worker.LangWorker +import cc.unitmesh.pick.worker.WorkerContext import chapi.ast.javaast.JavaAnalyser import kotlinx.coroutines.coroutineScope import org.archguard.scanner.analyser.count.FileJob @@ -20,7 +23,7 @@ import org.archguard.scanner.analyser.count.FileJob * - by Horizontal (with Import File): * - by Vertical (with History Change): */ -class JavaLangWorker : LangWorker() { +class JavaLangWorker(val workerContext: WorkerContext) : LangWorker() { private val jobs: MutableList = mutableListOf() private val packageTree: MutableMap = mutableMapOf() @@ -44,7 +47,7 @@ class JavaLangWorker : LangWorker() { } } - override suspend fun start(): List = coroutineScope { + override suspend fun start(): Collection = coroutineScope { jobs.map { }