diff --git a/Extension/src/LanguageServer/Providers/CopilotHoverProvider.ts b/Extension/src/LanguageServer/Providers/CopilotHoverProvider.ts index 4ac4d9f830..0d56c069e6 100644 --- a/Extension/src/LanguageServer/Providers/CopilotHoverProvider.ts +++ b/Extension/src/LanguageServer/Providers/CopilotHoverProvider.ts @@ -88,6 +88,10 @@ export class CopilotHoverProvider implements vscode.HoverProvider { return this.currentPosition; } + public getCurrentHoverCancellationToken(): vscode.CancellationToken | undefined { + return this.currentCancellationToken; + } + public async getRequestInfo(document: vscode.TextDocument, position: vscode.Position): Promise { let requestInfo = ""; const params: GetCopilotHoverInfoParams = { @@ -124,7 +128,7 @@ export class CopilotHoverProvider implements vscode.HoverProvider { return false; } - private reset(): void { + public reset(): void { // If there was a previous call, cancel it. if (this.waiting) { this.cancelled = true; diff --git a/Extension/src/LanguageServer/extension.ts b/Extension/src/LanguageServer/extension.ts index 952ac4ef21..78cc87c367 100644 --- a/Extension/src/LanguageServer/extension.ts +++ b/Extension/src/LanguageServer/extension.ts @@ -1443,7 +1443,7 @@ async function onCopilotHover(): Promise { chatResponse = await model.sendRequest( messages, {}, - new vscode.CancellationTokenSource().token + copilotHoverProvider.getCurrentHoverCancellationToken() ); } catch (err) { if (err instanceof vscode.LanguageModelError) { @@ -1484,7 +1484,8 @@ async function showCopilotContent(copilotHoverProvider: CopilotHoverProvider, ho // Check if the cursor has been manually moved by the user. If so, exit. const currentCursorPosition = vscode.window.activeTextEditor?.selection.active; if (!currentCursorPosition?.isEqual(hoverPosition)) { - return false; + // Reset implies cancellation, but we need to ensure cancellation is acknowledged before returning. + copilotHoverProvider.reset(); } if (copilotHoverProvider.isCancelled(hoverDocument, hoverPosition)) {