Skip to content

Commit 26396c7

Browse files
committed
get back files used for copilot context generation.
1 parent ad988e8 commit 26396c7

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

Extension/src/LanguageServer/Providers/CopilotHoverProvider.ts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import * as vscode from 'vscode';
66
import { Position, ResponseError } from 'vscode-languageclient';
77
import * as nls from 'vscode-nls';
8-
import { DefaultClient, GetCopilotHoverInfoParams, GetCopilotHoverInfoRequest } from '../client';
8+
import { DefaultClient, GetCopilotHoverInfoParams, GetCopilotHoverInfoRequest, GetCopilotHoverInfoResult } from '../client';
99
import { RequestCancelled, ServerCancelled } from '../protocolFilter';
1010
import { CppSettings } from '../settings';
1111

@@ -92,8 +92,8 @@ export class CopilotHoverProvider implements vscode.HoverProvider {
9292
return this.currentCancellationToken;
9393
}
9494

95-
public async getRequestInfo(document: vscode.TextDocument, position: vscode.Position): Promise<string> {
96-
let requestInfo = "";
95+
public async getRequestInfo(document: vscode.TextDocument, position: vscode.Position): Promise<GetCopilotHoverInfoResult> {
96+
let response: GetCopilotHoverInfoResult;
9797
const params: GetCopilotHoverInfoParams = {
9898
textDocument: { uri: document.uri.toString() },
9999
position: Position.create(position.line, position.character)
@@ -105,26 +105,15 @@ export class CopilotHoverProvider implements vscode.HoverProvider {
105105
}
106106

107107
try {
108-
const response = await this.client.languageClient.sendRequest(GetCopilotHoverInfoRequest, params, this.currentCancellationToken);
109-
requestInfo = response.content;
110-
if (response.files) {
111-
for (const file of response.files) {
112-
const fileUri = vscode.Uri.parse(file);
113-
const token = this.currentCancellationToken ?? new vscode.CancellationTokenSource().token;
114-
if (await vscode.lm.fileIsIgnored(fileUri, token)) {
115-
return "";
116-
}
117-
}
118-
}
119-
108+
response = await this.client.languageClient.sendRequest(GetCopilotHoverInfoRequest, params, this.currentCancellationToken);
120109
} catch (e: any) {
121110
if (e instanceof ResponseError && (e.code === RequestCancelled || e.code === ServerCancelled)) {
122111
throw new vscode.CancellationError();
123112
}
124113
throw e;
125114
}
126115

127-
return requestInfo;
116+
return response;
128117
}
129118

130119
public isCancelled(document: vscode.TextDocument, position: vscode.Position): boolean {

Extension/src/LanguageServer/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ export interface GetCopilotHoverInfoParams {
539539
position: Position;
540540
}
541541

542-
interface GetCopilotHoverInfoResult {
542+
export interface GetCopilotHoverInfoResult {
543543
content: string;
544544
files: string[];
545545
}

Extension/src/LanguageServer/extension.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import * as StreamZip from 'node-stream-zip';
1111
import * as os from 'os';
1212
import * as path from 'path';
1313
import * as vscode from 'vscode';
14-
import { Range } from 'vscode-languageclient';
14+
import { CancellationToken, Range } from 'vscode-languageclient';
1515
import * as nls from 'vscode-nls';
1616
import { TargetPopulation } from 'vscode-tas-client';
1717
import * as which from 'which';
@@ -1430,7 +1430,17 @@ async function onCopilotHover(): Promise<void> {
14301430

14311431
// Gather the content for the query from the client.
14321432
const requestInfo = await copilotHoverProvider.getRequestInfo(hoverDocument, hoverPosition);
1433-
if (requestInfo.length === 0) {
1433+
for (const file of requestInfo.files) {
1434+
// TODO: make uri from file string.
1435+
const fileUri = vscode.Uri.file(file);
1436+
if (await vscodelm.fileIsIgnored(fileUri, copilotHoverProvider.getCurrentHoverCancellationToken() ?? CancellationToken.None)) {
1437+
// Context is not available for this file.
1438+
telemetry.logLanguageServerEvent("CopilotHover", { "Message": "Copilot summary is not available for this file." });
1439+
await showCopilotContent(copilotHoverProvider, hoverDocument, hoverPosition, localize("copilot.hover.unavailable", "Copilot summary is not available for this file."));
1440+
return;
1441+
}
1442+
}
1443+
if (requestInfo.content.length === 0) {
14341444
// Context is not available for this symbol.
14351445
telemetry.logLanguageServerEvent("CopilotHover", { "Message": "Copilot summary is not available for this symbol." });
14361446
await showCopilotContent(copilotHoverProvider, hoverDocument, hoverPosition, localize("copilot.hover.unavailable", "Copilot summary is not available for this symbol."));

0 commit comments

Comments
 (0)