Skip to content

Commit

Permalink
Support Copilot.vim 1.17.0 to 1.19.x
Browse files Browse the repository at this point in the history
  • Loading branch information
intitni committed Feb 20, 2024
1 parent 09b77f2 commit 0deae85
Showing 1 changed file with 49 additions and 23 deletions.
72 changes: 49 additions & 23 deletions Tool/Sources/GitHubCopilotService/GitHubCopilotRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public struct GitHubCopilotCodeSuggestion: Codable, Equatable {
public var displayText: String
}


enum GitHubCopilotRequest {
struct SetEditorInfo: GitHubCopilotRequestType {
struct Response: Codable {}
Expand Down Expand Up @@ -80,40 +79,61 @@ enum GitHubCopilotRequest {
])
}
}
var editorConfiguration: JSONValue? {

var http: JSONValue? {
var dict: [String: JSONValue] = [:]
if let networkProxy {
dict["http"] = networkProxy
let host = UserDefaults.shared.value(for: \.gitHubCopilotProxyHost)
if host.isEmpty { return nil }
var port = UserDefaults.shared.value(for: \.gitHubCopilotProxyPort)
if port.isEmpty { port = "80" }
let username = UserDefaults.shared.value(for: \.gitHubCopilotProxyUsername)
let password = UserDefaults.shared.value(for: \.gitHubCopilotProxyPassword)
let strictSSL = UserDefaults.shared.value(for: \.gitHubCopilotUseStrictSSL)

let url = if !username.isEmpty {
"http://\(username):\(password)@\(host):\(port)"
} else {
"http://\(host):\(port)"
}


dict["proxy"] = .string(url)
dict["proxyStrictSSL"] = .bool(strictSSL)

if dict.isEmpty { return nil }

return .hash(dict)
}

var editorConfiguration: JSONValue? {
var dict: [String: JSONValue] = [:]
dict["http"] = http

let enterpriseURI = UserDefaults.shared.value(for: \.gitHubCopilotEnterpriseURI)
if !enterpriseURI.isEmpty {
dict["github-enterprise"] = .hash([
"uri": .string(enterpriseURI)
"uri": .string(enterpriseURI),
])
}

if dict.isEmpty { return nil }
return .hash(dict)
}

var request: ClientRequest {
if let editorConfiguration {
return .custom("setEditorInfo", .hash([
"editorInfo": .hash([
"name": "Xcode",
"version": "",
]),
"editorPluginInfo": .hash([
"name": "Copilot for Xcode",
"version": "",
]),
"editorConfiguration": editorConfiguration,
]))
var authProvider: JSONValue? {
var dict: [String: JSONValue] = [:]
let enterpriseURI = UserDefaults.shared.value(for: \.gitHubCopilotEnterpriseURI)
if !enterpriseURI.isEmpty {
dict["github-enterprise"] = .hash([
"url": .string(enterpriseURI),
])
}

return .custom("setEditorInfo", .hash([
if dict.isEmpty { return nil }
return .hash(dict)
}

var request: ClientRequest {
var dict: [String: JSONValue] = [
"editorInfo": .hash([
"name": "Xcode",
"version": "",
Expand All @@ -122,7 +142,13 @@ enum GitHubCopilotRequest {
"name": "Copilot for Xcode",
"version": "",
]),
]))
]

dict["editorConfiguration"] = editorConfiguration
dict["authProvider"] = authProvider
dict["networkProxy"] = networkProxy

return .custom("setEditorInfo", .hash(dict))
}
}

Expand Down

0 comments on commit 0deae85

Please sign in to comment.