From 21a0f9785ad9d536e71d6887ee8873bb33bfbab0 Mon Sep 17 00:00:00 2001 From: Matthias Behr Date: Tue, 19 Nov 2024 21:01:04 +0100 Subject: [PATCH] feat(sequence): add copy to clipboard for events/sequence Copies the sequence result in markdown format to the clipboard. --- package.json | 10 ++++++++++ src/adltDocumentProvider.ts | 14 +++++++++----- src/extension.ts | 6 ++++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index bd2da470..8ea070ca 100644 --- a/package.json +++ b/package.json @@ -799,6 +799,11 @@ "command": "dlt-logs.commentThreadExportAll", "title": "Export all to clipboard as markup", "icon": "$(markdown)" + }, + { + "command": "dlt-logs.treeItemToClipboard", + "title": "Export to clipboard", + "icon": "$(clippy)" } ], "menus": { @@ -904,6 +909,11 @@ "command": "dlt-logs.setPosFilter", "when": "view == dltLifecycleExplorer && viewItem =~ /canSetPosF/", "group": "inline" + }, + { + "command": "dlt-logs.treeItemToClipboard", + "when": "view == dltLifecycleExplorer && viewItem =~ /canCopyToClipboard/", + "group": "inline" } ], "editor/title": [ diff --git a/src/adltDocumentProvider.ts b/src/adltDocumentProvider.ts index 54461b39..8ffe95f7 100644 --- a/src/adltDocumentProvider.ts +++ b/src/adltDocumentProvider.ts @@ -2902,18 +2902,21 @@ export class AdltDocument implements vscode.Disposable { this._treeEventEmitter.fire(seqNode) } // get the full md from the sequence result: - /* todo support export command or preview as md - let tooltipSummary = summary try { const resAsMd = seqResultToMdAst(seqResult) const resAsMarkdown = toMarkdown( { type: 'root', children: resAsMd }, { extensions: [gfmTableToMarkdown({ tablePipeAlign: false })] }, ) - tooltipSummary += `\n${resAsMarkdown}` + thisSequenceNode.contextValue = 'canCopyToClipboard' + thisSequenceNode.applyCommand = (command) => { + // command should be 'copyToClipboard' but we can ignore it here + vscode.env.clipboard.writeText(resAsMarkdown) + vscode.window.showInformationMessage(`Exported sequence ${thisSequenceNode.label} to clipboard as markup text`) + } } catch (e) { - tooltipSummary += `\n... error in generating markdown: ${e}` - }*/ + log.warn(`restQueryDocsFilters failed toMarkdown due to: ${e}`) + } thisSequenceNode.description = summary //thisSequenceNode.tooltip = new vscode.MarkdownString(tooltipSummary) //thisSequenceNode.tooltip.supportHtml = true @@ -3604,6 +3607,7 @@ export class ADltDocumentProvider implements vscode.FileSystemProvider, /*vscode case 'setPosFilter': this.modifyNode(node, 'setPosFilter') break + case 'copyToClipboard': case 'save': if (node.uri !== null && this._documents.get(node.uri.toString()) !== undefined && node.applyCommand) { node.applyCommand(command) diff --git a/src/extension.ts b/src/extension.ts index f32400fb..9cd7b46b 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -690,6 +690,12 @@ export function activate(context: vscode.ExtensionContext) { }), ) + context.subscriptions.push( + vscode.commands.registerCommand('dlt-logs.treeItemToClipboard', async (...args: any[]) => { + adltProvider.onTreeNodeCommand('copyToClipboard', args[0]) + }), + ) + context.subscriptions.push( vscode.commands.registerCommand('dlt-logs.openReport', async (...args: any[]) => { // we can be called with two types of args: