Skip to content

Commit 32e6d3e

Browse files
committed
refactor: consolidate copy reference into shared helper and differentiate 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.
1 parent 34c144b commit 32e6d3e

3 files changed

Lines changed: 14 additions & 13 deletions

File tree

l10n/bundle.l10n.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@
986986
"The name must be between {0} and {1} characters.": "The name must be between {0} and {1} characters.",
987987
"The output window may contain additional information.": "The output window may contain additional information.",
988988
"The process exited prematurely.": "The process exited prematurely.",
989-
"The reference has been copied to the clipboard": "The reference has been copied to the clipboard",
989+
"The reference has been copied to the clipboard.": "The reference has been copied to the clipboard.",
990990
"The selected authentication method is not supported.": "The selected authentication method is not supported.",
991991
"The selected connection has been removed.": "The selected connection has been removed.",
992992
"The selected folder has been removed.": "The selected folder has been removed.",

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,13 +538,13 @@
538538
"//": "Copy Database Reference",
539539
"category": "DocumentDB",
540540
"command": "vscode-documentdb.command.copyDatabaseReference",
541-
"title": "Copy Reference"
541+
"title": "Copy Database Reference"
542542
},
543543
{
544544
"//": "Copy Collection Reference",
545545
"category": "DocumentDB",
546546
"command": "vscode-documentdb.command.copyCollectionReference",
547-
"title": "Copy Reference"
547+
"title": "Copy Collection Reference"
548548
}
549549
],
550550
"submenus": [

src/commands/copyReference/copyReference.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,23 @@ import * as vscode from 'vscode';
99
import { type CollectionItem } from '../../tree/documentdb/CollectionItem';
1010
import { type DatabaseItem } from '../../tree/documentdb/DatabaseItem';
1111

12-
export async function copyDatabaseReference(_context: IActionContext, node: DatabaseItem): Promise<void> {
12+
async function copyReferenceInternal<T extends DatabaseItem | CollectionItem>(
13+
node: T | undefined,
14+
getReference: (node: T) => string,
15+
): Promise<void> {
1316
if (!node) {
1417
throw new Error(l10n.t('No node selected.'));
1518
}
1619

17-
const reference = node.databaseInfo.name;
20+
const reference = getReference(node);
1821
await vscode.env.clipboard.writeText(reference);
19-
void vscode.window.showInformationMessage(l10n.t('The reference has been copied to the clipboard'));
22+
void vscode.window.showInformationMessage(l10n.t('The reference has been copied to the clipboard.'));
2023
}
2124

22-
export async function copyCollectionReference(_context: IActionContext, node: CollectionItem): Promise<void> {
23-
if (!node) {
24-
throw new Error(l10n.t('No node selected.'));
25-
}
25+
export async function copyDatabaseReference(_context: IActionContext, node: DatabaseItem): Promise<void> {
26+
await copyReferenceInternal(node, (n) => n.databaseInfo.name);
27+
}
2628

27-
const reference = `${node.databaseInfo.name}.${node.collectionInfo.name}`;
28-
await vscode.env.clipboard.writeText(reference);
29-
void vscode.window.showInformationMessage(l10n.t('The reference has been copied to the clipboard'));
29+
export async function copyCollectionReference(_context: IActionContext, node: CollectionItem): Promise<void> {
30+
await copyReferenceInternal(node, (n) => `${n.databaseInfo.name}.${n.collectionInfo.name}`);
3031
}

0 commit comments

Comments
 (0)