Skip to content

Commit

Permalink
feat(doc): init builder for build in Kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Dec 28, 2023
1 parent 8ebbec9 commit e03dd14
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
package cc.unitmesh.core.completion

/**
* The `CompletionBuilderType` enum represents the different types of code completion that can be generated by the completion builder.
*
* - `INLINE_COMPLETION`: This type generates code after the cursor position. For example, if the text after `Blog blog = ` is `new Blog();`, this type will generate `new Blog();`.
*
* - `IN_BLOCK_COMPLETION`: This type generates the rest of the code for a correct block. It is typically used for generating code within a function or method.
*
* - `AFTER_BLOCK_COMPLETION`: This type generates code after a block. It is commonly used for generating multiple functions or methods.
*
* - `TEST_CODE_GEN`: This type generates the full code for a file. It is often used for generating test code, class code, or API code.
*
* - `DOCUMENTATION`: This type generates documentation for code. It is used to generate comments and documentation for classes, methods, and variables.
*/
enum class CompletionBuilderType {
/**
* generate code after cursor, like text after `Blog blog = `, will be `new Blog();`
Expand All @@ -20,4 +33,9 @@ enum class CompletionBuilderType {
* generate full file code, like test code, class code, api code
*/
TEST_CODE_GEN,

/**
* generate documentation for code
*/
DOCUMENTATION
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cc.unitmesh.pick.builder

import cc.unitmesh.core.completion.CodeCompletionIns
import cc.unitmesh.core.completion.CompletionBuilder
import cc.unitmesh.core.completion.TypedIns
import cc.unitmesh.pick.worker.job.JobContext
import chapi.domain.core.CodeDataStruct
import chapi.domain.core.CodeFunction

class DocumentationCompletionBuilder(val context: JobContext) : CompletionBuilder {
override fun build(dataStruct: CodeDataStruct): List<TypedIns> {
return listOf()
}

override fun build(function: CodeFunction): List<CodeCompletionIns> {
return listOf()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ fun completionBuilder(completionBuilderType: CompletionBuilderType, context: Job
CompletionBuilderType.IN_BLOCK_COMPLETION to InBlockCodeCompletionBuilder(context),
CompletionBuilderType.AFTER_BLOCK_COMPLETION to AfterBlockCodeCompletionBuilder(context),
CompletionBuilderType.TEST_CODE_GEN to TestCodeCompletionBuilder(context),
CompletionBuilderType.DOCUMENTATION to DocumentationCompletionBuilder(context),
)[completionBuilderType] ?: throw SerializationException("Unknown message type: $completionBuilderType")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ data class InsPickerOption(
*/
val codeContextStrategies: List<BizCodeContextStrategy> = listOf(
BizCodeContextStrategy.RELATED_CODE,
// BizCodeContextStrategy.SIMILAR_CHUNKS,
BizCodeContextStrategy.SIMILAR_CHUNKS,
),
/**
* The [CompletionBuilderType], which will according you IDE strategy to generate the type.
Expand All @@ -70,7 +70,8 @@ data class InsPickerOption(
CompletionBuilderType.AFTER_BLOCK_COMPLETION,
CompletionBuilderType.IN_BLOCK_COMPLETION,
CompletionBuilderType.INLINE_COMPLETION,
// CompletionBuilderType.TEST_CODE_GEN,
CompletionBuilderType.TEST_CODE_GEN,
CompletionBuilderType.DOCUMENTATION,
),
/**
* The [CodeQualityType], will be like a tree to hold the item.
Expand Down Expand Up @@ -115,7 +116,12 @@ data class InsPickerOption(

fun repoFileName() = "${encodeFileName(url)}_${encodeFileName(branch)}_${language}.jsonl"

// for / \ : * ? " < > |, which is not allowed in file name
/**
* Encodes a given string to be used as a file name by replacing characters that are not allowed in file names.
*
* @param string the string to be encoded
* @return the encoded string with characters such as / \ : * ? " < > | replaced with underscores (_)
*/
fun encodeFileName(string: String): String {
return string.replace("/", "_")
.replace("\\", "_")
Expand Down

0 comments on commit e03dd14

Please sign in to comment.