Skip to content

Commit

Permalink
Get settings schema endpoint (#5080)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
pkukielka authored Aug 5, 2024
1 parent f3b71ab commit 066d9c6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ interface CodyAgentServer {
fun extensionConfiguration_change(params: ExtensionConfiguration): CompletableFuture<AuthStatus?>
@JsonRequest("extensionConfiguration/status")
fun extensionConfiguration_status(params: Null?): CompletableFuture<AuthStatus?>
@JsonRequest("extensionConfiguration/getSettingsSchema")
fun extensionConfiguration_getSettingsSchema(params: Null?): CompletableFuture<String>
@JsonRequest("textDocument/change")
fun textDocument_change(params: ProtocolTextDocument): CompletableFuture<TextDocument_ChangeResult>
@JsonRequest("attribution/search")
Expand Down
12 changes: 12 additions & 0 deletions agent/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { Polly, Request } from '@pollyjs/core'
import { type CodyCommand, ModelUsage, isWindows, telemetryRecorder } from '@sourcegraph/cody-shared'
import * as vscode from 'vscode'
import { StreamMessageReader, StreamMessageWriter, createMessageConnection } from 'vscode-jsonrpc/node'
import packageJson from '../../vscode/package.json'

import {
type AuthStatus,
Expand Down Expand Up @@ -506,6 +507,17 @@ export class Agent extends MessageHandler implements ExtensionClient {
return result ?? null
})

this.registerRequest('extensionConfiguration/getSettingsSchema', async () => {
return JSON.stringify({
$schema: 'http://json-schema.org/draft-07/schema#',
title: 'Schema for Cody settings in the Cody VSCode Extension.',
description: 'This prevents invalid Cody specific configuration in the settings file.',
type: 'object',
allOf: [{ $ref: 'https://json.schemastore.org/package' }],
properties: packageJson.contributes.configuration.properties,
})
})

this.registerNotification('progress/cancel', ({ id }) => {
const token = vscode_shim.progressBars.get(id)
if (token) {
Expand Down
3 changes: 3 additions & 0 deletions vscode/src/jsonrpc/agent-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ export type ClientRequests = {
// Returns the current authentication status without making changes to it.
'extensionConfiguration/status': [null, AuthStatus | null]

// Returns the json schema of the extension confi
'extensionConfiguration/getSettingsSchema': [null, string]

'textDocument/change': [ProtocolTextDocument, { success: boolean }]

// Run attribution search for a code snippet displayed in chat.
Expand Down

0 comments on commit 066d9c6

Please sign in to comment.