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

Add cody settings editor #1972

Merged
merged 5 commits into from
Aug 5, 2024
Merged

Conversation

pkukielka
Copy link
Contributor

@pkukielka pkukielka commented Aug 1, 2024

Fixes CODY-1310

Changes

This PR adds cody settings editor with schema validation and code completion.

image
image
image

Test plan

  1. Build this PR with CODY_DIR set to this PR branch.
  2. Run action Open Cody Settings Editor (you can use shift shift to find it)
  3. Change some Cody settings. E.g. you can try to disable autocomplete:
    "cody.autocomplete.enabled": true
  4. Hit Ctrl + S to trigger the config update
  5. Try to use autocomplete in some other file and make sure it does not work.
  6. Revert your changes and make sure autocomplete is enabled again.

@pkukielka pkukielka changed the title Pkukielka/add cody settings editor Add cody settings editor Aug 1, 2024
import com.sourcegraph.config.ConfigUtil

class CodySettingsChangeListener(private val project: Project) : FileDocumentManagerListener {
override fun beforeDocumentSaving(document: Document) {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it an issue for Cody repo?

Comment on lines 22 to 25
?: run {
logger.warn("Project cannot be null")
return
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can log it but it looks like a common practice is to simply ?: return (see our other actions and actions in IntelliJ)

Comment on lines 51 to 56
configName,
JsonSchemaVersion.SCHEMA_7,
schemaFile.toString(),
false,
listOf(
UserDefinedJsonSchemaConfiguration.Item(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you name the params?


private fun reloadSchemaAsync(project: Project) {
CodyAgentService.withAgentRestartIfNeeded(project) { agent ->
val settingsSchema = agent.server.extensionConfiguration_getSettingsSchema(null).get()
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, extensionConfiguration_getSettingsSchema always takes null, why is that? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder, shouldn't it be the client holding the truth?
I do not think so, and I'm not sure how that would be supposed to work?
After all it's VSC code which knows which settings are used, etc.
Keeping it in client would be artificial, and would also need to be duplicated for every client.

Copy link
Contributor

Choose a reason for hiding this comment

The 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 ConfigUtil::getAgentConfiguration handles the initialization properly on the startup - all good 👍

Copy link
Contributor

@mkondratek mkondratek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably I missed it but how do we notify the agent about the initial settings on IDE and plugin start up?

@mkondratek
Copy link
Contributor

I be just started the IDE with your changes and got this:

java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: org.eclipse.lsp4j.jsonrpc.ResponseErrorException: codeActions/provide: document not found for file:///Users/mkondratek/runIdeProjects/jetbrains/.idea/.sourcegraph/cody_settings.json

Error: codeActions/provide: document not found for file:///Users/mkondratek/runIdeProjects/jetbrains/.idea/.sourcegraph/cody_settings.json
    at /Users/mkondratek/IdeaProjects/jetbrains/build/sourcegraph/agent/index.js:137245:19
    at /Users/mkondratek/IdeaProjects/jetbrains/build/sourcegraph/agent/index.js:138156:18
    at runNextTicks (node:internal/process/task_queues:60:5)
    at process.processImmediate (node:internal/timers:449:9)
    at process.topLevelDomainCallback (node:domain:160:15)
    at process.callbackTrampoline (node:internal/async_hooks:128:24)
    at async /Users/mkondratek/IdeaProjects/jetbrains/build/sourcegraph/agent/index.js:136782:44
	at com.intellij.util.ExceptionUtil.rethrow(ExceptionUtil.java:132)
	at com.intellij.openapi.progress.util.ProgressIndicatorUtils.awaitWithCheckCanceled(ProgressIndicatorUtils.java:376)
	at com.sourcegraph.cody.inspections.CodyFixHighlightPass.doCollectInformation(CodyFixHighlightPass.kt:89)
	at com.intellij.codeHighlighting.TextEditorHighlightingPass.collectInformation(TextEditorHighlightingPass.java:56)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$1(PassExecutorService.java:419)
	at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1152)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$2(PassExecutorService.java:412)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$12(CoreProgressManager.java:608)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:683)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:639)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:607)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:60)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.doRun(PassExecutorService.java:411)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$run$0(PassExecutorService.java:387)
	at com.intellij.openapi.application.impl.ReadMostlyRWLock.executeByImpatientReader(ReadMostlyRWLock.java:174)
	at com.intellij.openapi.application.impl.ApplicationImpl.executeByImpatientReader(ApplicationImpl.java:213)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.run(PassExecutorService.java:385)
	at com.intellij.concurrency.JobLauncherImpl$VoidForkJoinTask$1.exec(JobLauncherImpl.java:184)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
Caused by: java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: org.eclipse.lsp4j.jsonrpc.ResponseErrorException: codeActions/provide: document not found for file:///Users/mkondratek/runIdeProjects/jetbrains/.idea/.sourcegraph/cody_settings.json

Error: codeActions/provide: document not found for file:///Users/mkondratek/runIdeProjects/jetbrains/.idea/.sourcegraph/cody_settings.json
    at /Users/mkondratek/IdeaProjects/jetbrains/build/sourcegraph/agent/index.js:137245:19
    at /Users/mkondratek/IdeaProjects/jetbrains/build/sourcegraph/agent/index.js:138156:18
    at runNextTicks (node:internal/process/task_queues:60:5)
    at process.processImmediate (node:internal/timers:449:9)
    at process.topLevelDomainCallback (node:domain:160:15)
    at process.callbackTrampoline (node:internal/async_hooks:128:24)
    at async /Users/mkondratek/IdeaProjects/jetbrains/build/sourcegraph/agent/index.js:136782:44
	at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:395)
	at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2022)
	at com.intellij.openapi.progress.util.ProgressIndicatorUtils.awaitWithCheckCanceled(ProgressIndicatorUtils.java:361)
	... 21 more
