forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblemsInActiveDocumentSkill.swift
More file actions
52 lines (46 loc) · 1.92 KB
/
ProblemsInActiveDocumentSkill.swift
File metadata and controls
52 lines (46 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import ConversationServiceProvider
import Foundation
import GitHubCopilotService
import JSONRPC
import XcodeInspector
public class ProblemsInActiveDocumentSkill: ConversationSkill {
public static let ID = "problems-in-active-document"
public var id: String {
return ProblemsInActiveDocumentSkill.ID
}
public init() {
}
public func applies(params: ConversationContextParams) -> Bool {
return params.skillId == self.id
}
public func resolveSkill(request: ConversationContextRequest, completion: @escaping (AnyJSONRPCResponse) -> Void) {
Task {
let editor = await XcodeInspector.shared.getFocusedEditorContent()
let result: JSONValue = JSONValue.hash([
"uri": JSONValue.string(editor?.documentURL.absoluteString ?? ""),
"problems": JSONValue.array(editor?.editorContent?.lineAnnotations.map { annotation in
JSONValue.hash([
"message": JSONValue.string(annotation.message),
"range": JSONValue.hash([
"start": JSONValue.hash([
"line": JSONValue.number(Double(annotation.line)),
"character": JSONValue.number(0)
]),
"end": JSONValue.hash([
"line": JSONValue.number(Double(annotation.line)),
"character": JSONValue.number(0)
])
])
])
} ?? [])
])
completion(
AnyJSONRPCResponse(id: request.id,
result: JSONValue.array([
result,
JSONValue.null
]))
)
}
}
}