Skip to content

Fix: cancel snippet tab stops on delimiter chars in query playground#590

Merged
tnaum-ms merged 3 commits intorel/release_0.8.0from
dev/tnaum/tab-stop-playground
Apr 17, 2026
Merged

Fix: cancel snippet tab stops on delimiter chars in query playground#590
tnaum-ms merged 3 commits intorel/release_0.8.0from
dev/tnaum/tab-stop-playground

Conversation

@tnaum-ms
Copy link
Copy Markdown
Collaborator

Summary

Ports the collection view's cancelSnippetSession behavior to the query playground so that snippet tab stops are proactively closed when delimiter characters are typed.

Problem

When a user accepts a snippet completion in the playground (e.g. { $exists: <tabstop> }), the tab stop remained active indefinitely. Typing ,, }, ], space, or pressing Escape did not exit the snippet — the "ghost selection" bug that was already fixed in the collection view.

Solution

New PlaygroundSnippetSessionManager that listens for onDidChangeTextDocument on playground files and executes the built-in leaveSnippet command when a single-character delimiter (,, }, ]) is typed — mirroring the collection view's SNIPPET_EXIT_CHARS logic.

The collection view uses Monaco's internal snippetController2.cancel() (webview), while the playground uses VS Code's native leaveSnippet command (extension host editor).

Files changed

  • PlaygroundSnippetSessionManager.ts — new manager class
  • ClustersExtension.ts — register the manager alongside existing playground providers
  • playgroundSnippetSessionManager.test.ts — 9 unit tests covering all delimiter/non-delimiter/non-playground cases

Port the collection view's cancelSnippetSession behavior to the
query playground. When a user types a delimiter character (`,`, `}`, `]`)
while a snippet tab stop is active, the snippet session is now cancelled
via the built-in `leaveSnippet` command.

Previously, accepting a snippet completion (e.g., `{ \$exists: <tabstop> }`)
and filling in the value left the tab stop active indefinitely — typing
delimiters, spaces, or even pressing Escape (consumed by the suggest
widget) would not exit the snippet.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@tnaum-ms tnaum-ms requested a review from a team as a code owner April 17, 2026 12:15
@tnaum-ms tnaum-ms requested a review from Copilot April 17, 2026 12:23
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

Ports the “cancel snippet session on delimiter characters” behavior from the Collection View query editor to the native VS Code query playground, preventing snippet tab-stop highlights from persisting (“ghost selection”) after snippet completion acceptance.

Changes:

  • Added a PlaygroundSnippetSessionManager that listens to playground document edits and triggers VS Code’s leaveSnippet command when delimiter characters are typed.
  • Registered the new manager during extension activation alongside existing playground completion/hover providers.
  • Added a Jest test suite covering delimiter vs non-delimiter edits and playground vs non-playground documents.

Reviewed changes

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

File Description
src/documentdb/query-language/playground-completions/tdd/playgroundSnippetSessionManager.test.ts New unit tests for snippet-session exit behavior in playground documents.
src/documentdb/query-language/playground-completions/PlaygroundSnippetSessionManager.ts New manager that exits snippet mode on delimiter keystrokes in playground editors.
src/documentdb/ClustersExtension.ts Registers the new snippet session manager during extension setup.

- Remove inaccurate 'or Enter is pressed' from class doc comment
- Add activeTextEditor guard to prevent leaveSnippet in wrong editor
- Move jest.mock() before imports per repo convention
- Add test for active editor document mismatch scenario
@tnaum-ms tnaum-ms merged commit b1b43d9 into rel/release_0.8.0 Apr 17, 2026
2 checks passed
@tnaum-ms tnaum-ms deleted the dev/tnaum/tab-stop-playground branch April 17, 2026 14:57
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.

2 participants