Skip to content

feat: add Copy Reference context menu for databases and collections#545

Open
bgaeddert wants to merge 4 commits intomicrosoft:nextfrom
bgaeddert:dev/bgaeddert/copy-reference
Open

feat: add Copy Reference context menu for databases and collections#545
bgaeddert wants to merge 4 commits intomicrosoft:nextfrom
bgaeddert:dev/bgaeddert/copy-reference

Conversation

@bgaeddert
Copy link
Copy Markdown

Adds a "Copy Reference" right-click option to database and collection nodes in the sidebar. Database copies the db name, collection copies db.collection dot notation.

@bgaeddert bgaeddert requested a review from a team as a code owner April 2, 2026 11:13
@bgaeddert
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@bgaeddert bgaeddert force-pushed the dev/bgaeddert/copy-reference branch from 1e8e641 to e5a93dc Compare April 2, 2026 11:23
@tnaum-ms tnaum-ms added this to the 0.7.4 milestone Apr 2, 2026
@tnaum-ms
Copy link
Copy Markdown
Collaborator

tnaum-ms commented Apr 2, 2026

@bgaeddert Thanks so much for your contribution! We have a patch release planned for today, so I'll add your work to the queue for review and inclusion in the next release.

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 a new “Copy Reference” context-menu action for DocumentDB/MongoRU database and collection tree nodes, enabling quick copying of db or db.collection identifiers to the clipboard.

Changes:

  • Registers two new tree-node commands (copyDatabaseReference, copyCollectionReference) in the extension.
  • Implements clipboard-copy behavior for database and collection references with a localized confirmation message.
  • Contributes the new commands and context-menu placements in package.json, and adds the new l10n bundle string.

Reviewed changes

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

File Description
src/documentdb/ClustersExtension.ts Registers the new commands with tree-node unwrapping/correlation.
src/commands/copyReference/copyReference.ts Implements reference construction and clipboard copy for database/collection nodes.
package.json Adds command contributions and context-menu entries (database + collection).
l10n/bundle.l10n.json Adds localization entry for the new confirmation message.

Comment on lines +12 to +29
export async function copyDatabaseReference(_context: IActionContext, node: DatabaseItem): Promise<void> {
if (!node) {
throw new Error(l10n.t('No node selected.'));
}

const reference = node.databaseInfo.name;
await vscode.env.clipboard.writeText(reference);
void vscode.window.showInformationMessage(l10n.t('The reference has been copied to the clipboard'));
}

