Skip to content

Commit

Permalink
Support proposed API registerMappedEditsProvider2 introduced in vscod…
Browse files Browse the repository at this point in the history
…e 1.94

fixes #14268

contributed on behalf of STMicroelectronics

Signed-off-by: Remi Schnekenburger <[email protected]>
  • Loading branch information
rschnekenbu committed Oct 9, 2024
1 parent 6b7ceb7 commit f842af9
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

- [Previous Changelogs](https://github.com/eclipse-theia/theia/tree/master/doc/changelogs/)

## 1.55.0 - not yet released

- [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

- [ai] add Theia AI LLM Support [Experimental] [#14048](https://github.com/eclipse-theia/theia/pull/14048)
Expand Down
4 changes: 4 additions & 0 deletions packages/plugin-ext/src/plugin/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,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 {
Expand Down
49 changes: 45 additions & 4 deletions packages/plugin/src/theia.proposed.mappedEditsProvider.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)[];
}

/**
Expand All @@ -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.
Expand All @@ -53,7 +68,33 @@ export module '@theia/plugin' {
): ProviderResult<WorkspaceEdit | null>;
}

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<MappedEditsResult>;
}

export namespace chat {
export function registerMappedEditsProvider(documentSelector: DocumentSelector, provider: MappedEditsProvider): Disposable;
export function registerMappedEditsProvider2(provider: MappedEditsProvider2): Disposable;
}
}

0 comments on commit f842af9

Please sign in to comment.