Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/chatSessions/copilotcli/node/todoSqlQuery.ts
13405 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { join } from 'path';
7
import { WorkerWithRpcProxy, type RpcProxy } from '../../../../util/node/worker';
8
import type { TodoItem, TodoSqlWorkerApi } from './copilotCLITodoWorker';
9
10
const DATABASE_FILENAME = 'session.db';
11
12
/**
13
* Queries the session SQLite database for todo items using a worker thread
14
* to avoid blocking the extension host with synchronous I/O.
15
*
16
* The worker is created lazily on first use and reused for subsequent queries.
17
* Call {@link dispose} to terminate the worker when no longer needed.
18
*/
19
export class TodoSqlQuery {
20
private _worker: WorkerWithRpcProxy<TodoSqlWorkerApi> | undefined;
21
private _proxy: RpcProxy<TodoSqlWorkerApi> | undefined;
22
23
private ensureWorker(): RpcProxy<TodoSqlWorkerApi> {
24
if (!this._proxy) {
25
this._worker = new WorkerWithRpcProxy<TodoSqlWorkerApi>(
26
join(__dirname, 'copilotCLITodoWorker.js')
27
);
28
this._proxy = this._worker.proxy;
29
}
30
return this._proxy;
31
}
32
33
/**
34
* Query todos from the session database.
35
* @param sessionDir - The session state directory (e.g. ~/.copilot/session-state/{session-id})
36
* @returns Array of todo items, or empty array if database or table doesn't exist
37
*/
38
async queryTodos(sessionDir: string): Promise<TodoItem[]> {
39
const dbPath = join(sessionDir, DATABASE_FILENAME);
40
const proxy = this.ensureWorker();
41
return proxy.queryTodos(dbPath);
42
}
43
44
dispose(): void {
45
this._worker?.terminate();
46
this._worker = undefined;
47
this._proxy = undefined;
48
}
49
}
50
51
export type { TodoItem };
52
53