Skip to content

Commit

Permalink
Send cody custom config as json, add support for dotted names
Browse files Browse the repository at this point in the history
  • Loading branch information
pkukielka committed Oct 30, 2024
1 parent 7c8278a commit e01bd6e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
29 changes: 16 additions & 13 deletions src/main/kotlin/com/sourcegraph/config/ConfigUtil.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -80,7 +82,7 @@ object ConfigUtil {
UserLevelConfig.getAutocompleteProviderType()?.vscodeSettingString(),
debug = isCodyDebugEnabled(),
verboseDebug = isCodyVerboseDebugEnabled(),
customConfiguration = getCustomConfiguration(project, customConfigContent),
customConfigurationJson = getCustomConfiguration(project, customConfigContent),
)
}

Expand Down Expand Up @@ -131,22 +133,23 @@ object ConfigUtil {
}

@JvmStatic
fun getCustomConfiguration(project: Project, customConfigContent: String?): Map<String, Any> {
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
Expand Down

0 comments on commit e01bd6e

Please sign in to comment.