Skip to content

Add shell completion telemetry coverage#635

Merged
tnaum-ms merged 4 commits into
nextfrom
dev/tnaum/shell-autocompletion-tweaks
May 13, 2026
Merged

Add shell completion telemetry coverage#635
tnaum-ms merged 4 commits into
nextfrom
dev/tnaum/shell-autocompletion-tweaks

Conversation

@tnaum-ms
Copy link
Copy Markdown
Collaborator

@tnaum-ms tnaum-ms commented May 13, 2026

Adds telemetry instrumentation to the interactive shell's completion system, closing the gap where Tab completions, ghost text, and closing-bracket suggestions were untracked.

Changes

  • completion.accepted — shell completions now flow into the existing accumulating event with src_shell, alongside playground and collection view. Includes trigger_tab / trigger_ghostText to distinguish acceptance method.
  • shell.completionGhost — tracks shown vs accepted ratio for inline ghost text suggestions, broken down by category (field, operator, collectionName, etc.).
  • shell.completionList — tracks when the multi-match picker is displayed (e.g., db.col.fin⇥ showing available methods), broken down by category.
  • shell.closingBrackets — tracks shown vs accepted ratio for closing-bracket ghost text (}}) suggestions).
  • Adds 'shell' as a CompletionSource in completionCategories.ts.

All events use callWithAccumulatingTelemetry for batched, low-overhead emission.

Telemetry correctness fixes (added during review)

  • ShellGhostText.show() now returns boolean; shown telemetry is gated on actual render to prevent overcount when the same ghost text stays visible.
  • completion.accepted is only emitted after a successful insert or replace — no-op Tab presses (fully typed word matching a single candidate) no longer inflate acceptance counts.
  • candidateCount was removed from shell.completionList: callWithAccumulatingTelemetry sums measurements across the batch, making a per-display length value analytically misleading. Tracked as #636 for future min/max/median support.

Copilot AI review requested due to automatic review settings May 13, 2026 05:33
@tnaum-ms tnaum-ms requested a review from a team as a code owner May 13, 2026 05:33
Copy link
Copy Markdown
Contributor

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

Adds telemetry instrumentation to the interactive shell’s completion system so completion acceptance and suggestion surfaces (Tab, ghost text, completion list, closing-brackets) are tracked consistently alongside existing completion telemetry.

Changes:

  • Adds 'shell' as a CompletionSource in the shared completion telemetry categories.
  • Instruments shell completion acceptance into the accumulating completion.accepted event (with src_shell and trigger_tab / trigger_ghostText measurements).
  • Adds new accumulating shell events for ghost text, completion list display, and closing-brackets ghost suggestions.

Reviewed changes

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

File Description
src/telemetry/completionCategories.ts Extends shared completion telemetry source taxonomy to include the shell surface.
src/documentdb/shell/DocumentDBShellPty.ts Adds accumulating telemetry emission for shell completion acceptance, ghost text shown/accepted, completion list shown, and closing-brackets suggestions.
Comments suppressed due to low confidence (1)

