-
Notifications
You must be signed in to change notification settings - Fork 77
feat: copy id or document to clipboard #419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -487,6 +487,38 @@ export default class MDBExtensionController implements vscode.Disposable { | |
return Promise.resolve(true); | ||
} | ||
); | ||
this.registerCommand( | ||
EXTENSION_COMMANDS.MDB_COPY_DOCUMENT_ID_FROM_TREE, | ||
async (element: DocumentTreeItem): Promise<boolean> => { | ||
const { documentId } = element; | ||
|
||
if (!documentId) { | ||
void vscode.window.showWarningMessage('Can\'t copy ID from document that has no ID.'); | ||
return false; | ||
} | ||
|
||
let body = JSON.stringify(documentId); | ||
|
||
if (body.startsWith('"')) { | ||
body = body.slice(1, body.length - 1); | ||
} | ||
Comment on lines
+502
to
+504
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the idea here is to leave string document ids as-is, it might be better to check e.g. |
||
|
||
await vscode.env.clipboard.writeText(body); | ||
return true; | ||
} | ||
); | ||
this.registerCommand( | ||
EXTENSION_COMMANDS.MDB_COPY_DOCUMENT_FROM_TREE, | ||
async (element: DocumentTreeItem): Promise<boolean> => { | ||
const { document } = element; | ||
const tabSize = vscode.workspace | ||
.getConfiguration('editor') | ||
.get('tabSize', 2); | ||
const body = JSON.stringify(document, undefined, tabSize); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar question here :) |
||
await vscode.env.clipboard.writeText(body); | ||
return true; | ||
} | ||
); | ||
this.registerCommand( | ||
EXTENSION_COMMANDS.MDB_REFRESH_SCHEMA, | ||
(schemaTreeItem: SchemaTreeItem): Promise<boolean> => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens here if
documentId
contains non-JS bson datatypes, e.g.Binary()
or similar? Should this be EJSON instead of JSON?