forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCurrentEditorSkill.swift
More file actions
46 lines (41 loc) · 1.6 KB
/
Copy pathCurrentEditorSkill.swift
File metadata and controls
46 lines (41 loc) · 1.6 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
import ConversationServiceProvider
import Foundation
import GitHubCopilotService
import JSONRPC
import SystemUtils
public class CurrentEditorSkill: ConversationSkill {
public static let ID = "current-editor"
public let currentFile: FileReference
public var id: String {
return CurrentEditorSkill.ID
}
public var currentFilePath: String { currentFile.url.path }
public init(
currentFile: FileReference
) {
self.currentFile = currentFile
}
public func applies(params: ConversationContextParams) -> Bool {
return params.skillId == self.id
}
public static let readabilityErrorMessageProvider: FileUtils.ReadabilityErrorMessageProvider = { status in
switch status {
case .readable:
return nil
case .notFound:
return "Copilot can’t find the current file, so it's not included."
case .permissionDenied:
return "Copilot can't access the current file. Enable \"Files & Folders\" access in [System Settings](x-apple.systempreferences:com.apple.preference.security?Privacy_FilesAndFolders)."
}
}
public func resolveSkill(request: ConversationContextRequest, completion: JSONRPCResponseHandler){
let uri: String? = self.currentFile.url.absoluteString
completion(
AnyJSONRPCResponse(id: request.id,
result: JSONValue.array([
JSONValue.hash(["uri" : .string(uri ?? "")]),
JSONValue.null
]))
)
}
}