|
| 1 | +import Foundation |
| 2 | +import JSONRPC |
| 3 | +import LanguageServerProtocol |
| 4 | +import SuggestionModel |
| 5 | + |
| 6 | +struct CodeiumCompletion: Codable { |
| 7 | + var completionId: String |
| 8 | + var text: String |
| 9 | + var prefix: String? |
| 10 | + var stop: String? |
| 11 | +// var score: Double |
| 12 | +// var tokens: [UInt64] |
| 13 | +// var decodedTokens: [String] |
| 14 | +// var probabilities: [Double] |
| 15 | +// var adjustedProbabilities: [Double] |
| 16 | +// var generatedLength: Int |
| 17 | +} |
| 18 | + |
| 19 | +struct CodeiumCompletionItem: Codable { |
| 20 | + var completion: CodeiumCompletion |
| 21 | + var suffix: Suffix? |
| 22 | + var range: Range |
| 23 | + var source: CompletionSource |
| 24 | + var completionParts: [CompletionPart] |
| 25 | +} |
| 26 | + |
| 27 | +struct Suffix: Codable { |
| 28 | + /// Text to insert after the cursor when accepting the completion. |
| 29 | + var text: String |
| 30 | + /// Cursor position delta (as signed offset) from the end of the inserted |
| 31 | + /// completion (including the suffix). |
| 32 | + var deltaCursorOffset: Int |
| 33 | +} |
| 34 | + |
| 35 | +struct Range: Codable { |
| 36 | + var startOffset: String? |
| 37 | + var endOffset: String? |
| 38 | + var startPosition: DocumentPosition? |
| 39 | + var endPosition: DocumentPosition? |
| 40 | +} |
| 41 | + |
| 42 | +enum CompletionSource: String, Codable { |
| 43 | + case unspecified = "COMPLETION_SOURCE_UNSPECIFIED" |
| 44 | + case typingAsSuggested = "COMPLETION_SOURCE_TYPING_AS_SUGGESTED" |
| 45 | + case cache = "COMPLETION_SOURCE_CACHE" |
| 46 | + case network = "COMPLETION_SOURCE_NETWORK" |
| 47 | +} |
| 48 | + |
| 49 | +/// Represents a contiguous part of the completion text that is not |
| 50 | +/// already in the document. |
| 51 | +struct CompletionPart: Codable { |
| 52 | + enum CompletionPartType: String, Codable { |
| 53 | + case unspecified = "COMPLETION_PART_TYPE_UNSPECIFIED" |
| 54 | + /// Single-line completion parts that appear within an existing line of text. |
| 55 | + case inline = "COMPLETION_PART_TYPE_INLINE" |
| 56 | + /// Possibly multi-line completion parts that appear below an existing line of text. |
| 57 | + case block = "COMPLETION_PART_TYPE_BLOCK" |
| 58 | + /// Like COMPLETION_PART_TYPE_INLINE, but overwrites the existing text. |
| 59 | + case inline_mask = "COMPLETION_PART_TYPE_INLINE_MASK" |
| 60 | + } |
| 61 | + |
| 62 | + var text: String |
| 63 | + /// Offset in the original document where the part starts. For block |
| 64 | + /// parts, this is always the end of the line before the block. |
| 65 | + var offset: String |
| 66 | + var type: CompletionPartType |
| 67 | + /// The section of the original line that came before this part. Only valid for |
| 68 | + /// COMPLETION_PART_TYPE_INLINE. |
| 69 | + var prefix: String? |
| 70 | + /// In the case of COMPLETION_PART_TYPE_BLOCK, represents the line it is below. |
| 71 | + var line: String? |
| 72 | +} |
| 73 | + |
| 74 | +struct CodeiumDocument: Codable { |
| 75 | + var absolute_path: String |
| 76 | + // Path relative to the root of the workspace. |
| 77 | + var relative_path: String |
| 78 | + var text: String |
| 79 | + // Language ID provided by the editor. |
| 80 | + var editor_language: String |
| 81 | + // Language enum standardized across editors. |
| 82 | + var language: CodeiumSupportedLanguage |
| 83 | + // Measured in number of UTF-8 bytes. |
| 84 | + // var cursor_offset: UInt64? |
| 85 | + // May be present instead of cursor_offset. |
| 86 | + var cursor_position: DocumentCursorPosition? |
| 87 | + // \n or \r\n, if known. |
| 88 | + var line_ending: String = "\n" |
| 89 | +} |
| 90 | + |
| 91 | +struct DocumentPosition: Codable { |
| 92 | + /// 0-indexed. Measured in UTF-8 bytes. |
| 93 | + var row: String? |
| 94 | + /// 0-indexed. Measured in UTF-8 bytes. |
| 95 | + var col: String? |
| 96 | +} |
| 97 | + |
| 98 | +struct DocumentCursorPosition: Codable { |
| 99 | + /// 0-indexed. Measured in UTF-8 bytes. |
| 100 | + var row: Int |
| 101 | + /// 0-indexed. Measured in UTF-8 bytes. |
| 102 | + var col: Int |
| 103 | +} |
| 104 | + |
| 105 | +struct CodeiumEditorOptions: Codable { |
| 106 | + var tab_size: Int |
| 107 | + var insert_spaces: Bool |
| 108 | +} |
| 109 | + |
| 110 | +struct Metadata: Codable { |
| 111 | + var ide_name: String |
| 112 | + var ide_version: String |
| 113 | + var extension_name: String |
| 114 | + var extension_version: String |
| 115 | + var api_key: String |
| 116 | + |
| 117 | + /// UID identifying a single session for the given user. |
| 118 | + var session_id: String |
| 119 | + |
| 120 | + /// Used purely in language server to cancel in flight requests. |
| 121 | + /// If request_id is 0, then the request is not cancelable. |
| 122 | + /// This should be a strictly monotonically increasing number |
| 123 | + /// for the duration of a session. |
| 124 | + var request_id: UInt64 |
| 125 | +} |
| 126 | + |
| 127 | +enum CodeiumState: String, Codable { |
| 128 | + case unspecified = "CODEIUM_STATE_UNSPECIFIED" |
| 129 | + case inactive = "CODEIUM_STATE_INACTIVE" |
| 130 | + case processing = "CODEIUM_STATE_PROCESSING" |
| 131 | + case success = "CODEIUM_STATE_SUCCESS" |
| 132 | + case warning = "CODEIUM_STATE_WARNING" |
| 133 | + case error = "CODEIUM_STATE_ERROR" |
| 134 | +} |
| 135 | + |
| 136 | +struct State: Codable { |
| 137 | + var state: CodeiumState |
| 138 | + var message: String |
| 139 | +} |
| 140 | + |
0 commit comments