Skip to content

Commit

Permalink
rename type Context{File => Item}, remove existing redundant ContextI…
Browse files Browse the repository at this point in the history
…tem type, (#3269)

Co-authored-by: Beatrix <[email protected]>
  • Loading branch information
sqs and abeatrix authored Mar 2, 2024
1 parent 3ae2b3e commit fa74675
Show file tree
Hide file tree
Showing 79 changed files with 1,080 additions and 1,124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package com.sourcegraph.cody.protocol_generated

data class ChatInputHistory(
val inputText: String? = null,
val inputContextFiles: List<ContextFile>? = null,
val inputContextFiles: List<ContextItem>? = null,
)

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ data class ChatMessage(
val speaker: SpeakerEnum? = null, // Oneof: human, assistant
val text: String? = null,
val displayText: String? = null,
val contextFiles: List<ContextFile>? = null,
val contextFiles: List<ContextItem>? = null,
val preciseContext: List<PreciseContext>? = null,
val buttons: List<ChatButton>? = null,
val data: Any? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,38 @@ import com.google.gson.JsonDeserializer
import com.google.gson.JsonElement
import java.lang.reflect.Type

sealed class ContextFile {
sealed class ContextItem {
companion object {
val deserializer: JsonDeserializer<ContextFile> =
val deserializer: JsonDeserializer<ContextItem> =
JsonDeserializer { element: JsonElement, _: Type, context: JsonDeserializationContext ->
when (element.asJsonObject.get("type").asString) {
"file" -> context.deserialize<ContextFileFile>(element, ContextFileFile::class.java)
"symbol" -> context.deserialize<ContextFileSymbol>(element, ContextFileSymbol::class.java)
"file" -> context.deserialize<ContextItemFile>(element, ContextItemFile::class.java)
"symbol" -> context.deserialize<ContextItemSymbol>(element, ContextItemSymbol::class.java)
else -> throw Exception("Unknown discriminator ${element}")
}
}
}
}

data class ContextFileFile(
data class ContextItemFile(
val uri: Uri? = null,
val range: ActiveTextEditorSelectionRange? = null,
val range: RangeData? = null,
val repoName: String? = null,
val revision: String? = null,
val title: String? = null,
val source: ContextFileSource? = null, // Oneof: embeddings, user, keyword, editor, filename, search, unified, selection, terminal
val content: String? = null,
val type: TypeEnum? = null, // Oneof: file
) : ContextFile() {
) : ContextItem() {

enum class TypeEnum {
@SerializedName("file") File,
}
}

data class ContextFileSymbol(
data class ContextItemSymbol(
val uri: Uri? = null,
val range: ActiveTextEditorSelectionRange? = null,
val range: RangeData? = null,
val repoName: String? = null,
val revision: String? = null,
val title: String? = null,
Expand All @@ -48,7 +48,7 @@ data class ContextFileSymbol(
val type: TypeEnum? = null, // Oneof: symbol
val symbolName: String? = null,
val kind: SymbolKind? = null, // Oneof: class, function, method
) : ContextFile() {
) : ContextItem() {

enum class TypeEnum {
@SerializedName("symbol") Symbol,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ data class `transcript-errorsExtensionMessage`(

data class UserContextFilesExtensionMessage(
val type: TypeEnum? = null, // Oneof: userContextFiles
val userContextFiles: List<ContextFile>? = null,
val userContextFiles: List<ContextItem>? = null,
) : ExtensionMessage() {

enum class TypeEnum {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ object ProtocolTypeAdapters {
fun register(gson: com.google.gson.GsonBuilder) {
gson.registerTypeAdapter(ExtensionMessage::class.java, ExtensionMessage.deserializer)
gson.registerTypeAdapter(CustomCommandResult::class.java, CustomCommandResult.deserializer)
gson.registerTypeAdapter(ContextFile::class.java, ContextFile.deserializer)
gson.registerTypeAdapter(ContextItem::class.java, ContextItem.deserializer)
gson.registerTypeAdapter(ContextProvider::class.java, ContextProvider.deserializer)
gson.registerTypeAdapter(WorkspaceEditOperation::class.java, WorkspaceEditOperation.deserializer)
gson.registerTypeAdapter(TextEdit::class.java, TextEdit.deserializer)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@file:Suppress("FunctionName", "ClassName", "unused", "EnumEntryName", "UnusedImport")
package com.sourcegraph.cody.protocol_generated

data class ActiveTextEditorSelectionRange(
data class RangeData(
val start: StartParams? = null,
val end: EndParams? = null,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ data class EventWebviewMessage(
data class SubmitWebviewMessage(
val command: CommandEnum? = null, // Oneof: submit
val addEnhancedContext: Boolean? = null,
val contextFiles: List<ContextFile>? = null,
val contextFiles: List<ContextItem>? = null,
val text: String? = null,
val submitType: ChatSubmitType? = null, // Oneof: user, user-newchat
) : WebviewMessage() {
Expand Down Expand Up @@ -169,7 +169,7 @@ data class `get-chat-modelsWebviewMessage`(
data class OpenFileWebviewMessage(
val command: CommandEnum? = null, // Oneof: openFile
val uri: Uri? = null,
val range: ActiveTextEditorSelectionRange? = null,
val range: RangeData? = null,
) : WebviewMessage() {

enum class CommandEnum {
Expand All @@ -180,7 +180,7 @@ data class OpenFileWebviewMessage(
data class OpenLocalFileWithRangeWebviewMessage(
val command: CommandEnum? = null, // Oneof: openLocalFileWithRange
val filePath: String? = null,
val range: ActiveTextEditorSelectionRange? = null,
val range: RangeData? = null,
) : WebviewMessage() {

enum class CommandEnum {
Expand All @@ -191,7 +191,7 @@ data class OpenLocalFileWithRangeWebviewMessage(
data class EditWebviewMessage(
val command: CommandEnum? = null, // Oneof: edit
val addEnhancedContext: Boolean? = null,
val contextFiles: List<ContextFile>? = null,
val contextFiles: List<ContextItem>? = null,
val text: String? = null,
val index: Int? = null,
) : WebviewMessage() {
Expand Down Expand Up @@ -364,7 +364,7 @@ data class SearchWebviewMessage(
data class `show-search-resultWebviewMessage`(
val command: CommandEnum? = null, // Oneof: show-search-result
val uri: Uri? = null,
val range: ActiveTextEditorSelectionRange? = null,
val range: RangeData? = null,
) : WebviewMessage() {

enum class CommandEnum {
Expand Down
Loading

0 comments on commit fa74675

Please sign in to comment.