Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@
"command": "weAudit.addRegionToAnEntry",
"title": "weAudit: Add Region to a Finding"
},
{
"command": "weAudit.addRegionToAnEntryWithLabel",
"title": "weAudit: Add Region to a Finding with Label"
},
{
"command": "weAudit.showFindingsSearchBar",
"title": "weAudit: Search and Filter Findings"
Expand Down
44 changes: 40 additions & 4 deletions src/codeMarker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2014,6 +2014,10 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
void this.addRegionToAnEntry();
});

vscode.commands.registerCommand("weAudit.addRegionToAnEntryWithLabel", () => {
void this.addRegionToAnEntryWithLabel();
});

vscode.commands.registerCommand("weAudit.deleteLocation", (entry: FullLocationEntry) => {
this.deleteLocation(entry);
});
Expand Down Expand Up @@ -3169,9 +3173,11 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
}

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

let label: string | undefined;
if (getLabel) {
label = await getLabel();
if (label === undefined) {
return;
}
}

const entry = pickItem.entry;
// Add each selection as a separate region
// Add each selection as a separate region, optionally tagging with the provided label
for (const location of locations) {
if (label !== undefined) {
location.label = label;
}
entry.locations.push(location);
}
void this.updateSavedData(entry.author);
this.updateSavedData(entry.author);
this.decorateWithUri(editor.document.uri);
this.refresh(editor.document.uri);
// reveal the entry in the tree view if the treeview is visible,
Expand All @@ -3227,6 +3244,25 @@ export class CodeMarker implements vscode.TreeDataProvider<TreeEntry> {
}
}

/**
* Add the selected code region to an existing entry
*/
async addRegionToAnEntry(): Promise<void> {
await this.addRegionToEntryWithOptionalLabel();
}

/**
* Add the selected code region to an existing entry, prompting for a label
*/
async addRegionToAnEntryWithLabel(): Promise<void> {
await this.addRegionToEntryWithOptionalLabel(async () =>
vscode.window.showInputBox({
title: "Enter a label for this location",
ignoreFocusOut: true,
}),
);
}

/**
* Loads the saved findings from a file
* @param config the configuration to load from
Expand Down
Loading