export async function copyCollectionReference(_context: IActionContext, node: CollectionItem): Promise<void> {
if (!node) {
throw new Error(l10n.t('No node selected.'));
}

const reference = `${node.databaseInfo.name}.${node.collectionInfo.name}`;
await vscode.env.clipboard.writeText(reference);
void vscode.window.showInformationMessage(l10n.t('The reference has been copied to the clipboard'));
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

copyDatabaseReference and copyCollectionReference are almost identical (null-check, build reference, copy to clipboard, same confirmation message). Consider consolidating into a shared helper (or a single command that handles both DatabaseItem and CollectionItem) to avoid duplicated logic and keep future changes (e.g., message text) in sync.

Suggested change
export async function copyDatabaseReference(_context: IActionContext, node: DatabaseItem): Promise<void> {
if (!node) {
throw new Error(l10n.t('No node selected.'));
}
const reference = node.databaseInfo.name;
await vscode.env.clipboard.writeText(reference);
void vscode.window.showInformationMessage(l10n.t('The reference has been copied to the clipboard'));
}
export async function copyCollectionReference(_context: IActionContext, node: CollectionItem): Promise<void> {
if (!node) {
throw new Error(l10n.t('No node selected.'));
}
const reference = `${node.databaseInfo.name}.${node.collectionInfo.name}`;
await vscode.env.clipboard.writeText(reference);
void vscode.window.showInformationMessage(l10n.t('The reference has been copied to the clipboard'));
async function copyReferenceInternal<T extends DatabaseItem | CollectionItem>(
node: T | undefined,
getReference: (node: T) => string,
): Promise<void> {
if (!node) {
throw new Error(l10n.t('No node selected.'));
}
const reference = getReference(node);
await vscode.env.clipboard.writeText(reference);
void vscode.window.showInformationMessage(l10n.t('The reference has been copied to the clipboard'));
}
export async function copyDatabaseReference(_context: IActionContext, node: DatabaseItem): Promise<void> {
await copyReferenceInternal(node, (n) => n.databaseInfo.name);
}
export async function copyCollectionReference(_context: IActionContext, node: CollectionItem): Promise<void> {
await copyReferenceInternal(node, (n) => `${n.databaseInfo.name}.${n.collectionInfo.name}`);

Copilot uses AI. Check for mistakes.
package.json Outdated
"//": "Copy Collection Reference",
"category": "DocumentDB",
"command": "vscode-documentdb.command.copyCollectionReference",
"title": "Copy Reference"
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

There are two separate commands contributed for the same UX label (both titled "Copy Reference") and they differ only by target type. If feasible, consider contributing a single command and branching on the selected node type, which reduces package.json/registration surface area and avoids duplicate command entries in VS Code’s command/keybinding lists.

Suggested change
"title": "Copy Reference"
"title": "Copy Collection Reference"

Copilot uses AI. Check for mistakes.
@tnaum-ms
Copy link
Copy Markdown
Collaborator

tnaum-ms commented Apr 2, 2026

I'll definitely update the contributing.md file next... I just noticed how often automatic checks have bounced you.

PR Completion Checklist
Before finishing work on a PR, agents must run the following steps in order:

Localization:
If any user-facing strings were added, modified, or removed, run:
npm run l10n

Formatting:
Run Prettier to ensure all files meet formatting standards:
npm run prettier-fix

Linting:
Run ESLint to confirm there are no linting errors:
npm run lint

@tnaum-ms
Copy link
Copy Markdown
Collaborator

tnaum-ms commented Apr 2, 2026

Copilot review procedure runs for all PRs

@bgaeddert
Copy link
Copy Markdown
Author

@tnaum-ms It would’ve been helpful to know ahead of time, but the build errors have been straightforward to understand and fix. Thanks!

I've also been wanting to see copilot review in action.

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 4 out of 4 changed files in this pull request and generated 2 comments.

Comment on lines +538 to +542
"//": "Copy Database Reference",
"category": "DocumentDB",
"command": "vscode-documentdb.command.copyDatabaseReference",
"title": "Copy Database Reference"
},
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

PR description says the context menu option is "Copy Reference", but the contributed command title here is "Copy Database Reference". If the intended UI label is the generic "Copy Reference" (with behavior determined by node type), consider changing the title to match the description (and keep the specificity only in the command id).

Copilot uses AI. Check for mistakes.
Comment on lines +543 to +547
{
"//": "Copy Collection Reference",
"category": "DocumentDB",
"command": "vscode-documentdb.command.copyCollectionReference",
"title": "Copy Collection Reference"
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

PR description says the context menu option is "Copy Reference", but this command is titled "Copy Collection Reference". Consider using the same "Copy Reference" title for both database/collection context menu commands so the UI matches the stated behavior.

Copilot uses AI. Check for mistakes.
Adds a "Copy Reference" right-click option to database and collection
nodes in the sidebar. Database copies the db name, collection copies
db.collection dot notation.
…iate titles

Extracts shared logic into copyReferenceInternal helper. Renames command
titles to "Copy Database Reference" and "Copy Collection Reference" to
avoid duplicate labels in VS Code command/keybinding lists.
@bgaeddert bgaeddert force-pushed the dev/bgaeddert/copy-reference branch from 47d4093 to 32e6d3e Compare April 9, 2026 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

3 participants