Skip to content

Commit

Permalink
Send cody custom config as json, add support for dotted names (#2552)
Browse files Browse the repository at this point in the history
## Changes:

See: sourcegraph/cody#6027

## Test plan

See: sourcegraph/cody#6027
  • Loading branch information
pkukielka authored Nov 1, 2024
1 parent 6cac3bd commit d21db31
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 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
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ org.gradle.jvmargs=-Xmx4g -Xms500m
nodeBinaries.commit=8755ae4c05fd476cd23f2972049111ba436c86d4
nodeBinaries.version=v20.12.2
cody.autocomplete.enableFormatting=true
cody.commit=23af99f690659084d820461a73a6fb094e52e998
cody.commit=5dccf8dc97191083cc3fe2209b11edb0ebea0017
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 d21db31

Please sign in to comment.