MCPcopy Create free account
hub / github.com/microsoft/vscode-cpptools / onCopilotHover

Function onCopilotHover

Extension/src/LanguageServer/extension.ts:1541–1658  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1539// This uses several workarounds for interacting with the hover feature.
1540// A proposal for dynamic hover content would help, such as the one here (https://github.com/microsoft/vscode/issues/195394)
1541async function onCopilotHover(): Promise<void> {
1542 telemetry.logLanguageServerEvent("CopilotHover");
1543
1544 const vscodelm = util.getVSCodeLanguageModel();
1545 if (!vscodelm) {
1546 return;
1547 }
1548
1549 const copilotHoverProvider = clients.getDefaultClient().getCopilotHoverProvider();
1550 if (!copilotHoverProvider) {
1551 return;
1552 }
1553
1554 const hoverDocument = copilotHoverProvider.getCurrentHoverDocument();
1555 const hoverPosition = copilotHoverProvider.getCurrentHoverPosition();
1556 if (!hoverDocument || !hoverPosition) {
1557 return;
1558 }
1559
1560 // Prep hover with wait message.
1561 copilotHoverProvider.showWaiting();
1562
1563 if (copilotHoverProvider.isCancelled(hoverDocument, hoverPosition)) {
1564 return;
1565 }
1566
1567 // Move the cursor to the hover position, but don't focus the editor.
1568 await vscode.window.showTextDocument(hoverDocument, { preserveFocus: true, selection: new vscode.Selection(hoverPosition, hoverPosition) });
1569
1570 if (!await showCopilotContent(copilotHoverProvider, hoverDocument, hoverPosition)) {
1571 return;
1572 }
1573
1574 // Gather the content for the query from the client.
1575 const requestInfo = await copilotHoverProvider.getRequestInfo(hoverDocument, hoverPosition);
1576 try {
1577 for (const file of requestInfo.files) {
1578 const fileUri = vscode.Uri.file(file);
1579 if (await vscodelm.fileIsIgnored(fileUri, copilotHoverProvider.getCurrentHoverCancellationToken() ?? CancellationToken.None)) {
1580 telemetry.logLanguageServerEvent("CopilotHover", { "Message": "Copilot summary is not available due to content exclusion." });
1581 await showCopilotContent(copilotHoverProvider, hoverDocument, hoverPosition, localize("copilot.hover.unavailable", "Copilot summary is not available.") + "\n\n" +
1582 localize("copilot.hover.excluded", "The file containing this symbol's definition or declaration has been excluded from use with Copilot."));
1583 return;
1584 }
1585 }
1586 } catch (err) {
1587 if (err instanceof Error) {
1588 await reportCopilotFailure(copilotHoverProvider, hoverDocument, hoverPosition, err.name);
1589 }
1590 return;
1591 }
1592 if (requestInfo.content.length === 0) {
1593 // Context is not available for this symbol.
1594 telemetry.logLanguageServerEvent("CopilotHover", { "Message": "Copilot summary is not available for this symbol." });
1595 await showCopilotContent(copilotHoverProvider, hoverDocument, hoverPosition, localize("copilot.hover.unavailable.symbol", "Copilot summary is not available for this symbol."));
1596 return;
1597 }
1598

Callers 1

registerCommandsFunction · 0.85

Calls 12

getLocaleIdFunction · 0.90
showCopilotContentFunction · 0.85
reportCopilotFailureFunction · 0.85
getDefaultClientMethod · 0.80
showWaitingMethod · 0.80
isCancelledMethod · 0.80
getRequestInfoMethod · 0.80

Tested by

no test coverage detected