Skip to content

feat(vscode): add token usage visibility setting - #1100

Open
macjayz wants to merge 2 commits into
Nano-Collective:mainfrom
macjayz:macjayz/toggle-token-usage
Open

feat(vscode): add token usage visibility setting#1100
macjayz wants to merge 2 commits into
Nano-Collective:mainfrom
macjayz:macjayz/toggle-token-usage

Conversation

@macjayz

@macjayz macjayz commented Aug 31, 2026

Copy link
Copy Markdown

Summary

  • add a nanocoder.showTokenUsage VS Code setting, defaulting to false
  • sync the setting into the chat webview when it becomes ready and when settings are refreshed
  • hide the token/cost footer unless the setting is enabled

Fixes #1096

Testing

  • pnpm run format:check
  • pnpm run test:types
  • pnpm run test:types:vscode
  • pnpm exec ava plugins/vscode/src/settings-manager.spec.ts source/vscode/chat-panel-turn-footer.spec.ts

@will-lamerton will-lamerton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approach looks right and the webview-side gating is clean. A few things to fix before merge.

Blocking

  1. Unhandled rejection on the update path. _handleUpdateSetting is now async but case 'updateSetting' calls it without await/.catch(), and _updateShowTokenUsage has no try/catch. If config.update rejects, the webview never gets a settingsUpdated message, no error toast fires, and the promise rejects unhandled. SettingsManager.updateSetting already wraps its body and returns {success: false, error}; mirror that.

  2. Always writing ConfigurationTarget.Global. The setting has no declared scope, so it defaults to window and can be set in .vscode/settings.json. When a workspace value exists, get() returns it, the panel writes Global, the effective value never changes, and the toggle silently snaps back with no error. Use config.inspect() to pick the narrowest scope that already holds a value, falling back to Global. Also worth deciding deliberately: every other toggle in this panel persists per-project, so this one changing behaviour for all workspaces is an inconsistency.

  3. No onDidChangeConfiguration listener. It is a contributed setting now, so users will flip it in the Settings editor, and nothing pushes that to a live webview. It stays stale until reload or until the in-panel settings view is opened. extension.ts:130 already has this pattern for nanocoder.codeLens; calling _handleRequestSettings() on affectsConfiguration('nanocoder.showTokenUsage') closes it.

Non-blocking

  1. SettingsManager.readSettings hardcodes showTokenUsage: false and the provider immediately overwrites it, so the field on SettingsData is wrong by construction for any other caller. Prefer leaving it off SettingsData and typing the webview payload as SettingsData & {showTokenUsage: boolean}.

  2. The settings-manager.spec.ts assertion tests that hardcoded constant, so it passes whether or not the feature works. Drop it or move it to whatever owns the real value. The chat-panel-turn-footer.spec.ts test is good; the missing case is enabled-then-disabled.

  3. Toggling off leaves already-rendered footers on screen (and toggling on does not back-fill). Since the issue is about visual noise, hiding existing indicators in renderSettingsData would match expectations.

  4. Changeset is patch for a user-facing feature; this repo uses minor for those (see anthropic-prompt-caching, calm-work-summaries).

  5. Minor: case 'ready' now does a full config-file read plus a whole renderSettingsData pass to learn one boolean.

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.

[Feature] Add setting to toggle Token/Cost counter visibility (default to off)

2 participants