Skip to content

add configurable toggle for marking whole directories - #57

Open
alxshine wants to merge 2 commits into
trailofbits:mainfrom
alxshine:mark-folders
Open

add configurable toggle for marking whole directories#57
alxshine wants to merge 2 commits into
trailofbits:mainfrom
alxshine:mark-folders

Conversation

@alxshine

Copy link
Copy Markdown

Hello again 👋 😊

This is a small PR implementing #30 , the ability to mark entire folders/directories as reviewed.

The toggleAuditedUri function will use the vscode.fs API to check if the URI in question is a directory or file, making a separate function for directories unnecessary.
This also makes adding a context menu action for the command simpler 🙂

For the behavior when encountering a directory, I added a configuration option with three modes:

  • no recursion: mark the directory only
  • direct children only: mark the directory and child files, no subdirectories
  • full recursion: recurse into all subdirectories, toggling all files

All the best 😊

Comment thread src/codeMarker.ts
}

private getRecursionBehavior(): string {
return vscode.workspace.getConfiguration("weaudit").get("general.recursionBehavior")!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weaudit should be weAudit, or this will always return undefined.

@jvdprng

jvdprng commented Oct 1, 2024

Copy link
Copy Markdown
Member

If I understand this correctly, with recursion off you can toggle a folder as audited without toggling the contained files as audited. However, if you ever toggle any of the recursive children of this folder as audited or not audited, it will start an upward recursion of this.checkIfAllSiblingFilesAreAudited, and if any of the intermediate files are not audited, your folder will not be marked as audited anymore. Is this the desired behavior?

@dguido

dguido commented Jan 21, 2026

Copy link
Copy Markdown
Member

Review

Thanks for this feature! Recursive directory marking is valuable functionality. However, there are some issues that need to be addressed:

1. Code Bugs

Filter logic bug (line 371 in the diff):

children = children.filter(([path, t], _) => { t != vscode.FileType.Directory })

The curly braces {} create a statement block, so the filter callback returns undefined for all items (effectively filtering out everything).

Should be:

children = children.filter(([_, t]) => t !== vscode.FileType.Directory)

Missing await on async recursive calls (line 373-376):

children.forEach(([child, __], _) => {
    const childUri = vscode.Uri.joinPath(uri, child)
    this.toggleAuditedUri(childUri)  // Missing await!
})

toggleAuditedUri is async but the call doesn't await. Also, forEach doesn't work well with async operations.

Should be:

for (const [child] of children) {
    const childUri = vscode.Uri.joinPath(uri, child);
    await this.toggleAuditedUri(childUri);
}

2. Architectural Conflict

The codebase has been significantly refactored since this PR was created. Main now uses a this.workspaces (MultiRootManager) abstraction instead of direct access to this.auditedFiles and this.workspacePath.

Your PR uses:

  • this.workspacePath
  • this.auditedFiles
  • Direct file path manipulation

Main now uses:

  • this.workspaces.toggleAudited(uri)
  • this.workspaces.getRoots()
  • Workspace-aware file management

Recommended Next Steps

  1. Rebase on main
  2. Adapt toggleAuditedUri to use the workspaces API instead of direct array manipulation
  3. The feature should call something like this.workspaces.toggleAudited(childUri) for each recursive call
  4. Fix the two bugs mentioned above

I'd be happy to help with the implementation if you'd like!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants