Skip to content

Commit

Permalink
feat: add inline code support
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Dec 16, 2023
1 parent 15683a0 commit 5c784ab
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import kotlinx.serialization.json.Json

@Serializable
data class CodeCompletionIns(
val language: String,
val beforeCursor: String,
val afterCursor: String,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ import chapi.domain.core.CodeFunction

class AfterBlockCodeCompletionBuilder(val context: JobContext) : InstructionBuilder {
override fun build(function: CodeFunction): List<CodeCompletionIns> {
TODO("Not yet implemented")
val position = function.Position
val beforeCursor = context.job.codeLines.subList(0, position.StartLine).joinToString("\n")

// pick after lines
val stopLine = if (position.StopLine == 0) {
context.job.codeLines.size
} else {
position.StopLine
}

val afterCursor = context.job.codeLines.subList(position.StartLine, stopLine).joinToString("\n")

return listOf(CodeCompletionIns(beforeCursor, afterCursor))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@ import chapi.domain.core.CodeFunction

class InBlockCodeCompletionBuilder(val context: JobContext) : InstructionBuilder {
override fun build(function: CodeFunction): List<CodeCompletionIns> {
TODO("Not yet implemented")
}
val position = function.Position
val beforeCursor = context.job.codeLines.subList(0, position.StartLine).joinToString("\n")

val stopLine = if (position.StopLine == 0) {
context.job.codeLines.size
} else {
position.StopLine
}

val afterCursor = context.job.codeLines.subList(position.StartLine, stopLine).joinToString("\n")

return listOf(CodeCompletionIns(beforeCursor, afterCursor))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import cc.unitmesh.pick.prompt.JobContext
import chapi.domain.core.CodeFunction

class InlineCodeCompletionBuilder(val context: JobContext) : InstructionBuilder {
fun isValidTypeOver(char: Char): Boolean {
return char == ')' || char == ']' || char == '}' || char == '"' || char == '\'' || char == '>' || char == ';'
}

override fun build(function: CodeFunction): List<CodeCompletionIns> {
TODO("Not yet implemented")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cc.unitmesh.pick.prompt.strategy

import cc.unitmesh.pick.prompt.Instruction
import cc.unitmesh.pick.prompt.CodeContextBuilder
import cc.unitmesh.pick.prompt.InstructionBuilder
import cc.unitmesh.pick.prompt.JobContext
import cc.unitmesh.pick.related.JavaSimilarChunker
import kotlinx.serialization.Serializable
Expand Down

0 comments on commit 5c784ab

Please sign in to comment.