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

Add check for copilot access before providing copilot hover #13238

Merged
merged 2 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 18 additions & 0 deletions Extension/src/LanguageServer/Providers/CopilotHoverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import * as vscode from 'vscode';
import { Position, ResponseError } from 'vscode-languageclient';
import * as nls from 'vscode-nls';
import { modelSelector } from '../../constants';
import * as telemetry from '../../telemetry';
import { DefaultClient, GetCopilotHoverInfoParams, GetCopilotHoverInfoRequest, GetCopilotHoverInfoResult } from '../client';
import { RequestCancelled, ServerCancelled } from '../protocolFilter';
import { CppSettings } from '../settings';
Expand Down Expand Up @@ -35,6 +37,22 @@ export class CopilotHoverProvider implements vscode.HoverProvider {
return undefined;
}

// Ensure the user has access to Copilot.
const vscodelm = (vscode as any).lm;
if (vscodelm) {
const [model] = await vscodelm.selectChatModels(modelSelector);
if (!model) {
return undefined;
}
}

if (settings.copilotHover === "default") {
// Check flight to make sure the feature is enabled.
if (!await telemetry.isFlightEnabled("CppCopilotHover")) {
return undefined;
}
}

const newHover = this.isNewHover(document, position);
if (newHover) {
this.reset();
Expand Down
3 changes: 1 addition & 2 deletions Extension/src/LanguageServer/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1316,8 +1316,7 @@ export class DefaultClient implements Client {

const settings: CppSettings = new CppSettings();
this.currentCopilotHoverEnabled = new PersistentWorkspaceState<string>("cpp.copilotHover", settings.copilotHover);
if (settings.copilotHover === "enabled" ||
(settings.copilotHover === "default" && await telemetry.isFlightEnabled("CppCopilotHover"))) {
if (settings.copilotHover !== "disabled") {
this.copilotHoverProvider = new CopilotHoverProvider(this);
this.disposables.push(vscode.languages.registerHoverProvider(util.documentSelector, this.copilotHoverProvider));
}
Expand Down
4 changes: 2 additions & 2 deletions Extension/src/LanguageServer/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1469,10 +1469,10 @@ async function onCopilotHover(): Promise<void> {
vscode.LanguageModelChatMessage
.User(requestInfo.content + locale)];

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

let chatResponse: vscode.LanguageModelChatResponse | undefined;
try {
const [model] = await vscodelm.selectChatModels(modelSelector);

chatResponse = await model.sendRequest(
messages,
{},
Expand Down