Skip to content

Commit

Permalink
Merge pull request #209 from mbehr1/feat/comments_multiselect
Browse files Browse the repository at this point in the history
feat(comments): add command to select comments to export
  • Loading branch information
mbehr1 authored May 25, 2024
2 parents 1503d4f + 3e50866 commit 2c76760
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 3 deletions.
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,11 @@
"title": "Export to clipboard as markup",
"icon": "$(clippy)"
},
{
"command": "dlt-logs.commentThreadExportMulti",
"title": "Select comments to export to clipboard as markup...",
"icon": "$(checklist)"
},
{
"command": "dlt-logs.commentThreadExportAll",
"title": "Export all to clipboard as markup",
Expand All @@ -800,6 +805,11 @@
"comments/commentThread/title": [
{
"command": "dlt-logs.commentThreadExportAll",
"group": "navigation@4",
"when": "commentController == dlt-logs && !commentThreadIsEmpty"
},
{
"command": "dlt-logs.commentThreadExportMulti",
"group": "navigation@3",
"when": "commentController == dlt-logs && !commentThreadIsEmpty"
},
Expand Down
15 changes: 15 additions & 0 deletions src/adltComments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,21 @@ export class AdltCommentThread {
}
}

/**
* return a headline (single line summary) for the thread
*
* Currently this is the first line of the first comment
*/
summary(): string {
if (this.thread.comments.length === 0) {
return 'no comments'
}
const comment1 = this.thread.comments[0]
const comment1Text = typeof comment1.body === 'string' ? comment1.body : comment1.body.value
// first line
return comment1Text.split('\n')[0]
}

asMarkdownText(): string {
let md = ''
this.thread.comments.forEach((comment) => {
Expand Down
48 changes: 45 additions & 3 deletions src/adltDocumentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1601,10 +1601,16 @@ export class AdltDocument implements vscode.Disposable {

/**
* Export the comments to the clipboard
* @param thread the thread to export, if undefined all threads will be exported
* @param thread the thread to export or the commentThreads to export or if undefined all threads will be exported
*/
commentsExport(thread: vscode.CommentThread | undefined) {
const threads = thread ? [this.commentThreads.find((t) => t.thread === thread)] : this.commentThreads
commentsExport(thread: vscode.CommentThread | AdltCommentThread[] | undefined) {
let threads =
thread !== undefined ? (Array.isArray(thread) ? thread : [this.commentThreads.find((t) => t.thread === thread)]) : this.commentThreads
threads = threads.filter((t) => t !== undefined)
if (threads.length === 0) {
vscode.window.showInformationMessage('No comments to export')
return
}
let exportStr = ''
for (const thread of threads) {
if (thread !== undefined) {
Expand All @@ -1617,6 +1623,32 @@ export class AdltDocument implements vscode.Disposable {
)
}

/**
* Show a quick pick to select which threads/comments to export and export them to the clipboard
* @param thread the thread that should be pre-selected
*/
commentsExportMulti(thread: vscode.CommentThread) {
const threads = this.commentThreads
const items = threads.map((t) => ({
label: t.summary().slice(0, 60),
description:
t.msgs.length > 1
? `${t.msgs.length} logs #${t.minMsgIndex}..${t.msgs[t.msgs.length - 1].index} ${new Date(
t.minMsgTimeInMs,
).toLocaleTimeString()}..`
: `log #${t.minMsgIndex} ${new Date(t.minMsgTimeInMs).toLocaleTimeString()} (calc.time)`,
picked: t.thread === thread, // determines whether it's pre-selected only
_thread: t,
}))
vscode.window.showQuickPick(items, { canPickMany: true, placeHolder: 'Select the comment threads to export' }).then((selected) => {
if (selected) {
const selectedThreads = selected.map((s) => s._thread)
this.log.info(`AdltDocument.commentsExportMulti() selected ${selectedThreads.length} threads`)
this.commentsExport(selectedThreads)
}
})
}

/**
* Clears all decorations from the text editors.
*
Expand Down Expand Up @@ -3246,6 +3278,16 @@ export class ADltDocumentProvider implements vscode.FileSystemProvider, /*vscode
}
}),
)
context.subscriptions.push(
vscode.commands.registerCommand('dlt-logs.commentThreadExportMulti', (thread: vscode.CommentThread) => {
const document = this._documents.get(thread.uri.toString())
if (document) {
document.commentsExportMulti(thread)
} else {
log.warn(`AdltDocumentProvider commentThreadExportMulti called but no document for thread`, thread)
}
}),
)

/* this.timerId = setInterval(() => {
// dump mem usage:
Expand Down

0 comments on commit 2c76760

Please sign in to comment.