Skip to content

Commit 82b970a

Browse files
committed
Add InlineCompletion request
1 parent a4e4288 commit 82b970a

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

Tool/Sources/GitHubCopilotService/LanguageServer/GitHubCopilotRequest.swift

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,60 @@ enum GitHubCopilotRequest {
241241
}
242242
}
243243

244+
struct InlineCompletion: GitHubCopilotRequestType {
245+
struct Response: Codable {
246+
var items: [InlineCompletionItem]
247+
}
248+
249+
struct InlineCompletionItem: Codable {
250+
var insertText: String
251+
var filterText: String?
252+
var range: Range?
253+
var command: Command?
254+
255+
struct Range: Codable {
256+
var start: Position
257+
var end: Position
258+
}
259+
260+
struct Command: Codable {
261+
var title: String
262+
var command: String
263+
var arguments: [String]?
264+
}
265+
}
266+
267+
var doc: GitHubCopilotDoc
268+
269+
struct Input: Codable {
270+
var textDocument: _TextDocument; struct _TextDocument: Codable {
271+
var uri: String
272+
}
273+
274+
var position: Position
275+
var formattingOptions: FormattingOptions
276+
var context: _Context; struct _Context: Codable {
277+
enum TriggerKind: Int, Codable {
278+
case invoked = 1
279+
case automatic = 2
280+
}
281+
282+
var triggerKind: TriggerKind
283+
}
284+
}
285+
286+
var request: ClientRequest {
287+
let data = (try? JSONEncoder().encode(Input(
288+
textDocument: .init(uri: doc.uri),
289+
position: doc.position,
290+
formattingOptions: .init(tabSize: doc.tabSize, insertSpaces: doc.insertSpaces),
291+
context: .init(triggerKind: .invoked)
292+
))) ?? Data()
293+
let dict = (try? JSONDecoder().decode(JSONValue.self, from: data)) ?? .hash([:])
294+
return .custom("textDocument/inlineCompletion", dict)
295+
}
296+
}
297+
244298
struct GetPanelCompletions: GitHubCopilotRequestType {
245299
struct Response: Codable {
246300
var completions: [GitHubCopilotCodeSuggestion]

0 commit comments

Comments
 (0)