Skip to content

Commit

Permalink
refactor: reorg for builder factory
Browse files Browse the repository at this point in the history
phodal committed Jan 7, 2024
1 parent e41a7d2 commit 1931b16
Showing 12 changed files with 37 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cc.unitmesh.pick.builder

import cc.unitmesh.core.completion.TypedInsBuilder
import cc.unitmesh.core.completion.InstructionBuilderType
import cc.unitmesh.pick.builder.comment.DocumentationTypedInsBuilder
import cc.unitmesh.pick.builder.completion.AfterBlockCodeTypedInsBuilder
import cc.unitmesh.pick.builder.completion.InBlockCodeTypedInsBuilder
import cc.unitmesh.pick.builder.completion.InlineCodeTypedInsBuilder
import cc.unitmesh.pick.builder.unittest.TestCodeTypedInsBuilder
import cc.unitmesh.pick.worker.job.JobContext
import kotlinx.serialization.SerializationException

fun instructionBuilders(types: List<InstructionBuilderType>, context: JobContext) : List<TypedInsBuilder> {
return types.map { instructionBuilder(it, context) }
}

fun instructionBuilder(instructionBuilderType: InstructionBuilderType, context: JobContext): TypedInsBuilder {
return mapOf(
InstructionBuilderType.INLINE_COMPLETION to InlineCodeTypedInsBuilder(context),
InstructionBuilderType.IN_BLOCK_COMPLETION to InBlockCodeTypedInsBuilder(context),
InstructionBuilderType.AFTER_BLOCK_COMPLETION to AfterBlockCodeTypedInsBuilder(context),
InstructionBuilderType.TEST_CODE_GEN to TestCodeTypedInsBuilder(context),
InstructionBuilderType.DOCUMENTATION to DocumentationTypedInsBuilder(context),
)[instructionBuilderType] ?: throw SerializationException("Unknown message type: $instructionBuilderType")
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package cc.unitmesh.pick.builder
package cc.unitmesh.pick.builder.comment

import cc.unitmesh.core.SupportedLang
import cc.unitmesh.core.SupportedLang.*
import cc.unitmesh.core.comment.DocInstruction
import cc.unitmesh.core.completion.TypedIns
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cc.unitmesh.pick.builder.bizcode
package cc.unitmesh.pick.builder.completion

import cc.unitmesh.core.completion.CodeCompletionIns
import cc.unitmesh.core.completion.TypedInsBuilder
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cc.unitmesh.pick.builder.bizcode
package cc.unitmesh.pick.builder.completion

import cc.unitmesh.core.completion.CodeCompletionIns
import cc.unitmesh.core.completion.TypedInsBuilder
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cc.unitmesh.pick.builder.bizcode
package cc.unitmesh.pick.builder.completion

import cc.unitmesh.core.completion.CodeCompletionIns
import cc.unitmesh.core.completion.TypedInsBuilder
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cc.unitmesh.pick.builder
package cc.unitmesh.pick.builder.unittest

import cc.unitmesh.core.completion.CodeCompletionIns
import cc.unitmesh.core.completion.TypedInsBuilder
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ package cc.unitmesh.pick.strategy.bizcode

import cc.unitmesh.core.completion.TypedIns
import cc.unitmesh.core.intelli.SimilarChunker
import cc.unitmesh.pick.builder.completionBuilders
import cc.unitmesh.pick.builder.instructionBuilders
import cc.unitmesh.pick.strategy.ins.RelatedCodeIns
import cc.unitmesh.pick.strategy.base.CodeStrategyBuilder
import cc.unitmesh.pick.worker.job.JobContext
@@ -46,7 +46,7 @@ class RelatedCodeStrategyBuilder(private val context: JobContext) : CodeStrategy
}

// 3. build completion instruction
val builders = completionBuilders(context.instructionBuilderTypes, context)
val builders = instructionBuilders(context.instructionBuilderTypes, context)
val containerIns = builders.asSequence().map {
it.build(container)
}.flatten()
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ package cc.unitmesh.pick.strategy.bizcode
import cc.unitmesh.core.SupportedLang
import cc.unitmesh.core.completion.TypedIns
import cc.unitmesh.core.intelli.SimilarChunker
import cc.unitmesh.pick.builder.completionBuilders
import cc.unitmesh.pick.builder.instructionBuilders
import cc.unitmesh.pick.similar.JavaSimilarChunker
import cc.unitmesh.pick.similar.TypeScriptSimilarChunker
import cc.unitmesh.pick.strategy.base.CodeStrategyBuilder
@@ -48,7 +48,7 @@ class SimilarChunksStrategyBuilder(private val context: JobContext) : CodeStrate
SupportedLang.RUST -> TODO()
}

val builders = completionBuilders(context.instructionBuilderTypes, context)
val builders = instructionBuilders(context.instructionBuilderTypes, context)
val containerIns = builders.asSequence().map {
it.build(container)
}.flatten()
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cc.unitmesh.pick.builder.bizcode;
package cc.unitmesh.pick.builder.completion;

import cc.unitmesh.pick.option.InsOutputConfig
import cc.unitmesh.pick.worker.job.InstructionFileJob
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cc.unitmesh.pick.builder.bizcode;
package cc.unitmesh.pick.builder.completion;

import cc.unitmesh.pick.option.InsOutputConfig
import cc.unitmesh.pick.worker.job.InstructionFileJob
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cc.unitmesh.pick.builder.bizcode;
package cc.unitmesh.pick.builder.completion;

import cc.unitmesh.pick.option.InsOutputConfig
import cc.unitmesh.pick.worker.job.InstructionFileJob

0 comments on commit 1931b16

Please sign in to comment.