feat: add Copy Reference context menu for databases and collections#545
feat: add Copy Reference context menu for databases and collections#545bgaeddert wants to merge 4 commits intomicrosoft:nextfrom
Conversation
|
@microsoft-github-policy-service agree |
1e8e641 to
e5a93dc
Compare
|
@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. |
There was a problem hiding this comment.
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. |
| 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')); |
There was a problem hiding this comment.
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.
| 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}`); |
package.json
Outdated
| "//": "Copy Collection Reference", | ||
| "category": "DocumentDB", | ||
| "command": "vscode-documentdb.command.copyCollectionReference", | ||
| "title": "Copy Reference" |
There was a problem hiding this comment.
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.
| "title": "Copy Reference" | |
| "title": "Copy Collection Reference" |
|
I'll definitely update the PR Completion Checklist Localization: Formatting: Linting: |
|
Copilot review procedure runs for all PRs |
|
@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. |
f50dd59 to
47d4093
Compare
| "//": "Copy Database Reference", | ||
| "category": "DocumentDB", | ||
| "command": "vscode-documentdb.command.copyDatabaseReference", | ||
| "title": "Copy Database Reference" | ||
| }, |
There was a problem hiding this comment.
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).
| { | ||
| "//": "Copy Collection Reference", | ||
| "category": "DocumentDB", | ||
| "command": "vscode-documentdb.command.copyCollectionReference", | ||
| "title": "Copy Collection Reference" |
There was a problem hiding this comment.
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.
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.
47d4093 to
32e6d3e
Compare
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.