Caused by: java.util.concurrent.ExecutionException: org.eclipse.lsp4j.jsonrpc.ResponseErrorException: codeActions/provide: document not found for file:///Users/mkondratek/runIdeProjects/jetbrains/.idea/.sourcegraph/cody_settings.json

Error: codeActions/provide: document not found for file:///Users/mkondratek/runIdeProjects/jetbrains/.idea/.sourcegraph/cody_settings.json
    at /Users/mkondratek/IdeaProjects/jetbrains/build/sourcegraph/agent/index.js:137245:19
    at /Users/mkondratek/IdeaProjects/jetbrains/build/sourcegraph/agent/index.js:138156:18
    at runNextTicks (node:internal/process/task_queues:60:5)
    at process.processImmediate (node:internal/timers:449:9)
    at process.topLevelDomainCallback (node:domain:160:15)
    at process.callbackTrampoline (node:internal/async_hooks:128:24)
    at async /Users/mkondratek/IdeaProjects/jetbrains/build/sourcegraph/agent/index.js:136782:44
	at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:395)
	at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1999)
	at com.sourcegraph.cody.inspections.CodyFixHighlightPass.doCollectInformation$lambda$3(CodyFixHighlightPass.kt:78)
	at com.sourcegraph.cody.agent.CodyAgentService$Companion.withAgent$lambda$2(CodyAgentService.kt:250)
	at com.intellij.openapi.application.impl.ApplicationImpl$1.run(ApplicationImpl.java:295)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:668)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:665)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:665)
	at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: org.eclipse.lsp4j.jsonrpc.ResponseErrorException: codeActions/provide: document not found for file:///Users/mkondratek/runIdeProjects/jetbrains/.idea/.sourcegraph/cody_settings.json

Error: codeActions/provide: document not found for file:///Users/mkondratek/runIdeProjects/jetbrains/.idea/.sourcegraph/cody_settings.json
    at /Users/mkondratek/IdeaProjects/jetbrains/build/sourcegraph/agent/index.js:137245:19
    at /Users/mkondratek/IdeaProjects/jetbrains/build/sourcegraph/agent/index.js:138156:18
    at runNextTicks (node:internal/process/task_queues:60:5)
    at process.processImmediate (node:internal/timers:449:9)
    at process.topLevelDomainCallback (node:domain:160:15)
    at process.callbackTrampoline (node:internal/async_hooks:128:24)
    at async /Users/mkondratek/IdeaProjects/jetbrains/build/sourcegraph/agent/index.js:136782:44
	at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.handleResponse(RemoteEndpoint.java:220)
	at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.consume(RemoteEndpoint.java:204)
	at org.eclipse.lsp4j.jsonrpc.TracingMessageConsumer.consume(TracingMessageConsumer.java:119)
	at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.handleMessage(StreamMessageProducer.java:185)
	at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.listen(StreamMessageProducer.java:97)
	at org.eclipse.lsp4j.jsonrpc.json.ConcurrentMessageProcessor.run(ConcurrentMessageProcessor.java:114)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	... 1 more

(I assume my config json did not exist initially)

@pkukielka
Copy link
Contributor Author

probably I missed it but how do we notify the agent about the initial settings on IDE and plugin start up?

ConfigUtil::getAgentConfiguration which in turn uses ConfigUtil::getCustomConfiguration takes care of that.

pkukielka added a commit to sourcegraph/cody that referenced this pull request Aug 5, 2024
## Changes

This PR adds `extensionConfiguration/getSettingsSchema` endpoint which
generates json schema file useful for validating cody settings and for
documentation purposes.

## Test plan

1. Build Jenkins [PR
#1972](sourcegraph/jetbrains#1972) with CODY_DIR
set to this PR branch.
2. Run action `Open Cody Settings Editor` (you can use `shift shift` to
find it)
3. Change some Cody settings. E.g. you can try to disable autocomplete:
`"cody.autocomplete.enabled": true`
4. Hit `Ctrl + S` to trigger the config update
5. Try to use autocomplete in some other file and make sure it does not
work.
6. Revert your changes and make sure autocomplete is enabled again.
@pkukielka pkukielka force-pushed the pkukielka/add-cody-settings-editor branch from 89101b4 to 283fbd6 Compare August 5, 2024 15:21
@RXminuS RXminuS self-requested a review August 5, 2024 15:59
@pkukielka pkukielka merged commit 8c50dfd into main Aug 5, 2024
6 of 7 checks passed
@pkukielka pkukielka deleted the pkukielka/add-cody-settings-editor branch August 5, 2024 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants