fix(playground): use contextual untitled filenames#664
Conversation
Generate Query Playground filenames from cluster and database or collection context, sanitize invalid filename characters, and suffix duplicate open playground names.
There was a problem hiding this comment.
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. |
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'.
|
Two maintainer follow-up commits pushed to this branch: 721c40d fixes two collision gaps in 4fef0c9 pipes context through |
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.
|
Hey @omribz156, thanks for this 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! |

Summary
{cluster}_{collection}.documentdb.jsor{cluster}_{database}.documentdb.js.Closes #660
Verification
npm run buildnpm run lint -- src/commands/playground/newPlayground.ts src/commands/playground/newPlayground.test.tsnpm run jesttest -- src/commands/playground/newPlayground.test.ts --runInBandnpm run prettier -- src/commands/playground/newPlayground.ts src/commands/playground/newPlayground.test.tsnpm run l10nnpm run packagegit diff --checkThis was implemented with Codex assistance, with the patch kept focused and manually reviewed before sending.