Skip to content

fix(playground): use contextual untitled filenames#664

Merged
tnaum-ms merged 6 commits into
microsoft:mainfrom
omribz156:codex/playground-context-filenames
May 27, 2026
Merged

fix(playground): use contextual untitled filenames#664
tnaum-ms merged 6 commits into
microsoft:mainfrom
omribz156:codex/playground-context-filenames

Conversation

@omribz156

Copy link
Copy Markdown
Contributor

Summary

  • Generate Query Playground untitled filenames from the tree node context, e.g. {cluster}_{collection}.documentdb.js or {cluster}_{database}.documentdb.js.
  • Sanitize invalid filename characters and whitespace before building the filename.
  • Add numeric suffixes when a contextual playground filename is already open, while preserving the existing generic fallback when no context is available.

Closes #660

Verification

  • npm run build
  • npm run lint -- src/commands/playground/newPlayground.ts src/commands/playground/newPlayground.test.ts
  • npm run jesttest -- src/commands/playground/newPlayground.test.ts --runInBand
  • npm run prettier -- src/commands/playground/newPlayground.ts src/commands/playground/newPlayground.test.ts
  • npm run l10n
  • npm run package
  • git diff --check

This was implemented with Codex assistance, with the patch kept focused and manually reviewed before sending.

Generate Query Playground filenames from cluster and database or collection context, sanitize invalid filename characters, and suffix duplicate open playground names.
@omribz156 omribz156 requested a review from a team as a code owner May 21, 2026 07:52
Copilot AI review requested due to automatic review settings May 21, 2026 07:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 updates Query Playground creation to generate context-aware untitled filenames (derived from the originating tree node), improving tab readability when multiple playgrounds are open.

Changes:

  • Pass cluster + database/collection context into playground creation when launched from the tree.
  • Add filename generation that sanitizes invalid characters/whitespace and appends numeric suffixes on collisions.
  • Add Jest unit tests for contextual naming, sanitization, suffixing, and fallback behavior.

Reviewed changes

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

File Description
src/commands/playground/newPlayground.ts Adds contextual filename generation + sanitization/suffix logic and wires it into playground creation from tree context.
src/commands/playground/newPlayground.test.ts Adds unit coverage for the new filename generation behavior.

Comment thread src/commands/playground/newPlayground.ts Outdated
@tnaum-ms tnaum-ms added this to the 0.8.1 milestone May 21, 2026
@tnaum-ms tnaum-ms changed the base branch from next to main May 27, 2026 06:40
tnaum-ms added 3 commits May 27, 2026 08:41
The generic 'playground-N' fallback used the count of open playground
documents as its suffix, which collides whenever a user closes a
middle playground (e.g., closing playground-2 leaves [-1, -3], and
the old logic would re-issue playground-3).

Also broaden the dedup set to ALL open text documents (not just
playgrounds): VS Code rejects applyEdit on an untitled URI that
already exists regardless of language.

Both the contextual and generic branches now share a single
find-next-free-name helper.
newPlaygroundWithContent now forwards its connection metadata as the
filename context, so playgrounds opened from Collection View or the
Interactive Shell get the same '<cluster>_<database>.documentdb.js'
naming as tree-launched playgrounds — instead of falling back to
generic 'playground-N'.
@tnaum-ms

Copy link
Copy Markdown
Collaborator

Two maintainer follow-up commits pushed to this branch:

721c40d fixes two collision gaps in createPlaygroundFileName: the generic playground-N fallback used a raw document count as the suffix, which could collide after closing a middle playground (e.g., closing playground-2 leaves [-1, -3] open and the old logic would re-issue playground-3). Also addresses the Copilot review comment by broadening the dedup set to all open text documents. Both the contextual and generic branches now share a single find-next-free-name loop.

4fef0c9 pipes context through newPlaygroundWithContent (the entry point used by Collection View and the Interactive Shell). Those playgrounds now get contextual cluster_database.documentdb.js names instead of falling back to playground-N.

tnaum-ms added 2 commits May 27, 2026 11:14
The filename context object duplicated clusterDisplayName and (in the
cross-feature path) databaseName from the connection. Drop the separate
fileNameContext parameter and accept just an optional collectionName.
The filename now derives from connection.clusterDisplayName plus
collectionName ?? connection.databaseName, removing the duplication
and the possibility of passing mismatched cluster/db names.
@tnaum-ms

Copy link
Copy Markdown
Collaborator

Hey @omribz156, thanks for this contribution!

first-contribution

The core idea is solid and the test coverage was a great addition.

We made a few follow-up tweaks on top:

The collision check now covers all open text documents (not just playground-language ones), since VS Code rejects applyEdit on a duplicate URI regardless of language mode. The generic playground-N fallback also got the same loop-based approach so it can't collide after a user closes a middle playground.

newPlaygroundWithContent (the cross-feature entry point from Collection View / Interactive Shell) now also produces contextual filenames, since it already had the cluster and database name available.

Minor parameter cleanup: the filename context is now derived directly from the connection object instead of being passed as a separate parameter with duplicated fields.

All changes are on this branch as individual commits, so the history stays readable. Thanks again!

@tnaum-ms tnaum-ms closed this May 27, 2026
@tnaum-ms tnaum-ms reopened this May 27, 2026
@tnaum-ms tnaum-ms merged commit 762c2e9 into microsoft:main May 27, 2026
9 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.

Use context-aware filenames for new Query Playgrounds 📝

3 participants