src/documentdb/shell/DocumentDBShellPty.ts:1139

  • Same overcounting issue as completion ghost text: trackClosingBracketsShown() is called even when ShellGhostText.show(closing) doesn’t re-render because the same closing string is already visible. That will inflate shell.closingBrackets.shown and distort the accepted ratio. Gate the telemetry on an actual change in the ghost text (or have ShellGhostText.show() report whether it rendered).
                const closing = getClosingBrackets(buffer);
                if (closing.length > 0) {
                    this._ghostTextIsHint = false;
                    this._ghostTextIsClosingBrackets = true;
                    this._ghostCandidateKind = undefined;
                    this._ghostText.show(closing, (d) => this._writeEmitter.fire(d));
                    this.trackClosingBracketsShown();
                    return;

Comment thread src/documentdb/shell/DocumentDBShellPty.ts Outdated
Comment thread src/documentdb/shell/DocumentDBShellPty.ts
Comment thread src/documentdb/shell/DocumentDBShellPty.ts
sajeetharan
sajeetharan previously approved these changes May 13, 2026
@tnaum-ms
Copy link
Copy Markdown
Collaborator Author

Independent finding fixed: Single-candidate Tab acceptance counted even when Tab inserts nothing.

applySingleCompletion() recorded completion.accepted telemetry before verifying the buffer actually changed. When the user fully types a word that matches a single candidate (e.g., typing use matching candidate use), the remaining text is empty — no insertion happens, but the acceptance counter still fired.

Fixed in 3f40929c by moving trackCompletionAccepted() to fire only after a successful insertText() or replaceText() call.

Copy link
Copy Markdown
Collaborator Author

@tnaum-ms tnaum-ms left a comment

Choose a reason for hiding this comment

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

Review after fixes applied:

Three issues addressed in this round:

  1. Ghost/closing-brackets shown overcount (Medium → Fixed in 33ecdafb) — ShellGhostText.show() now returns boolean; telemetry gated on actual render.
  2. Tab acceptance fires on no-op (Medium → Fixed in 3f40929c) — trackCompletionAccepted() moved after insertText()/replaceText().
  3. candidateCount removed from accumulating telemetry (Fixed in 3f40929c) — accumulating telemetry is for occurrence counts; summing candidates.length is not meaningful here. If per-display distribution is needed in the future, it should use non-accumulating telemetry or a min/max/median collector.

One remaining low-severity nit (file comment): inconsistent state reset across _ghostText.clear() call sites. Harmless but worth consolidating into a helper.

All 1937 tests pass. Build succeeds.

Comment thread src/documentdb/shell/DocumentDBShellPty.ts
tnaum-ms added 3 commits May 13, 2026 09:48
ShellGhostText.show() returns early when the same text is already
visible, but trackCompletionGhostShown() and trackClosingBracketsShown()
fired unconditionally after the call. This inflated shown counts.

Changed show() to return a boolean indicating whether it rendered new
content, and gate the telemetry calls on that return value.
applySingleCompletion() recorded acceptance telemetry before verifying
the Tab press changed the buffer. Fully typed inputs (e.g., 'use'
matching candidate 'use') produced empty remaining text but still
incremented completion.accepted, inflating acceptance counts.

Moved trackCompletionAccepted() to fire only after a successful insert
or replace.

Also removed candidateCount from shell.completionList accumulating
telemetry — accumulating telemetry is designed to count how often events
occur (shown/accepted), not to sum variable-length values like candidate
list sizes.
All ghost text clear sites now use a single clearGhostState() method
that resets _ghostText, _ghostTextIsHint, _ghostTextIsClosingBrackets,
and _ghostCandidateKind together. Previously, several call sites only
partially reset state fields, which was harmless but inconsistent and
fragile for future additions.
@github-actions
Copy link
Copy Markdown
Contributor

✅ Code Quality Checks

Check Status How to fix
Localization (l10n) ✅ Passed
ESLint ✅ Passed
Prettier formatting ✅ Passed

This comment is updated automatically on each push.

Copy link
Copy Markdown
Contributor

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread src/documentdb/shell/DocumentDBShellPty.ts
@github-actions
Copy link
Copy Markdown
Contributor

📦 Build Size Report

Metric Base (next) PR Delta
VSIX (vscode-documentdb-0.8.0.vsix) 7.51 MB 7.51 MB ⬆️ +0 KB (+0.0%)
Webview bundle (views.js) 5.79 MB 5.79 MB ⬆️ +0 KB (+0.0%)

Download artifact · updated automatically on each push.

@tnaum-ms tnaum-ms merged commit 6ebf697 into next May 13, 2026
12 checks passed
@tnaum-ms tnaum-ms deleted the dev/tnaum/shell-autocompletion-tweaks branch May 13, 2026 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

3 participants