From 95792a915306f3ca1e5589f5933afccfc3319261 Mon Sep 17 00:00:00 2001 From: Remi Schnekenburger Date: Tue, 29 Oct 2024 11:53:59 +0100 Subject: [PATCH] Support proposed API registerMappedEditsProvider2 introduced in vscode 1.94 (#14276) fixes #14268 contributed on behalf of STMicroelectronics Signed-off-by: Remi Schnekenburger --- CHANGELOG.md | 3 +- .../plugin-ext/src/plugin/plugin-context.ts | 4 ++ .../theia.proposed.mappedEditsProvider.d.ts | 49 +++++++++++++++++-- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99e54c9ab7e01..48fb012e3732e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,10 @@ - [Previous Changelogs](https://github.com/eclipse-theia/theia/tree/master/doc/changelogs/) -## 1.55.0 - not yet release +## 1.55.0 - not yet released - [application-package] feat: provide an application prop to set the configuration area [#14319](https://github.com/eclipse-theia/theia/pull/14319) - Contributed on behalf of STMicroelectronics +- [plugin] supported MappedEditProviders proposed API evolution [#14276](https://github.com/eclipse-theia/theia/pull/14276) - Contributed on behalf of STMicroelectronics ## 1.54.0 - 09/26/2024 diff --git a/packages/plugin-ext/src/plugin/plugin-context.ts b/packages/plugin-ext/src/plugin/plugin-context.ts index e027b45d6b84c..be2db8d020a8c 100644 --- a/packages/plugin-ext/src/plugin/plugin-context.ts +++ b/packages/plugin-ext/src/plugin/plugin-context.ts @@ -1304,6 +1304,10 @@ export function createAPIFactory( registerMappedEditsProvider(documentSelector: theia.DocumentSelector, provider: theia.MappedEditsProvider): Disposable { return Disposable.NULL; }, + /** @stubbed MappedEditsProvider */ + registerMappedEditsProvider2(provider: theia.MappedEditsProvider2) { + return Disposable.NULL; + }, /** @stubbed ChatRequestHandler */ createChatParticipant(id: string, handler: theia.ChatRequestHandler): theia.ChatParticipant { return { diff --git a/packages/plugin/src/theia.proposed.mappedEditsProvider.d.ts b/packages/plugin/src/theia.proposed.mappedEditsProvider.d.ts index cedc13e167e6b..5ed4a121bc80d 100644 --- a/packages/plugin/src/theia.proposed.mappedEditsProvider.d.ts +++ b/packages/plugin/src/theia.proposed.mappedEditsProvider.d.ts @@ -27,8 +27,24 @@ export module '@theia/plugin' { readonly ranges: Range[]; } + export interface ConversationRequest { + readonly type: 'request'; + readonly message: string; + } + + export interface ConversationResponse { + readonly type: 'response'; + readonly message: string; + readonly references?: DocumentContextItem[]; + } + export interface MappedEditsContext { - documents: DocumentContextItem[][]; + readonly documents: DocumentContextItem[][]; + /** + * The conversation that led to the current code block(s). + * The last conversation part contains the code block(s) for which the code mapper should provide edits. + */ + readonly conversation?: (ConversationRequest | ConversationResponse)[]; } /** @@ -38,9 +54,8 @@ export module '@theia/plugin' { /** * Provide mapped edits for a given document. * @param document The document to provide mapped edits for. - * @param codeBlocks Code blocks that come from an LLM's reply. - * "Insert at cursor" in the panel chat only sends one edit that the user clicks on, but inline chat can send multiple blocks - * and let the lang server decide what to do with them. + * @param codeBlocks Code blocks that come from an LLM's reply. "Apply in Editor" in the panel chat only sends one edit that the user clicks on, but inline chat can send + * multiple blocks and let the lang server decide what to do with them. * @param context The context for providing mapped edits. * @param token A cancellation token. * @returns A provider result of text edits. @@ -53,7 +68,33 @@ export module '@theia/plugin' { ): ProviderResult; } + export interface MappedEditsRequest { + readonly codeBlocks: { code: string; resource: Uri }[]; + // for every prior response that contains codeblocks, make sure we pass the code as well as the resources based on the reported codemapper URIs + readonly conversation: (ConversationRequest | ConversationResponse)[]; + } + + export interface MappedEditsResponseStream { + textEdit(target: Uri, edits: TextEdit | TextEdit[]): void; + } + + export interface MappedEditsResult { + readonly errorMessage?: string; + } + + /** + * Interface for providing mapped edits for a given document. + */ + export interface MappedEditsProvider2 { + provideMappedEdits( + request: MappedEditsRequest, + result: MappedEditsResponseStream, + token: CancellationToken + ): ProviderResult; + } + export namespace chat { export function registerMappedEditsProvider(documentSelector: DocumentSelector, provider: MappedEditsProvider): Disposable; + export function registerMappedEditsProvider2(provider: MappedEditsProvider2): Disposable; } }