Skip to content

Add Copilot Usage Statistics Feature with gS as default keymap #1677

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

Merged
merged 7 commits into from
Jun 24, 2025

Conversation

bassamsdata
Copy link
Contributor

@bassamsdata bassamsdata commented Jun 20, 2025

Description

This PR adds a feature to display GitHub Copilot usage statistics, similar to what's available in VSCode, JetBrains IDEs, and other editors. Users can now check their quota usage directly within CodeCompanion without switching to other tools or waiting an email from GitHub (when requesting usage data).

Note: Premium interactions quota applies to all models except gpt-4.1 and gpt-4o.

Usage

Press gS in any Copilot chat buffer to display a centered floating window showing:

  • Premium interactions usage with percentage and color coding
  • Chat quota status (those added for users uses free copilot)
  • Completions quota status (those added for users uses free copilot)

Usage above 80% is highlighted in red (Error), below 80% in green (MoreMsg).

Implementation Changes

Existing Code Changes

  • UI enhancement: Added row="center" and col="center" support to create_float() for window centering
  • Neovim 0.11 compatibility: Added winborder option support to respect user's border preferences (inspired by mini.nvim)

If this doesn't fit the core, that's completely fine. Happy to maintain it as a separate extension.
However, I feel it’s essential now, especially since they’ve started counting premium requests. :(

Related Issue(s)

This PR is related to the discussion in #1667. Instead of calculating usages locally, it’s better to rely on GitHub for that, as I believe this is essential now, and I haven’t seen any Neovim plugin implement it yet.

Notes:

I’m thinking of adding the Neovim version to the header tomorrow.
Also, I believe the reset date should be added now after adding the vscode screenshot.

Screenshots

Screenshot 2025-06-20 at 10 28 41 AM

in Vscode:
Screenshot 2025-06-20 at 1 00 34 AM

Checklist

  • I've read the contributing guidelines and have adhered to them in this PR
  • I've updated CodeCompanion.has in the init.lua file for my new feature
  • I've added test coverage for this fix/feature
  • I've updated the README and/or relevant docs pages
  • I've run make all to ensure docs are generated, tests pass and my formatting is applied

@Copilot Copilot AI review requested due to automatic review settings June 20, 2025 05:07
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new Copilot usage statistics feature, allowing users to view their Copilot quota usage directly from a centered floating window. Key changes include:

  • Added tests to verify correct calculation of usage percentages and proper highlight color selection.
  • Enhanced the UI floating window creation to support "center" positioning.
  • Introduced a new keymap ("gS") and associated adapter functions to display Copilot usage statistics.
  • Updated documentation to reflect the new feature and keymap.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/adapters/test_copilot.lua Added unit tests for verifying Copilot usage and highlight calculations.
lua/codecompanion/utils/ui.lua Improved create_float to support centered positioning.
lua/codecompanion/strategies/chat/keymaps.lua Added keymap and callback for displaying Copilot stats.
lua/codecompanion/config.lua Configured the new keymap and updated callback reference.
lua/codecompanion/adapters/copilot.lua Added functions to fetch and present Copilot usage statistics.
doc/usage/chat-buffer/index.md Updated keymap documentation to include the new "gS" mapping.
doc/codecompanion.txt Updated documentation with new version and keymap details (encoding issues observed).

@@ -1947,7 +1947,7 @@ The fastest way to copy an LLM’s code output is with `gy`. This will yank the
nearest codeblock.


APPLYING AN LLMS EDITS TO A BUFFER OR FILE ~
APPLYING AN LLM€�S EDITS TO A BUFFER OR FILE ~
Copy link
Preview

Copilot AI Jun 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The apostrophe in this line appears to be replaced with a corrupted character sequence. Please ensure that the encoding is corrected to use a standard apostrophe (’).

Suggested change
APPLYING AN LLM��S EDITS TO A BUFFER OR FILE ~
APPLYING AN LLMS EDITS TO A BUFFER OR FILE ~

Copilot uses AI. Check for mistakes.

@@ -3139,7 +3140,7 @@ OpenAI adapter.
as a great reference to understand how they’re working with the output of the
API

OPENAIS API OUTPUT
OPENAI€�S API OUTPUT
Copy link
Preview

Copilot AI Jun 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The apostrophe in this line seems to have been corrupted. Please replace the invalid characters with a standard apostrophe (’).

Suggested change
OPENAI��S API OUTPUT
OPENAIS API OUTPUT

Copilot uses AI. Check for mistakes.

@jinzhongjia
Copy link
Contributor

Great, this feature is important, which prompts me that my advanced request has been used 1/3

@arnm
Copy link

arnm commented Jun 22, 2025

@bassamsdata I pulled your branch and everything seems to be working great! excited for this to get in 👍

@olimorris
Copy link
Owner

Ahhh man does this mean we've all reached our Copilot Premium Interactions quotas at the same time 😆?!

@olimorris
Copy link
Owner

This is yet another absolute killer PR, @bassamsdata! CodeCompanion owes you a lot ❤️

@olimorris olimorris merged commit 8602a50 into olimorris:main Jun 24, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants