Skip to content

Replace naive string matching with proper glob library for exclude patterns #15

Description

@dollfins

Description

The shouldScan() method in diagnostics.ts implements a naive glob matcher that only handles **/ prefix patterns using string inclusion checks. This means complex exclude patterns like **/test_*, **/target/**, or **/fixtures/*.rs do not work correctly in all cases.

Current State

private shouldScan(filePath: string): boolean {
    const patterns = this.config.exclude.split(',');
    const relativePath = path.relative(workspaceFolder, filePath);
    return !patterns.some(pattern => {
        const glob = pattern.trim();
        if (glob.startsWith('**/')) {
            return relativePath.includes(glob.slice(3));
        }
        return false;
    });
}

Problems:

  • relativePath.includes('test_*') treats * as a literal character, not a glob wildcard
  • Patterns without **/ prefix are silently ignored (return false)
  • Cannot exclude specific file extensions or directories properly

Expected Behavior

Use a proper glob matching library (or VS Code's built-in glob support) for exclude pattern evaluation:

  1. Replace the naive implementation with minimatch (already compatible with VS Code patterns)
  2. Support all standard glob patterns: *, **, ?, {a,b}, etc.
  3. Validate patterns at configuration time and warn about invalid patterns
  4. Consider using vscode.RelativePattern or vscode.GlobPattern for consistency with VS Code's own pattern matching

Implementation Notes

  • minimatch is already a transitive dependency through VS Code types — add it as an explicit devDependency
  • Or use picomatch for a lighter alternative
  • Add unit tests for pattern matching with common exclude scenarios
  • Cache compiled patterns for performance

Acceptance Criteria

  • Pattern **/test_* excludes files like test_utils.rs and src/test_helper.rs
  • Pattern **/target/** excludes all files in target directories
  • Pattern **/fixtures/*.rs excludes Rust files in fixtures but not other file types
  • Invalid patterns show a warning notification
  • All existing tests pass
  • No performance regression on workspace scan

Complexity

Trivial — replace a simple function with a well-tested library, add tests.

Points

100

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions