Skip to content

Commit

Permalink
feat(comments): init comments for #1
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Dec 29, 2023
1 parent ddeece8 commit 1d60f8d
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package cc.unitmesh.core.comments

import cc.unitmesh.core.completion.TypedIns
import chapi.domain.core.CodeDataStruct

interface CommentsBuilder {
fun build(dataStruct: CodeDataStruct): List<TypedIns>
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package cc.unitmesh.core.comments

enum class CommentsBuilderType {
METHOD_LEVEL,
CLASS_LEVEL,
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cc.unitmesh.pick.builder
import cc.unitmesh.core.completion.CompletionBuilder
import cc.unitmesh.core.completion.CompletionBuilderType
import cc.unitmesh.core.unittest.TestCodeBuilderType
import cc.unitmesh.core.unittest.TestCodeBuilder
import cc.unitmesh.core.comments.CommentsBuilder
import cc.unitmesh.pick.builder.bizcode.AfterBlockCodeCompletionBuilder
import cc.unitmesh.pick.builder.bizcode.InBlockCodeCompletionBuilder
import cc.unitmesh.pick.builder.bizcode.InlineCodeCompletionBuilder
Expand All @@ -26,12 +26,11 @@ fun completionBuilder(completionBuilderType: CompletionBuilderType, context: Job
)[completionBuilderType] ?: throw SerializationException("Unknown message type: $completionBuilderType")
}


fun testBuilders(types: List<TestCodeBuilderType>, context: JobContext) : List<TestCodeBuilder> {
fun testBuilders(types: List<TestCodeBuilderType>, context: JobContext) : List<CommentsBuilder> {
return types.map { testBuilder(it, context) }
}

fun testBuilder(type: TestCodeBuilderType, context: JobContext): TestCodeBuilder {
fun testBuilder(type: TestCodeBuilderType, context: JobContext): CommentsBuilder {
return mapOf(
TestCodeBuilderType.METHOD_UNIT to JavaMethodTestCodeBuilder(context),
TestCodeBuilderType.CLASS_UNIT to ClassTestCodeBuilder(context),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cc.unitmesh.pick.builder.unittest.java
import cc.unitmesh.core.ast.NodeIdentifier
import cc.unitmesh.core.ast.NodeType
import cc.unitmesh.core.unittest.TestCodeBuilderType
import cc.unitmesh.core.unittest.TestCodeBuilder
import cc.unitmesh.core.comments.CommentsBuilder
import cc.unitmesh.pick.builder.unittest.base.BasicTestIns
import cc.unitmesh.pick.ext.checkNamingStyle
import cc.unitmesh.pick.ext.toSourceCode
Expand All @@ -17,7 +17,7 @@ import chapi.domain.core.CodeDataStruct
* @constructor Creates a `ClassTestCodeBuilder` with the specified job context.
* @param context the job context for the test code generation
*/
class ClassTestCodeBuilder(private val context: JobContext) : TestCodeBuilder {
class ClassTestCodeBuilder(private val context: JobContext) : CommentsBuilder {
/**
* 为给定的 CodeDataStruct 生成测试指令。
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cc.unitmesh.pick.builder.unittest.java

import cc.unitmesh.core.ast.NodeIdentifier
import cc.unitmesh.core.ast.NodeType
import cc.unitmesh.core.unittest.TestCodeBuilder
import cc.unitmesh.core.comments.CommentsBuilder
import cc.unitmesh.core.unittest.TestCodeBuilderType
import cc.unitmesh.pick.builder.unittest.base.BasicTestIns
import cc.unitmesh.pick.ext.checkNamingStyle
Expand All @@ -17,7 +17,7 @@ import chapi.domain.core.CodeFunction
*
* @property context 生成测试指令的上下文
*/
class JavaMethodTestCodeBuilder(private val context: JobContext) : TestCodeBuilder {
class JavaMethodTestCodeBuilder(private val context: JobContext) : CommentsBuilder {

/**
* 针对给定的 [CodeDataStruct] 的每个 [CodeFunction] 生成 [BasicTestIns]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cc.unitmesh.pick.builder.unittest.kotlin

import cc.unitmesh.core.ast.NodeIdentifier
import cc.unitmesh.core.ast.NodeType
import cc.unitmesh.core.unittest.TestCodeBuilder
import cc.unitmesh.core.comments.CommentsBuilder
import cc.unitmesh.core.unittest.TestCodeBuilderType
import cc.unitmesh.pick.builder.unittest.base.BasicTestIns
import cc.unitmesh.pick.ext.checkNamingStyle
Expand All @@ -17,7 +17,7 @@ import chapi.domain.core.DataStructType
*
* @property context 生成测试指令的上下文
*/
class KotlinMethodTestCodeBuilder(private val context: JobContext) : TestCodeBuilder {
class KotlinMethodTestCodeBuilder(private val context: JobContext) : CommentsBuilder {

override fun build(
// 测试类,即当前类
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import cc.unitmesh.pick.worker.job.JobContext
/**
* 对于其它不需要上下文的 AI 能力,需要实现一个空的上下文策略,如注释生成。
*/
class CommentsStrategyBuilder(context: JobContext) : CodeStrategyBuilder {
class CommentsStrategyBuilder(val context: JobContext) : CodeStrategyBuilder {
override fun build(): List<TypedIns> {
val language = context.job.fileSummary.language.lowercase()
val container = context.job.container ?: return emptyList()

return emptyList()
}
}

0 comments on commit 1d60f8d

Please sign in to comment.