@@ -49,72 +49,41 @@ public struct GitHubCopilotCodeSuggestion: Codable, Equatable {
49
49
public var displayText : String
50
50
}
51
51
52
- enum GitHubCopilotRequest {
53
- // TODO migrate from setEditorInfo to didConfigurationChange
54
- struct SetEditorInfo : GitHubCopilotRequestType {
55
- struct Response : Codable { }
56
-
57
- let versionNumber = JSONValue ( stringLiteral: Bundle . main. infoDictionary ? [ " CFBundleShortVersionString " ] as? String ?? " " )
58
- let xcodeVersion = JSONValue ( stringLiteral: SystemInfo ( ) . xcodeVersion ( ) ?? " " )
59
-
60
- var networkProxy : JSONValue ? {
61
- let host = UserDefaults . shared. value ( for: \. gitHubCopilotProxyHost)
62
- if host. isEmpty { return nil }
63
- var port = UserDefaults . shared. value ( for: \. gitHubCopilotProxyPort)
64
- if port. isEmpty { port = " 80 " }
65
- let username = UserDefaults . shared. value ( for: \. gitHubCopilotProxyUsername)
66
- if username. isEmpty {
67
- return . hash( [
68
- " host " : . string( host) ,
69
- " port " : . number( Double ( Int ( port) ?? 80 ) ) ,
70
- " rejectUnauthorized " : . bool( UserDefaults . shared
71
- . value ( for: \. gitHubCopilotUseStrictSSL) ) ,
72
- ] )
73
- } else {
74
- return . hash( [
75
- " host " : . string( host) ,
76
- " port " : . number( Double ( Int ( port) ?? 80 ) ) ,
77
- " rejectUnauthorized " : . bool( UserDefaults . shared
78
- . value ( for: \. gitHubCopilotUseStrictSSL) ) ,
79
- " username " : . string( username) ,
80
- " password " : . string( UserDefaults . shared
81
- . value ( for: \. gitHubCopilotProxyPassword) ) ,
82
-
83
- ] )
84
- }
85
- }
86
-
87
- var authProvider : JSONValue ? {
88
- var dict : [ String : JSONValue ] = [ : ]
89
- let enterpriseURI = UserDefaults . shared. value ( for: \. gitHubCopilotEnterpriseURI)
90
- if !enterpriseURI. isEmpty {
91
- dict [ " url " ] = . string( enterpriseURI)
92
- }
52
+ public func editorConfiguration( ) -> JSONValue {
53
+ var proxyAuthorization : String ? {
54
+ let username = UserDefaults . shared. value ( for: \. gitHubCopilotProxyUsername)
55
+ if username. isEmpty { return nil }
56
+ let password = UserDefaults . shared. value ( for: \. gitHubCopilotProxyPassword)
57
+ return " \( username) : \( password) "
58
+ }
93
59
94
- if dict. isEmpty { return nil }
95
- return . hash( dict)
60
+ var http : JSONValue ? {
61
+ var d : [ String : JSONValue ] = [ : ]
62
+ let proxy = UserDefaults . shared. value ( for: \. gitHubCopilotProxyUrl)
63
+ if !proxy. isEmpty {
64
+ d [ " proxy " ] = . string( proxy)
96
65
}
97
-
98
- var request : ClientRequest {
99
- var dict : [ String : JSONValue ] = [
100
- " editorInfo " : . hash( [
101
- " name " : " Xcode " ,
102
- " version " : xcodeVersion,
103
- ] ) ,
104
- " editorPluginInfo " : . hash( [
105
- " name " : " copilot-xcode " ,
106
- " version " : versionNumber,
107
- ] ) ,
108
- ]
109
-
110
- dict [ " authProvider " ] = authProvider
111
- dict [ " networkProxy " ] = networkProxy
112
-
113
- return . custom( " setEditorInfo " , . hash( dict) )
66
+ if let proxyAuthorization = proxyAuthorization {
67
+ d [ " proxyAuthorization " ] = . string( proxyAuthorization)
114
68
}
69
+ d [ " proxyStrictSSL " ] = . bool( UserDefaults . shared. value ( for: \. gitHubCopilotUseStrictSSL) )
70
+ if d. isEmpty { return nil }
71
+ return . hash( d)
72
+ }
115
73
74
+ var authProvider : JSONValue ? {
75
+ let enterpriseURI = UserDefaults . shared. value ( for: \. gitHubCopilotEnterpriseURI)
76
+ if enterpriseURI. isEmpty { return nil }
77
+ return . hash( [ " uri " : . string( enterpriseURI) ] )
116
78
}
117
79
80
+ var d : [ String : JSONValue ] = [ : ]
81
+ if let http { d [ " http " ] = http }
82
+ if let authProvider { d [ " github-enterprise " ] = authProvider }
83
+ return . hash( d)
84
+ }
85
+
86
+ enum GitHubCopilotRequest {
118
87
struct GetVersion : GitHubCopilotRequestType {
119
88
struct Response : Codable {
120
89
var version : String
0 commit comments