Skip to content

Commit ccd0c17

Browse files
committed
Adds feature #71
1 parent d218780 commit ccd0c17

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@
215215
"command": "weAudit.addRegionToAnEntry",
216216
"title": "weAudit: Add Region to a Finding"
217217
},
218+
{
219+
"command": "weAudit.addRegionToAnEntryWithLabel",
220+
"title": "weAudit: Add Region to a Finding with Label"
221+
},
218222
{
219223
"command": "weAudit.showFindingsSearchBar",
220224
"title": "weAudit: Search and Filter Findings"

src/codeMarker.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,6 +2011,10 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
20112011
this.addRegionToAnEntry();
20122012
});
20132013

2014+
vscode.commands.registerCommand("weAudit.addRegionToAnEntryWithLabel", () => {
2015+
this.addRegionToAnEntryWithLabel();
2016+
});
2017+
20142018
vscode.commands.registerCommand("weAudit.deleteLocation", (entry: FullLocationEntry) => {
20152019
this.deleteLocation(entry);
20162020
});
@@ -3222,6 +3226,75 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
32223226
});
32233227
}
32243228

3229+
/**
3230+
* Add the selected code region to an existing entry, prompting for a label
3231+
*/
3232+
async addRegionToAnEntryWithLabel(): Promise<void> {
3233+
const editor = vscode.window.activeTextEditor;
3234+
if (editor === undefined) {
3235+
return;
3236+
}
3237+
const locations = this.getActiveSelectionLocation();
3238+
if (locations === undefined || locations.length === 0) {
3239+
return;
3240+
}
3241+
3242+
// create a quick pick to select the entry to add the region to
3243+
const items = this.treeEntries
3244+
.filter((entry) => {
3245+
if (entry.locations.length === 0 || entry.locations[0].rootPath !== locations[0].rootPath) {
3246+
return false;
3247+
}
3248+
return true;
3249+
})
3250+
.map((entry) => {
3251+
return {
3252+
label: entry.label,
3253+
entry: entry,
3254+
};
3255+
});
3256+
3257+
// if we have no findings so far, create a new one
3258+
if (items.length === 0) {
3259+
this.addFinding();
3260+
return;
3261+
}
3262+
3263+
const pickItem = await vscode.window.showQuickPick(items, {
3264+
ignoreFocusOut: true,
3265+
title: "Select the finding to add the region to",
3266+
});
3267+
3268+
if (pickItem === undefined) {
3269+
return;
3270+
}
3271+
3272+
const label = await vscode.window.showInputBox({
3273+
title: "Enter a label for this location",
3274+
ignoreFocusOut: true,
3275+
});
3276+
3277+
if (label === undefined) {
3278+
return;
3279+
}
3280+
3281+
const entry = pickItem.entry;
3282+
// Add each selection as a separate region with the label
3283+
for (const location of locations) {
3284+
location.label = label;
3285+
entry.locations.push(location);
3286+
}
3287+
this.updateSavedData(entry.author);
3288+
this.decorateWithUri(editor.document.uri);
3289+
this.refresh(editor.document.uri);
3290+
// reveal the entry in the tree view if the treeview is visible,
3291+
// for some reason, it won't expand even if though it is created
3292+
// with an expanded state
3293+
if (treeView.visible) {
3294+
treeView.reveal(entry, { expand: 1, select: false });
3295+
}
3296+
}
3297+
32253298
/**
32263299
* Loads the saved findings from a file
32273300
* @param config the configuration to load from

0 commit comments

Comments
 (0)