Skip to content

Commit af2f668

Browse files
committed
Support Copilot.vim 1.17.0 to 1.19.x
1 parent 8325c3e commit af2f668

File tree

1 file changed

+49
-23
lines changed

1 file changed

+49
-23
lines changed

Tool/Sources/GitHubCopilotService/GitHubCopilotRequest.swift

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public struct GitHubCopilotCodeSuggestion: Codable, Equatable {
4949
public var displayText: String
5050
}
5151

52-
5352
enum GitHubCopilotRequest {
5453
struct SetEditorInfo: GitHubCopilotRequestType {
5554
struct Response: Codable {}
@@ -80,40 +79,61 @@ enum GitHubCopilotRequest {
8079
])
8180
}
8281
}
83-
84-
var editorConfiguration: JSONValue? {
82+
83+
var http: JSONValue? {
8584
var dict: [String: JSONValue] = [:]
86-
if let networkProxy {
87-
dict["http"] = networkProxy
85+
let host = UserDefaults.shared.value(for: \.gitHubCopilotProxyHost)
86+
if host.isEmpty { return nil }
87+
var port = UserDefaults.shared.value(for: \.gitHubCopilotProxyPort)
88+
if port.isEmpty { port = "80" }
89+
let username = UserDefaults.shared.value(for: \.gitHubCopilotProxyUsername)
90+
let password = UserDefaults.shared.value(for: \.gitHubCopilotProxyPassword)
91+
let strictSSL = UserDefaults.shared.value(for: \.gitHubCopilotUseStrictSSL)
92+
93+
let url = if !username.isEmpty {
94+
"http://\(username):\(password)@\(host):\(port)"
95+
} else {
96+
"http://\(host):\(port)"
8897
}
89-
98+
99+
dict["proxy"] = .string(url)
100+
dict["proxyStrictSSL"] = .bool(strictSSL)
101+
102+
if dict.isEmpty { return nil }
103+
104+
return .hash(dict)
105+
}
106+
107+
var editorConfiguration: JSONValue? {
108+
var dict: [String: JSONValue] = [:]
109+
dict["http"] = http
110+
90111
let enterpriseURI = UserDefaults.shared.value(for: \.gitHubCopilotEnterpriseURI)
91112
if !enterpriseURI.isEmpty {
92113
dict["github-enterprise"] = .hash([
93-
"uri": .string(enterpriseURI)
114+
"uri": .string(enterpriseURI),
94115
])
95116
}
96-
117+
97118
if dict.isEmpty { return nil }
98119
return .hash(dict)
99120
}
100121

101-
var request: ClientRequest {
102-
if let editorConfiguration {
103-
return .custom("setEditorInfo", .hash([
104-
"editorInfo": .hash([
105-
"name": "Xcode",
106-
"version": "",
107-
]),
108-
"editorPluginInfo": .hash([
109-
"name": "Copilot for Xcode",
110-
"version": "",
111-
]),
112-
"editorConfiguration": editorConfiguration,
113-
]))
122+
var authProvider: JSONValue? {
123+
var dict: [String: JSONValue] = [:]
124+
let enterpriseURI = UserDefaults.shared.value(for: \.gitHubCopilotEnterpriseURI)
125+
if !enterpriseURI.isEmpty {
126+
dict["github-enterprise"] = .hash([
127+
"url": .string(enterpriseURI),
128+
])
114129
}
115130

116-
return .custom("setEditorInfo", .hash([
131+
if dict.isEmpty { return nil }
132+
return .hash(dict)
133+
}
134+
135+
var request: ClientRequest {
136+
var dict: [String: JSONValue] = [
117137
"editorInfo": .hash([
118138
"name": "Xcode",
119139
"version": "",
@@ -122,7 +142,13 @@ enum GitHubCopilotRequest {
122142
"name": "Copilot for Xcode",
123143
"version": "",
124144
]),
125-
]))
145+
]
146+
147+
dict["editorConfiguration"] = editorConfiguration
148+
dict["authProvider"] = authProvider
149+
dict["networkProxy"] = networkProxy
150+
151+
return .custom("setEditorInfo", .hash(dict))
126152
}
127153
}
128154

0 commit comments

Comments
 (0)