Skip to content

Use context-aware filenames for new Query Playgrounds 📝 #660

@tnaum-ms

Description

@tnaum-ms

Problem

When creating a new Query Playground, the file is named generically: playground-1.documentdb.js, playground-2.documentdb.js, etc. When a user has multiple playgrounds open targeting different clusters or collections, these names provide no context about what each playground is for.

The cluster name and collection/database context are already available at creation time (used in the header comment), but not reflected in the filename.

Current tab bar:
  playground-1.documentdb.js | playground-2.documentdb.js | playground-3.documentdb.js

Expected tab bar:
  my-cluster_users.documentdb.js | my-cluster_orders.documentdb.js | staging_products.documentdb.js

Expected Behavior

When a playground is created from the tree view (right-click on a database or collection), the filename should include context from the source node:

  • From a collection: {clusterName}_{collectionName}.documentdb.js
  • From a database: {clusterName}_{databaseName}.documentdb.js
  • Fallback (no context): keep the current playground-{N}.documentdb.js naming

If a file with the generated name already exists (as an untitled document), append a numeric suffix: my-cluster_users-2.documentdb.js.

Development Hints

Since this is a good first issue, here are some hints on where to start:

File to modify: src/commands/playground/newPlayground.ts

The filename is generated in the private createPlaygroundWithContent() function:

const numberUntitledPlaygrounds = vscode.workspace.textDocuments.filter(
    (doc) => doc.languageId === PLAYGROUND_LANGUAGE_ID,
).length;
const fileName = `playground-${numberUntitledPlaygrounds + 1}${PLAYGROUND_FILE_EXTENSION}`;

The public newPlayground() function already has access to context:

  • node.cluster.name for the cluster display name
  • node.collectionInfo.name for the collection (when launched from a collection)
  • node.databaseInfo.name for the database

You need to:

  1. Pass the relevant context (cluster name + database/collection name) into createPlaygroundWithContent()
  2. Build a descriptive filename from that context
  3. Sanitize the name for filesystem safety (replace special characters like /, \, :, etc.)
  4. Handle name collisions with existing untitled documents (append -2, -3, etc.)
  5. Fall back to the current generic naming when no context is available

Be mindful that cluster and collection names can contain special characters that are invalid in filenames.

Files to Modify

File Change
src/commands/playground/newPlayground.ts Update filename generation logic to include context

Acceptance Criteria

  • Playgrounds created from a collection node include cluster and collection name in filename
  • Playgrounds created from a database node include cluster and database name in filename
  • Special characters in names are sanitized for filesystem safety
  • Duplicate names get a numeric suffix
  • Fallback to generic naming when context is unavailable
  • The PLAYGROUND_FILE_EXTENSION (.documentdb.js) is preserved

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions