Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(intellij): use ide proxy settings for tabby agent config #4103

Merged
merged 2 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion clients/intellij/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,3 @@ tasks {
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.tabbyml.intellijtabby.lsp.protocol.server.LanguageServer
import com.tabbyml.intellijtabby.settings.KeymapSettings
import com.tabbyml.intellijtabby.settings.SettingsService
import com.tabbyml.intellijtabby.settings.SettingsState
import java.util.Base64

class ConfigurationSync(private val project: Project) : Disposable {
private val messageBusConnection = project.messageBus.connect()
Expand Down Expand Up @@ -43,6 +44,23 @@ class ConfigurationSync(private val project: Project) : Disposable {
)
return buildClientProvidedConfig(cached)
}
private fun getProxyUrl(): String? {
val proxySettings = com.intellij.util.net.HttpConfigurable.getInstance()
return if (proxySettings.USE_HTTP_PROXY) {
"http://${proxySettings.PROXY_HOST}:${proxySettings.PROXY_PORT}"
} else {
null
}
}

private fun getProxyAuthorization(): String? {
val proxySettings = com.intellij.util.net.HttpConfigurable.getInstance()
return if (!proxySettings.proxyLogin.isNullOrEmpty() && !proxySettings.plainProxyPassword.isNullOrEmpty()) {
"Basic " + Base64.getEncoder().encodeToString("${proxySettings.proxyLogin}:${proxySettings.plainProxyPassword}".toByteArray())
} else {
null
}
}

fun startSync(server: LanguageServer) {
messageBusConnection.subscribe(SettingsService.Listener.TOPIC, object : SettingsService.Listener {
Expand Down Expand Up @@ -74,11 +92,17 @@ class ConfigurationSync(private val project: Project) : Disposable {
private fun buildClientProvidedConfig(data: SettingsData): ClientProvidedConfig {
val settings = data.settings
val keymap = data.keymap
val proxyUrl = getProxyUrl()
val proxyAuthorization = getProxyAuthorization()
return ClientProvidedConfig(
server = ClientProvidedConfig.ServerConfig(
endpoint = settings.serverEndpoint,
token = settings.serverToken,
),
proxy = ClientProvidedConfig.ProxyConfig(
url = proxyUrl,
authorization = proxyAuthorization,
),
inlineCompletion = ClientProvidedConfig.InlineCompletionConfig(
triggerMode = when (settings.completionTriggerMode) {
SettingsState.TriggerMode.AUTOMATIC -> ClientProvidedConfig.InlineCompletionConfig.TriggerMode.AUTO
Expand All @@ -100,4 +124,4 @@ class ConfigurationSync(private val project: Project) : Disposable {
override fun dispose() {
messageBusConnection.dispose()
}
}
}
Loading