diff --git a/unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/InsBuilderFactory.kt b/unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/InsBuilderFactory.kt new file mode 100644 index 00000000..f737c6a7 --- /dev/null +++ b/unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/InsBuilderFactory.kt @@ -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, context: JobContext) : List { + 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") +} diff --git a/unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/InsBuilderUtil.kt b/unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/InsBuilderUtil.kt deleted file mode 100644 index 36626443..00000000 --- a/unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/InsBuilderUtil.kt +++ /dev/null @@ -1,38 +0,0 @@ -package cc.unitmesh.pick.builder - -import cc.unitmesh.core.completion.TypedInsBuilder -import cc.unitmesh.core.completion.InstructionBuilderType -import cc.unitmesh.core.unittest.TestCodeBuilder -import cc.unitmesh.core.unittest.TestCodeBuilderType -import cc.unitmesh.pick.builder.bizcode.AfterBlockCodeTypedInsBuilder -import cc.unitmesh.pick.builder.bizcode.InBlockCodeTypedInsBuilder -import cc.unitmesh.pick.builder.bizcode.InlineCodeTypedInsBuilder -import cc.unitmesh.pick.builder.unittest.java.ClassTestCodeBuilder -import cc.unitmesh.pick.builder.unittest.java.JavaMethodTestCodeBuilder -import cc.unitmesh.pick.worker.job.JobContext -import kotlinx.serialization.SerializationException - -fun completionBuilders(types: List, context: JobContext) : List { - return types.map { completionBuilder(it, context) } -} - -fun completionBuilder(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") -} - -fun testBuilders(types: List, context: JobContext) : List { - return types.map { testBuilder(it, context) } -} - -fun testBuilder(type: TestCodeBuilderType, context: JobContext): TestCodeBuilder { - return mapOf( - TestCodeBuilderType.METHOD_UNIT to JavaMethodTestCodeBuilder(context), - TestCodeBuilderType.CLASS_UNIT to ClassTestCodeBuilder(context), - )[type] ?: throw SerializationException("Unknown message type: $type") -} diff --git a/unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/DocumentationTypedInsBuilder.kt b/unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/comment/DocumentationTypedInsBuilder.kt similarity index 93% rename from unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/DocumentationTypedInsBuilder.kt rename to unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/comment/DocumentationTypedInsBuilder.kt index 4286811d..5972fa0a 100644 --- a/unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/DocumentationTypedInsBuilder.kt +++ b/unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/comment/DocumentationTypedInsBuilder.kt @@ -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 diff --git a/unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/bizcode/AfterBlockCodeTypedInsBuilder.kt b/unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/completion/AfterBlockCodeTypedInsBuilder.kt similarity index 97% rename from unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/bizcode/AfterBlockCodeTypedInsBuilder.kt rename to unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/completion/AfterBlockCodeTypedInsBuilder.kt index 0b12fd89..0d63256b 100644 --- a/unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/bizcode/AfterBlockCodeTypedInsBuilder.kt +++ b/unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/completion/AfterBlockCodeTypedInsBuilder.kt @@ -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 diff --git a/unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/bizcode/InBlockCodeTypedInsBuilder.kt b/unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/completion/InBlockCodeTypedInsBuilder.kt similarity index 95% rename from unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/bizcode/InBlockCodeTypedInsBuilder.kt rename to unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/completion/InBlockCodeTypedInsBuilder.kt index 6bc0a1de..cb1b3b4e 100644 --- a/unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/bizcode/InBlockCodeTypedInsBuilder.kt +++ b/unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/completion/InBlockCodeTypedInsBuilder.kt @@ -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 diff --git a/unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/bizcode/InlineCodeTypedInsBuilder.kt b/unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/completion/InlineCodeTypedInsBuilder.kt similarity index 98% rename from unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/bizcode/InlineCodeTypedInsBuilder.kt rename to unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/completion/InlineCodeTypedInsBuilder.kt index 038911d1..4dd2bb5a 100644 --- a/unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/bizcode/InlineCodeTypedInsBuilder.kt +++ b/unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/completion/InlineCodeTypedInsBuilder.kt @@ -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 diff --git a/unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/TestCodeTypedInsBuilder.kt b/unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/unittest/TestCodeTypedInsBuilder.kt similarity index 95% rename from unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/TestCodeTypedInsBuilder.kt rename to unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/unittest/TestCodeTypedInsBuilder.kt index f3b7af24..394bbfc0 100644 --- a/unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/TestCodeTypedInsBuilder.kt +++ b/unit-picker/src/main/kotlin/cc/unitmesh/pick/builder/unittest/TestCodeTypedInsBuilder.kt @@ -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 diff --git a/unit-picker/src/main/kotlin/cc/unitmesh/pick/strategy/bizcode/RelatedCodeStrategyBuilder.kt b/unit-picker/src/main/kotlin/cc/unitmesh/pick/strategy/bizcode/RelatedCodeStrategyBuilder.kt index bcd2dad0..77162a8d 100644 --- a/unit-picker/src/main/kotlin/cc/unitmesh/pick/strategy/bizcode/RelatedCodeStrategyBuilder.kt +++ b/unit-picker/src/main/kotlin/cc/unitmesh/pick/strategy/bizcode/RelatedCodeStrategyBuilder.kt @@ -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() diff --git a/unit-picker/src/main/kotlin/cc/unitmesh/pick/strategy/bizcode/SimilarChunksStrategyBuilder.kt b/unit-picker/src/main/kotlin/cc/unitmesh/pick/strategy/bizcode/SimilarChunksStrategyBuilder.kt index 37bd0d0d..ce43c778 100644 --- a/unit-picker/src/main/kotlin/cc/unitmesh/pick/strategy/bizcode/SimilarChunksStrategyBuilder.kt +++ b/unit-picker/src/main/kotlin/cc/unitmesh/pick/strategy/bizcode/SimilarChunksStrategyBuilder.kt @@ -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() diff --git a/unit-picker/src/test/kotlin/cc/unitmesh/pick/builder/bizcode/AfterBlockCodeTypedInsBuilderTest.kt b/unit-picker/src/test/kotlin/cc/unitmesh/pick/builder/completion/AfterBlockCodeTypedInsBuilderTest.kt similarity index 97% rename from unit-picker/src/test/kotlin/cc/unitmesh/pick/builder/bizcode/AfterBlockCodeTypedInsBuilderTest.kt rename to unit-picker/src/test/kotlin/cc/unitmesh/pick/builder/completion/AfterBlockCodeTypedInsBuilderTest.kt index 46b565b9..3cec2cd8 100644 --- a/unit-picker/src/test/kotlin/cc/unitmesh/pick/builder/bizcode/AfterBlockCodeTypedInsBuilderTest.kt +++ b/unit-picker/src/test/kotlin/cc/unitmesh/pick/builder/completion/AfterBlockCodeTypedInsBuilderTest.kt @@ -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 diff --git a/unit-picker/src/test/kotlin/cc/unitmesh/pick/builder/bizcode/InBlockCodeTypedInsBuilderTest.kt b/unit-picker/src/test/kotlin/cc/unitmesh/pick/builder/completion/InBlockCodeTypedInsBuilderTest.kt similarity index 97% rename from unit-picker/src/test/kotlin/cc/unitmesh/pick/builder/bizcode/InBlockCodeTypedInsBuilderTest.kt rename to unit-picker/src/test/kotlin/cc/unitmesh/pick/builder/completion/InBlockCodeTypedInsBuilderTest.kt index e670c8da..92cab61f 100644 --- a/unit-picker/src/test/kotlin/cc/unitmesh/pick/builder/bizcode/InBlockCodeTypedInsBuilderTest.kt +++ b/unit-picker/src/test/kotlin/cc/unitmesh/pick/builder/completion/InBlockCodeTypedInsBuilderTest.kt @@ -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 diff --git a/unit-picker/src/test/kotlin/cc/unitmesh/pick/builder/bizcode/InlineCodeTypedInsBuilderTest.kt b/unit-picker/src/test/kotlin/cc/unitmesh/pick/builder/completion/InlineCodeTypedInsBuilderTest.kt similarity index 97% rename from unit-picker/src/test/kotlin/cc/unitmesh/pick/builder/bizcode/InlineCodeTypedInsBuilderTest.kt rename to unit-picker/src/test/kotlin/cc/unitmesh/pick/builder/completion/InlineCodeTypedInsBuilderTest.kt index 72c04929..25f9a178 100644 --- a/unit-picker/src/test/kotlin/cc/unitmesh/pick/builder/bizcode/InlineCodeTypedInsBuilderTest.kt +++ b/unit-picker/src/test/kotlin/cc/unitmesh/pick/builder/completion/InlineCodeTypedInsBuilderTest.kt @@ -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