Skip to content

Commit 204d76e

Browse files
authored
Merge pull request #25 from j4rviscmd/fix/config-stale
fix: make configuration changes take effect immediately
2 parents 85b496f + d39be51 commit 204d76e

2 files changed

Lines changed: 41 additions & 7 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/extension.ts

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,32 @@ interface UsageData {
143143
/** Global state key for storing cached Copilot usage data. */
144144
const CACHE_KEY = "copilotUsage.cache";
145145

146+
/**
147+
* Activates the Copilot Usage extension.
148+
*
149+
* Sets up a status bar item that displays the current GitHub Copilot premium
150+
* request usage percentage. The extension periodically fetches usage data from
151+
* the GitHub Copilot internal API, caches it in global state, and updates the
152+
* status bar display. It also registers commands for toggling the label style,
153+
* adjusting the refresh interval, and switching the display mode between used
154+
* and remaining percentages.
155+
*
156+
* @param context - The VSCode extension context providing access to global state
157+
* and subscription management.
158+
*/
146159
export function activate(context: vscode.ExtensionContext): void {
147-
const config = vscode.workspace.getConfiguration("copilotUsage");
148-
const priority = config.get<number>("statusBarPriority", -1000);
160+
/**
161+
* Retrieves the current Copilot usage configuration.
162+
*
163+
* Re-fetches on every call to avoid stale values after runtime changes.
164+
*
165+
* @returns The current workspace configuration for the "copilotUsage" section.
166+
*/
167+
function getConfig(): vscode.WorkspaceConfiguration {
168+
return vscode.workspace.getConfiguration("copilotUsage");
169+
}
170+
171+
const priority = getConfig().get<number>("statusBarPriority", -1000);
149172

150173
const statusBarItem = vscode.window.createStatusBarItem(
151174
vscode.StatusBarAlignment.Right,
@@ -372,11 +395,16 @@ export function activate(context: vscode.ExtensionContext): void {
372395
* @returns The refresh interval in milliseconds.
373396
*/
374397
function getRefreshInterval(): number {
375-
return config.get<number>("refreshInterval", 60) * 1000;
398+
return getConfig().get<number>("refreshInterval", 60) * 1000;
376399
}
377400

401+
/**
402+
* Retrieves the configured display mode for usage data.
403+
*
404+
* @returns The display mode: "used" shows consumed percentage, "remaining" shows leftover percentage.
405+
*/
378406
function getDisplayMode(): "used" | "remaining" {
379-
return config.get<"used" | "remaining">("displayMode", "used");
407+
return getConfig().get<"used" | "remaining">("displayMode", "used");
380408
}
381409

382410
/**
@@ -385,7 +413,7 @@ export function activate(context: vscode.ExtensionContext): void {
385413
* @returns The label style: "icon" for Copilot icon, "text" for "Copilot" text.
386414
*/
387415
function getLabelStyle(): "icon" | "text" {
388-
return config.get<"icon" | "text">("labelStyle", "icon");
416+
return getConfig().get<"icon" | "text">("labelStyle", "icon");
389417
}
390418

391419
/**
@@ -531,6 +559,12 @@ export function activate(context: vscode.ExtensionContext): void {
531559
);
532560
}
533561

562+
/**
563+
* Deactivates the Copilot Usage extension.
564+
*
565+
* Cleanup is handled automatically via disposables registered in `context.subscriptions`
566+
* during activation, so no additional teardown is required here.
567+
*/
534568
export function deactivate() {
535569
// No cleanup needed
536570
}

0 commit comments

Comments
 (0)