Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Content Exclusion for Copilot Hover #13143

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@
"Snippets"
],
"enabledApiProposals": [
"terminalDataWriteEvent"
"terminalDataWriteEvent",
"chatVariableResolver",
spebl marked this conversation as resolved.
Show resolved Hide resolved
"chatParticipantPrivate",
"chatParticipantAdditions"
],
"capabilities": {
"untrustedWorkspaces": {
Expand Down
11 changes: 5 additions & 6 deletions Extension/src/LanguageServer/Providers/CopilotHoverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import * as vscode from 'vscode';
import { Position, ResponseError } from 'vscode-languageclient';
import * as nls from 'vscode-nls';
import { DefaultClient, GetCopilotHoverInfoParams, GetCopilotHoverInfoRequest } from '../client';
import { DefaultClient, GetCopilotHoverInfoParams, GetCopilotHoverInfoRequest, GetCopilotHoverInfoResult } from '../client';
import { RequestCancelled, ServerCancelled } from '../protocolFilter';
import { CppSettings } from '../settings';

Expand Down Expand Up @@ -92,8 +92,8 @@ export class CopilotHoverProvider implements vscode.HoverProvider {
return this.currentCancellationToken;
}

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

try {
const response = await this.client.languageClient.sendRequest(GetCopilotHoverInfoRequest, params, this.currentCancellationToken);
requestInfo = response.content;
response = await this.client.languageClient.sendRequest(GetCopilotHoverInfoRequest, params, this.currentCancellationToken);
} catch (e: any) {
if (e instanceof ResponseError && (e.code === RequestCancelled || e.code === ServerCancelled)) {
throw new vscode.CancellationError();
}
throw e;
}

return requestInfo;
return response;
}

public isCancelled(document: vscode.TextDocument, position: vscode.Position): boolean {
Expand Down
3 changes: 2 additions & 1 deletion Extension/src/LanguageServer/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,9 @@ export interface GetCopilotHoverInfoParams {
position: Position;
}

interface GetCopilotHoverInfoResult {
export interface GetCopilotHoverInfoResult {
content: string;
files: string[];
}

export interface ChatContextResult {
Expand Down
18 changes: 14 additions & 4 deletions Extension/src/LanguageServer/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as StreamZip from 'node-stream-zip';
import * as os from 'os';
import * as path from 'path';
import * as vscode from 'vscode';
import { Range } from 'vscode-languageclient';
import { CancellationToken, Range } from 'vscode-languageclient';
import * as nls from 'vscode-nls';
import { TargetPopulation } from 'vscode-tas-client';
import * as which from 'which';
Expand Down Expand Up @@ -1430,18 +1430,28 @@ async function onCopilotHover(): Promise<void> {

// Gather the content for the query from the client.
const requestInfo = await copilotHoverProvider.getRequestInfo(hoverDocument, hoverPosition);
if (requestInfo.length === 0) {
for (const file of requestInfo.files) {
const fileUri = vscode.Uri.file(file);
if (await vscodelm.fileIsIgnored(fileUri, copilotHoverProvider.getCurrentHoverCancellationToken() ?? CancellationToken.None)) {
spebl marked this conversation as resolved.
Show resolved Hide resolved
// Context is not available for this file.
telemetry.logLanguageServerEvent("CopilotHover", { "Message": "Copilot summary is not available for definition or declaration." });
spebl marked this conversation as resolved.
Show resolved Hide resolved
await showCopilotContent(copilotHoverProvider, hoverDocument, hoverPosition, localize("copilot.hover.unavailable", "Copilot summary is not available.") + "\n\n" +
localize("copilot.hover.excluded", "The file containing this symbol's defintion or declaration has been excluded from use with Copilot."));
spebl marked this conversation as resolved.
Show resolved Hide resolved
return;
}
}
if (requestInfo.content.length === 0) {
// Context is not available for this symbol.
telemetry.logLanguageServerEvent("CopilotHover", { "Message": "Copilot summary is not available for this symbol." });
await showCopilotContent(copilotHoverProvider, hoverDocument, hoverPosition, localize("copilot.hover.unavailable", "Copilot summary is not available for this symbol."));
await showCopilotContent(copilotHoverProvider, hoverDocument, hoverPosition, localize("copilot.hover.unavailable.symbol", "Copilot summary is not available for this symbol."));
return;
}

const locale = getLocaleId();

const messages = [
vscode.LanguageModelChatMessage
.User(requestInfo + locale)];
.User(requestInfo.content + locale)];

const [model] = await vscodelm.selectChatModels(modelSelector);

Expand Down
Loading