-
Notifications
You must be signed in to change notification settings - Fork 23
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
Add cody settings editor #1972
Add cody settings editor #1972
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Generated file - DO NOT EDIT MANUALLY | ||
* They are copied from the cody agent project using the copyProtocol gradle task. | ||
* This is only a temporary solution before we fully migrate to generated protocol messages. | ||
*/ | ||
@file:Suppress("FunctionName", "ClassName", "unused", "EnumEntryName", "UnusedImport") | ||
package com.sourcegraph.cody.agent.protocol_generated; | ||
|
||
data class DefinitionParams( | ||
val text: String, | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Generated file - DO NOT EDIT MANUALLY | ||
* They are copied from the cody agent project using the copyProtocol gradle task. | ||
* This is only a temporary solution before we fully migrate to generated protocol messages. | ||
*/ | ||
@file:Suppress("FunctionName", "ClassName", "unused", "EnumEntryName", "UnusedImport") | ||
package com.sourcegraph.cody.agent.protocol_generated; | ||
|
||
data class OwnerParams( | ||
val namespaceName: String, | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Generated file - DO NOT EDIT MANUALLY | ||
* They are copied from the cody agent project using the copyProtocol gradle task. | ||
* This is only a temporary solution before we fully migrate to generated protocol messages. | ||
*/ | ||
@file:Suppress("FunctionName", "ClassName", "unused", "EnumEntryName", "UnusedImport") | ||
package com.sourcegraph.cody.agent.protocol_generated; | ||
|
||
data class Prompt( | ||
val id: String, | ||
val name: String, | ||
val nameWithOwner: String, | ||
val owner: OwnerParams, | ||
val description: String? = null, | ||
val draft: Boolean, | ||
val definition: DefinitionParams, | ||
val url: String, | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Generated file - DO NOT EDIT MANUALLY | ||
* They are copied from the cody agent project using the copyProtocol gradle task. | ||
* This is only a temporary solution before we fully migrate to generated protocol messages. | ||
*/ | ||
@file:Suppress("FunctionName", "ClassName", "unused", "EnumEntryName", "UnusedImport") | ||
package com.sourcegraph.cody.agent.protocol_generated; | ||
|
||
typealias WebviewType = String // One of: sidebar, editor | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.sourcegraph.cody.config | ||
|
||
import com.intellij.openapi.editor.Document | ||
import com.intellij.openapi.fileEditor.FileDocumentManager | ||
import com.intellij.openapi.fileEditor.FileDocumentManagerListener | ||
import com.intellij.openapi.project.Project | ||
import com.sourcegraph.cody.agent.CodyAgentService | ||
import com.sourcegraph.config.ConfigUtil | ||
|
||
class CodySettingsChangeListener(private val project: Project) : FileDocumentManagerListener { | ||
override fun beforeDocumentSaving(document: Document) { | ||
val currentFile = FileDocumentManager.getInstance().getFile(document) | ||
if (currentFile?.toNioPath() == ConfigUtil.getSettingsFile(project)) { | ||
CodyAgentService.getInstance(project).restartAgent(project) | ||
// TODO: we should instead call `extensionConfiguration_didChange` there: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it an issue for Cody repo? |
||
// `it.server.extensionConfiguration_didChange(ConfigUtil.getAgentConfiguration(project, | ||
// document.text))` but it seams that some of the settings changes (like enabling/disabling | ||
// autocomplete) requires agent restart to take effect. | ||
|
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.sourcegraph.cody.config.actions | ||
|
||
import com.intellij.openapi.actionSystem.AnActionEvent | ||
import com.intellij.openapi.diagnostic.Logger | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.vfs.LocalFileSystem | ||
import com.intellij.util.io.write | ||
import com.jetbrains.jsonSchema.JsonSchemaMappingsProjectConfiguration | ||
import com.jetbrains.jsonSchema.UserDefinedJsonSchemaConfiguration | ||
import com.jetbrains.jsonSchema.ide.JsonSchemaService | ||
import com.jetbrains.jsonSchema.impl.JsonSchemaVersion | ||
import com.sourcegraph.cody.agent.CodyAgentService | ||
import com.sourcegraph.common.ui.DumbAwareEDTAction | ||
import com.sourcegraph.config.ConfigUtil | ||
import com.sourcegraph.utils.CodyEditorUtil | ||
import kotlin.io.path.name | ||
|
||
class OpenCodySettingsEditorAction : DumbAwareEDTAction("Open Cody Settings Editor") { | ||
override fun actionPerformed(e: AnActionEvent) { | ||
val project = e.project ?: return | ||
|
||
val settingsVf = | ||
CodyEditorUtil.createFileOrScratchFromUntitled( | ||
project, ConfigUtil.getSettingsFile(project).toString(), content = "{\n \n}") | ||
?: run { | ||
logger.warn("Could not create settings file") | ||
return | ||
} | ||
|
||
CodyEditorUtil.showDocument(project, settingsVf) | ||
|
||
reloadSchemaAsync(project) | ||
} | ||
|
||
private fun reloadSchemaAsync(project: Project) { | ||
CodyAgentService.withAgentRestartIfNeeded(project) { agent -> | ||
val settingsSchema = agent.server.extensionConfiguration_getSettingsSchema(null).get() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so this actions not only opens the file but also fetches the config from the agent and updates the content of the file, is that right? that makes the agent the source of truth at the moment we use this action - I wonder, shouldn't it be the client holding the truth? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. btw, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. My main concern was about persisting the settings b/w the IDE runs. Now I can see that |
||
|
||
val schemaFile = ConfigUtil.getConfigDir(project).resolve("cody_settings.schema.json") | ||
schemaFile.write(settingsSchema) | ||
LocalFileSystem.getInstance().refreshAndFindFileByNioFile(schemaFile) | ||
|
||
val configName = "Cody Settings" | ||
val schemaConfig = | ||
UserDefinedJsonSchemaConfiguration( | ||
configName, | ||
JsonSchemaVersion.SCHEMA_7, | ||
schemaFile.toString(), | ||
/* applicationDefined = */ false, | ||
listOf( | ||
UserDefinedJsonSchemaConfiguration.Item( | ||
"*/${ConfigUtil.getSettingsFile(project).name}", | ||
/* isPattern = */ true, | ||
/* isDirectory = */ false))) | ||
|
||
val schemaMapping = JsonSchemaMappingsProjectConfiguration.getInstance(project) | ||
|
||
schemaMapping.stateMap | ||
.filter { it.value.name == configName } | ||
.forEach { schemaMapping.removeConfiguration(it.value) } | ||
schemaMapping.addConfiguration(schemaConfig) | ||
JsonSchemaService.Impl.get(project).reset() | ||
} | ||
} | ||
|
||
companion object { | ||
private val logger = Logger.getInstance(OpenCodySettingsEditorAction::class.java) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any risk that the restart will happen to often while editing the file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think not, this happen only on Ctrl+S, or if you switch IJ window.