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

Send cody custom config as json, add support for dotted names #2552

Merged
merged 2 commits into from
Nov 1, 2024
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: 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 @@ -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
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
Loading