@@ -12,6 +12,7 @@ import com.tabbyml.intellijtabby.lsp.protocol.server.LanguageServer
12
12
import com.tabbyml.intellijtabby.settings.KeymapSettings
13
13
import com.tabbyml.intellijtabby.settings.SettingsService
14
14
import com.tabbyml.intellijtabby.settings.SettingsState
15
+ import java.util.Base64
15
16
16
17
class ConfigurationSync (private val project : Project ) : Disposable {
17
18
private val messageBusConnection = project.messageBus.connect()
@@ -43,6 +44,23 @@ class ConfigurationSync(private val project: Project) : Disposable {
43
44
)
44
45
return buildClientProvidedConfig(cached)
45
46
}
47
+ private fun getProxyUrl (): String? {
48
+ val proxySettings = com.intellij.util.net.HttpConfigurable .getInstance()
49
+ return if (proxySettings.USE_HTTP_PROXY ) {
50
+ " http://${proxySettings.PROXY_HOST } :${proxySettings.PROXY_PORT } "
51
+ } else {
52
+ null
53
+ }
54
+ }
55
+
56
+ private fun getProxyAuthorization (): String? {
57
+ val proxySettings = com.intellij.util.net.HttpConfigurable .getInstance()
58
+ return if (! proxySettings.proxyLogin.isNullOrEmpty() && ! proxySettings.plainProxyPassword.isNullOrEmpty()) {
59
+ " Basic " + Base64 .getEncoder().encodeToString(" ${proxySettings.proxyLogin} :${proxySettings.plainProxyPassword} " .toByteArray())
60
+ } else {
61
+ null
62
+ }
63
+ }
46
64
47
65
fun startSync (server : LanguageServer ) {
48
66
messageBusConnection.subscribe(SettingsService .Listener .TOPIC , object : SettingsService .Listener {
@@ -74,11 +92,17 @@ class ConfigurationSync(private val project: Project) : Disposable {
74
92
private fun buildClientProvidedConfig (data : SettingsData ): ClientProvidedConfig {
75
93
val settings = data.settings
76
94
val keymap = data.keymap
95
+ val proxyUrl = getProxyUrl()
96
+ val proxyAuthorization = getProxyAuthorization()
77
97
return ClientProvidedConfig (
78
98
server = ClientProvidedConfig .ServerConfig (
79
99
endpoint = settings.serverEndpoint,
80
100
token = settings.serverToken,
81
101
),
102
+ proxy = ClientProvidedConfig .ProxyConfig (
103
+ url = proxyUrl,
104
+ authorization = proxyAuthorization,
105
+ ),
82
106
inlineCompletion = ClientProvidedConfig .InlineCompletionConfig (
83
107
triggerMode = when (settings.completionTriggerMode) {
84
108
SettingsState .TriggerMode .AUTOMATIC -> ClientProvidedConfig .InlineCompletionConfig .TriggerMode .AUTO
@@ -100,4 +124,4 @@ class ConfigurationSync(private val project: Project) : Disposable {
100
124
override fun dispose () {
101
125
messageBusConnection.dispose()
102
126
}
103
- }
127
+ }
0 commit comments