Skip to content

Commit

Permalink
vscode-lib: provide hook to adjust configuration
Browse files Browse the repository at this point in the history
This allows a client of vscode-lib to change the openctx client
configuration before it is acted upon. We are adding this hook to make
it possible for OpenCtx configuration to be set by the Sourcegraph
instance Cody is connected to.

Test Plan: TODO
  • Loading branch information
keegancsmith committed Jul 31, 2024
1 parent 5d4de66 commit 793c834
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions client/vscode-lib/src/controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
type AuthInfo,
type Client,
type ClientConfiguration,
type ProviderMethodOptions,
type Range,
createClient,
Expand Down Expand Up @@ -56,6 +57,7 @@ export function createController({
getAuthInfo,
features,
providers,
mergeConfiguration,
preloadDelay,
}: {
secrets: Observable<vscode.SecretStorage> | vscode.SecretStorage
Expand All @@ -64,6 +66,7 @@ export function createController({
getAuthInfo?: (secrets: vscode.SecretStorage, providerUri: string) => Promise<AuthInfo | null>
features: { annotations?: boolean; statusBar?: boolean }
providers?: ImportedProviderConfiguration[]
mergeConfiguration?: (configuration: ClientConfiguration) => Promise<ClientConfiguration>
preloadDelay?: number
}): {
controller: Controller
Expand All @@ -87,8 +90,13 @@ export function createController({
)
disposables.push(configOrSecretsChanged)

const getConfiguration = async (scope?: vscode.ConfigurationScope) => {
const config = getClientConfiguration(scope)
return mergeConfiguration ? await mergeConfiguration(config) : config
}

const toggleEnableCommand = vscode.commands.registerCommand('openctx.toggleEnable', async () => {
const currentValue = getClientConfiguration().enable
const currentValue = (await getConfiguration()).enable
await vscode.workspace.getConfiguration('openctx').update('enable', !currentValue)
})
disposables.push(toggleEnableCommand)
Expand All @@ -103,7 +111,7 @@ export function createController({
? vscode.Uri.parse(resource)
: vscode.workspace.workspaceFolders?.[0]?.uri
return observeWorkspaceConfigurationChanges('openctx', scope).pipe(
map(() => getClientConfiguration(scope)),
mergeMap(() => from(getConfiguration(scope))),
)
},
authInfo: getAuthInfo
Expand Down

0 comments on commit 793c834

Please sign in to comment.