Skip to content

Commit

Permalink
vscode-lib: provide hook to adjust configuration (#188)
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: Tested in Cody PR
  • Loading branch information
keegancsmith authored Aug 1, 2024
1 parent 1b597c7 commit 5b39354
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion client/vscode-lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openctx/vscode-lib",
"version": "0.0.16",
"version": "0.0.17",
"description": "OpenCtx library for VS Code extensions",
"license": "Apache-2.0",
"repository": {
Expand Down
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 5b39354

Please sign in to comment.