Skip to content

Commit 202e630

Browse files
BuffaloWillfcasal
andauthored
Feature #71: Add the "Add Region to a Finding with Label" command (#104)
* Adds feature #71 * chore: unify add finding to region implementations --------- Co-authored-by: Filipe Casal <[email protected]>
1 parent 6c1785c commit 202e630

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@
220220
"command": "weAudit.addRegionToAnEntry",
221221
"title": "weAudit: Add Region to a Finding"
222222
},
223+
{
224+
"command": "weAudit.addRegionToAnEntryWithLabel",
225+
"title": "weAudit: Add Region to a Finding with Label"
226+
},
223227
{
224228
"command": "weAudit.showFindingsSearchBar",
225229
"title": "weAudit: Search and Filter Findings"

src/codeMarker.ts

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,6 +2014,10 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
20142014
void this.addRegionToAnEntry();
20152015
});
20162016

2017+
vscode.commands.registerCommand("weAudit.addRegionToAnEntryWithLabel", () => {
2018+
void this.addRegionToAnEntryWithLabel();
2019+
});
2020+
20172021
vscode.commands.registerCommand("weAudit.deleteLocation", (entry: FullLocationEntry) => {
20182022
this.deleteLocation(entry);
20192023
});
@@ -3169,9 +3173,11 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
31693173
}
31703174

31713175
/**
3172-
* Add the selected code region to an existing entry
3176+
* Shared helper that adds the current editor selection(s) to an existing entry.
3177+
* Optionally prompts for a label that is applied to each new location.
3178+
* @param getLabel function that resolves to the label to assign, or undefined to skip labeling
31733179
*/
3174-
async addRegionToAnEntry(): Promise<void> {
3180+
private async addRegionToEntryWithOptionalLabel(getLabel?: () => Promise<string | undefined>): Promise<void> {
31753181
const editor = vscode.window.activeTextEditor;
31763182
if (editor === undefined) {
31773183
return;
@@ -3211,12 +3217,23 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
32113217
return;
32123218
}
32133219

3220+
let label: string | undefined;
3221+
if (getLabel) {
3222+
label = await getLabel();
3223+
if (label === undefined) {
3224+
return;
3225+
}
3226+
}
3227+
32143228
const entry = pickItem.entry;
3215-
// Add each selection as a separate region
3229+
// Add each selection as a separate region, optionally tagging with the provided label
32163230
for (const location of locations) {
3231+
if (label !== undefined) {
3232+
location.label = label;
3233+
}
32173234
entry.locations.push(location);
32183235
}
3219-
void this.updateSavedData(entry.author);
3236+
this.updateSavedData(entry.author);
32203237
this.decorateWithUri(editor.document.uri);
32213238
this.refresh(editor.document.uri);
32223239
// reveal the entry in the tree view if the treeview is visible,
@@ -3227,6 +3244,25 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
32273244
}
32283245
}
32293246

3247+
/**
3248+
* Add the selected code region to an existing entry
3249+
*/
3250+
async addRegionToAnEntry(): Promise<void> {
3251+
await this.addRegionToEntryWithOptionalLabel();
3252+
}
3253+
3254+
/**
3255+
* Add the selected code region to an existing entry, prompting for a label
3256+
*/
3257+
async addRegionToAnEntryWithLabel(): Promise<void> {
3258+
await this.addRegionToEntryWithOptionalLabel(async () =>
3259+
vscode.window.showInputBox({
3260+
title: "Enter a label for this location",
3261+
ignoreFocusOut: true,
3262+
}),
3263+
);
3264+
}
3265+
32303266
/**
32313267
* Loads the saved findings from a file
32323268
* @param config the configuration to load from

0 commit comments

Comments
 (0)