Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/prompt/node/todoListContextProvider.ts
13399 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 { createServiceIdentifier } from '../../../util/common/services';
7
import { CancellationToken } from '../../../util/vs/base/common/cancellation';
8
import { LanguageModelTextPart } from '../../../vscodeTypes';
9
import { ToolName } from '../../tools/common/toolNames';
10
import { IToolsService } from '../../tools/common/toolsService';
11
12
export const ITodoListContextProvider = createServiceIdentifier<ITodoListContextProvider>('ITodoListContextProvider');
13
export interface ITodoListContextProvider {
14
getCurrentTodoContext(sessionResource: string): Promise<string | undefined>;
15
}
16
17
export class TodoListContextProvider implements ITodoListContextProvider {
18
constructor(
19
@IToolsService private readonly toolsService: IToolsService,
20
) { }
21
22
async getCurrentTodoContext(sessionResource: string): Promise<string | undefined> {
23
try {
24
const result = await this.toolsService.invokeTool(
25
ToolName.CoreManageTodoList,
26
{
27
input: { operation: 'read', chatSessionResource: sessionResource }
28
} as any,
29
CancellationToken.None
30
);
31
32
if (!result || !result.content) {
33
return undefined;
34
}
35
36
const todoList = result.content
37
.filter((part): part is LanguageModelTextPart => part instanceof LanguageModelTextPart)
38
.map(part => part.value)
39
.join('\n');
40
41
if (!todoList.trim() || todoList === 'No todo list found.') {
42
return undefined;
43
}
44
45
return todoList;
46
} catch (error) {
47
return undefined;
48
}
49
}
50
}
51
52