diff --git a/build.gradle.kts b/build.gradle.kts index f85c1fb88..df20e94aa 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -133,6 +133,7 @@ dependencies { } } + implementation("com.typesafe:config:1.4.3") implementation("org.commonmark:commonmark:0.22.0") implementation("org.commonmark:commonmark-ext-gfm-tables:0.22.0") implementation("org.eclipse.lsp4j:org.eclipse.lsp4j.jsonrpc:0.23.1") diff --git a/gradle.properties b/gradle.properties index 1c4fb4c21..d54150100 100644 --- a/gradle.properties +++ b/gradle.properties @@ -24,4 +24,4 @@ kotlin.daemon.jvmargs=-Xmx2g -Xms500m nodeBinaries.commit=8755ae4c05fd476cd23f2972049111ba436c86d4 nodeBinaries.version=v20.12.2 cody.autocomplete.enableFormatting=true -cody.commit=23af99f690659084d820461a73a6fb094e52e998 +cody.commit=5dccf8dc97191083cc3fe2209b11edb0ebea0017 diff --git a/src/main/kotlin/com/sourcegraph/config/ConfigUtil.kt b/src/main/kotlin/com/sourcegraph/config/ConfigUtil.kt index 93abe6a55..c7074348a 100644 --- a/src/main/kotlin/com/sourcegraph/config/ConfigUtil.kt +++ b/src/main/kotlin/com/sourcegraph/config/ConfigUtil.kt @@ -1,7 +1,6 @@ package com.sourcegraph.config import com.google.gson.JsonObject -import com.google.gson.JsonParser import com.intellij.ide.plugins.PluginManagerCore import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.editor.Editor @@ -17,6 +16,9 @@ import com.sourcegraph.cody.config.CodyAuthenticationManager import com.sourcegraph.cody.config.ServerAuthLoader import com.sourcegraph.cody.config.SourcegraphServerPath import com.sourcegraph.cody.config.SourcegraphServerPath.Companion.from +import com.typesafe.config.ConfigFactory +import com.typesafe.config.ConfigRenderOptions +import com.typesafe.config.ConfigValueFactory import java.nio.file.Path import java.nio.file.Paths import kotlin.io.path.readText @@ -80,7 +82,7 @@ object ConfigUtil { UserLevelConfig.getAutocompleteProviderType()?.vscodeSettingString(), debug = isCodyDebugEnabled(), verboseDebug = isCodyVerboseDebugEnabled(), - customConfiguration = getCustomConfiguration(project, customConfigContent), + customConfigurationJson = getCustomConfiguration(project, customConfigContent), ) } @@ -131,22 +133,23 @@ object ConfigUtil { } @JvmStatic - fun getCustomConfiguration(project: Project, customConfigContent: String?): Map { - val settingsProperties = - try { - val text = customConfigContent ?: getSettingsFile(project).readText() - val jsonObj = JsonParser.parseString(text).asJsonObject - jsonObj.keySet().associateWith { jsonObj[it] } - } catch (e: Exception) { - logger.info("No user defined settings file found. Proceeding with empty custom config") - emptyMap() - } + fun getCustomConfiguration(project: Project, customConfigContent: String?): String { // Needed by Edit commands to trigger smart-selection; without it things break. // So it isn't optional in JetBrains clients, which do not offer language-neutral solutions // to this problem; instead we hardwire it to use the indentation-based provider. val additionalProperties = mapOf("cody.experimental.foldingRanges" to "indentation-based") - return settingsProperties + additionalProperties + return try { + val text = customConfigContent ?: getSettingsFile(project).readText() + val config = ConfigFactory.parseString(text).resolve() + additionalProperties.forEach { (key, value) -> + config.withValue(key, ConfigValueFactory.fromAnyRef(value)) + } + config.root().render(ConfigRenderOptions.defaults().setOriginComments(false)) + } catch (e: Exception) { + logger.info("No user defined settings file found. Proceeding with empty custom config") + "" + } } @JvmStatic