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 globalStorage/didChange agent endpoint #5795

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion agent/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,8 @@ export class Agent extends MessageHandler implements ExtensionClient {
case 'server-managed':
return AgentGlobalState.initialize(
clientInfo.name,
clientInfo.globalStateDir ?? codyPaths().data
clientInfo.globalStateDir ?? codyPaths().data,
this
)
case 'client-managed':
throw new Error('client-managed global state is not supported')
Expand Down
13 changes: 9 additions & 4 deletions agent/src/global-state/AgentGlobalState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import * as vscode_shim from '../vscode-shim'
import path from 'node:path'
import { localStorage } from '../../../vscode/src/services/LocalStorageProvider'
import migrate from './migrations/migrate'
import type {MessageHandler} from "../../../vscode/src/jsonrpc/jsonrpc";

type GlobalStateManager = 'client' | 'server'

export class AgentGlobalState implements vscode.Memento {
private db: DB

static async initialize(ide: string, dir?: string): Promise<AgentGlobalState> {
const globalState = new AgentGlobalState(ide, dir ? 'server' : 'client', dir)
static async initialize(ide: string, dir?: string, agent?: MessageHandler,): Promise<AgentGlobalState> {
const globalState = new AgentGlobalState(ide, dir ? 'server' : 'client', dir, agent)
if (globalState.db instanceof LocalStorageDB) {
await migrate(globalState)
}
Expand All @@ -23,7 +24,8 @@ export class AgentGlobalState implements vscode.Memento {
private constructor(
ide: string,
private manager: GlobalStateManager,
dir?: string
dir?: string,
private agent?: MessageHandler
) {
// If not provided, will default to an in-memory database
if (dir) {
Expand All @@ -40,8 +42,11 @@ export class AgentGlobalState implements vscode.Memento {
}
}

private set(key: string, value: any): void {
private set(key: string, value: any) {
this.db.set(key, value)
if (this.agent) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not do it this way. VSCode globalState is shared, and there's no notifications when other agents are editing it. We should build the notification we need at the semantic level in the extension and use that, instead of exciting some action every time global state changes.

What specifically are we using this for on the JetBrains side?

this.agent.notify('globalStorage/didChange', { key, value: JSON.stringify(value) })
}
}

public reset(): void {
Expand Down
5 changes: 5 additions & 0 deletions vscode/src/jsonrpc/agent-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,11 @@ export type ServerNotifications = {
'window/didChangeContext': [{ key: string; value?: string | undefined | null }]
// Client should move the focus to the sidebar.
'window/focusSidebar': [null]

'globalStorage/didChange': [{
key: string;
value: string
}, null];
}

export interface WebviewCreateWebviewPanelOptions {
Expand Down
Loading