Skip to content

Commit

Permalink
feat: add worker context to text builder
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Dec 7, 2023
1 parent 9a542e9 commit ac6eef7
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<FileJob>()
val summary = mutableListOf<InstructionBuilder>()
val summary = mutableListOf<Instruction>()

launch {
launch {
Expand All @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<InstructionType> = listOf(
InstructionType.RELATED_CODE_COMPLETION
),
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<InstructionBuilder>
abstract suspend fun start() : Collection<Instruction>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package cc.unitmesh.pick.worker

import cc.unitmesh.pick.prompt.InstructionType

data class WorkerContext(
val builderType: List<InstructionType>,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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<Language, LangWorker> = mapOf(
Language.JAVA to JavaLangWorker(),
Language.JAVA to JavaLangWorker(workerContext),
)

fun addJob(job: InstructionJob) {
Expand All @@ -15,7 +17,7 @@ class WorkerManager {
worker?.addJob(job)
}

suspend fun runAll() : List<InstructionBuilder> {
suspend fun runAll() : List<Instruction> {
return workers.map { (_, worker) ->
worker.start()
}.flatten()
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<InstructionJob> = mutableListOf()
private val packageTree: MutableMap<String, InstructionJob> = mutableMapOf()

Expand All @@ -44,7 +47,7 @@ class JavaLangWorker : LangWorker() {
}
}

override suspend fun start(): List<InstructionBuilder> = coroutineScope {
override suspend fun start(): Collection<Instruction> = coroutineScope {
jobs.map {

}
Expand Down

0 comments on commit ac6eef7

Please sign in to comment.