Skip to content

Conversation

@steffen-heil-secforge
Copy link

@steffen-heil-secforge steffen-heil-secforge commented Nov 5, 2025

Summary

Replace custom glob matching implementation with the official gopls glob pattern matcher to provide full LSP 3.17 specification compliance. This fixes file watcher pattern matching for complex glob patterns that were previously unsupported.

Changes

  • Integrate LSP-compliant glob pattern matcher from golang.org/x/tools/gopls

  • Support all LSP glob pattern syntax:

    • * - match one or more characters in a path segment
    • ? - match one character in a path segment
    • ** - match any number of path segments, including none
    • {} - OR expressions (e.g., **/*.{ts,js})
    • [] - character ranges (e.g., [a-z])
    • [!...] - negated character ranges (e.g., [!0-9])
  • Implement thread-safe pattern caching with safety valve:

    • Uses sync.Map for efficient, lock-free reads
    • Clears cache if size exceeds 100 entries to protect against unbounded growth
    • Logs warning when cache is cleared
  • Remove previous go-gitignore-based implementation and custom brace expansion

Implementation Details

The implementation is derived from golang.org/x/tools/gopls/internal/lsp/glob with proper attribution to The Go Authors. Pattern caching eliminates redundant parsing on every file system event, significantly reducing CPU usage during high-frequency file watching operations.

Replace custom glob matching implementation with official gopls glob
pattern matcher to provide full LSP 3.17 specification compliance.

The implementation includes:
- LSP-compliant glob pattern syntax support:
  * * : match one or more characters in a path segment
  * ? : match one character in a path segment
  * ** : match any number of path segments, including none
  * {} : OR expressions for alternation (e.g., **/*.{ts,js})
  * [] : character ranges (e.g., [a-z])
  * [!...] : negated character ranges (e.g., [!0-9])

- Thread-safe pattern caching with safety valve:
  * Uses sync.Map for efficient, lock-free reads
  * Clears cache if size exceeds 100 entries to protect against
    unbounded growth from pattern leaks
  * Logs warning when cache is cleared

Implementation is derived from golang.org/x/tools/gopls/internal/lsp/glob
with proper attribution to The Go Authors.

Fixes file watcher pattern matching for complex glob patterns that were
previously unsupported, improving compatibility with LSP clients and
language servers.
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.

1 participant