Skip to content

Commit

Permalink
feat: add build config for project
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Dec 9, 2023
1 parent 71da3c3 commit 2f6d37e
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ data class PickerConfig(
val builderTypes: List<InstructionType> = listOf(
InstructionType.RELATED_CODE_COMPLETION
),
val codeQualityTypes: List<CodeQualityType> = listOf()
val codeQualityTypes: List<CodeQualityType> = listOf(),
val builderConfig: BuilderConfig = BuilderConfig(),
)

/**
* For different generic data in [cc.unitmesh.pick.prompt.InstructionBuilder]
*/
@Serializable
data class BuilderConfig(
val withGenTempData: Boolean = true,
val mergeFinalOutput: Boolean = true,
)
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class SimpleCodePicker(private val config: PickerConfig) : CodePicker {
logger.info("start picker")

val languageWorker = LanguageWorker()
val workerManager = WorkerManager(WorkerContext(config.builderTypes, config.codeQualityTypes))
val workerManager = WorkerManager(WorkerContext(config.builderTypes, config.codeQualityTypes, config.builderConfig))
val walkdirChannel = Channel<FileJob>()
val summary = mutableListOf<Instruction>()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cc.unitmesh.pick.prompt

import cc.unitmesh.pick.picker.BuilderConfig
import cc.unitmesh.pick.picker.InstructionJob
import cc.unitmesh.quality.CodeQualityType
import cc.unitmesh.quality.QualityAnalyser
Expand All @@ -9,6 +10,7 @@ data class InstructionContext(
val job: InstructionJob,
val qualityTypes: List<CodeQualityType>,
val fileTree: HashMap<String, InstructionJob>,
val builderConfig: BuilderConfig,
)

/**
Expand Down Expand Up @@ -70,8 +72,9 @@ interface InstructionBuilder<T> {
qualityTypes: List<CodeQualityType>,
fileTree: HashMap<String, InstructionJob>,
job: InstructionJob,
builderConfig: BuilderConfig,
): Collection<Instruction> {
val instructionContext = InstructionContext(job, qualityTypes, fileTree)
val instructionContext = InstructionContext(job, qualityTypes, fileTree, builderConfig)

return instructionTypes.map { type ->
type.builder(instructionContext).build()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package cc.unitmesh.pick.worker

import cc.unitmesh.pick.picker.BuilderConfig
import cc.unitmesh.pick.prompt.InstructionType
import cc.unitmesh.quality.CodeQualityType

data class WorkerContext(
val builderTypes: List<InstructionType>,
val qualityTypes: List<CodeQualityType>
val qualityTypes: List<CodeQualityType>,
val builderConfig: BuilderConfig,
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.archguard.scanner.analyser.count.FileJob
* - by Horizontal (with Import File):
* - by Vertical (with History Change):
*/
class JavaLangWorker(val workerContext: WorkerContext) : LangWorker() {
class JavaLangWorker(val context: WorkerContext) : LangWorker() {
private val jobs: MutableList<InstructionJob> = mutableListOf()
private val fileTree: HashMap<String, InstructionJob> = hashMapOf()

Expand Down Expand Up @@ -61,7 +61,9 @@ class JavaLangWorker(val workerContext: WorkerContext) : LangWorker() {

override suspend fun start(): Collection<Instruction> = coroutineScope {
return@coroutineScope jobs.map {
InstructionBuilder.build(workerContext.builderTypes, workerContext.qualityTypes, fileTree, it)
InstructionBuilder.build(
context.builderTypes, context.qualityTypes, fileTree, it, context.builderConfig
)
}.flatten()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package cc.unitmesh.pick.prompt.builder

import cc.unitmesh.pick.picker.BuilderConfig
import cc.unitmesh.pick.picker.InstructionJob
import cc.unitmesh.pick.prompt.InstructionContext
import cc.unitmesh.quality.CodeQualityType
import chapi.ast.javaast.JavaAnalyser
import chapi.domain.core.CodeDataStruct
import kotlinx.serialization.json.Json
import org.archguard.scanner.analyser.count.FileJob
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -40,7 +39,8 @@ public class HelloController {
val context = InstructionContext(
job = job,
qualityTypes = listOf(CodeQualityType.JavaController),
fileTree = hashMapOf("" to job)
fileTree = hashMapOf("" to job),
builderConfig = BuilderConfig()
)
val builder = RelatedCodeCompletionBuilder(context)
val result = builder.convert()
Expand Down Expand Up @@ -75,7 +75,8 @@ public class HelloController {
val context = InstructionContext(
job = job,
qualityTypes = listOf(CodeQualityType.JavaController),
fileTree = hashMapOf("" to job)
fileTree = hashMapOf("" to job),
builderConfig = BuilderConfig()
)
val builder = RelatedCodeCompletionBuilder(context)
val result = builder.convert()
Expand Down Expand Up @@ -119,7 +120,8 @@ public class HelloController {
container = repositoryContainer
),
"cc.unitmesh.testng.service.BlogService" to job
)
),
builderConfig = BuilderConfig()
)

val builder = RelatedCodeCompletionBuilder(context)
Expand All @@ -128,7 +130,8 @@ public class HelloController {
assertEquals(result.size, 4)
val first = result.first()

assertEquals(first.relatedCode, """// class BlogPost {
assertEquals(
first.relatedCode, """// class BlogPost {
// : Long
// : String
// : String
Expand All @@ -141,6 +144,7 @@ public class HelloController {
// class BlogRepository {
//
// }
// """)
// """
)
}
}

0 comments on commit 2f6d37e

Please sign in to comment.