Skip to content

feat(client): respect .gitignore + better exclude defaults (#145)#164

Merged
pranaygp merged 2 commits into
masterfrom
worktree-agent-a5eebbbaf10c319b0
May 17, 2026
Merged

feat(client): respect .gitignore + better exclude defaults (#145)#164
pranaygp merged 2 commits into
masterfrom
worktree-agent-a5eebbbaf10c319b0

Conversation

@pranaygp
Copy link
Copy Markdown
Owner

@pranaygp pranaygp commented May 16, 2026

Summary

  • Add a new cssPeek.respectGitignore setting (default true) that reads the workspace root .gitignore and merges its patterns into cssPeek.peekToExclude before calling Workspace.findFiles.
  • Expand the default cssPeek.peekToExclude to also cover common build artifact directories: **/.git/**, **/dist/**, **/build/**, **/.next/**, **/out/**, **/coverage/**.
  • Reads .gitignore via vscode.workspace.fs.readFile (no new Node fs dependency added on the client). Note: the extension as a whole does not yet declare virtual-workspace support — package.json still has capabilities.virtualWorkspaces.supported: false and the language server uses Node fs. This PR does not change that; it just keeps the new reader from being the blocker if/when the rest of the extension catches up.
  • No new npm dependencies — a small line-based .gitignore -> glob converter lives in client/src/gitignore.ts.

Closes #145

Behavior

When cssPeek.respectGitignore is true:

  1. The extension reads the .gitignore at the workspace root (if any).
  2. Each non-empty, non-comment, non-negation line is converted to one or two VS Code globs (file + directory variants for bare names; directory-only when the line ends with /).
  3. Those globs are deduped against cssPeek.peekToExclude and passed as the exclude pattern to Workspace.findFiles.

Known limitations / edge cases

The converter is small and dependency-free. It explicitly skips:

  • Blank lines and comments (#...)
  • Negation lines (!pattern) — skipped to avoid accidentally including files
  • Patterns that reduce to empty after stripping a leading / or trailing /
  • Nested .gitignore files in subdirectories (only the workspace root file is read)

Other unsupported gitignore constructs are NOT detected — they pass through verbatim and may produce wrong or best-effort matches:

  • Character classes ([abc], [!a-z])
  • Escape sequences (\#, \!, \ )
  • ** placements where gitignore semantics differ from VS Code's glob semantics — common shapes (foo/**, **/foo) work, exotic ones may not

Users with complex ignore needs can set cssPeek.respectGitignore to false and manage cssPeek.peekToExclude directly.

Test plan

  • yarn build — zero TS errors
  • yarn test — 33 passing (8 new tests covering gitignoreLineToGlob + readGitignoreGlobs with a fixture .gitignore)
  • yarn lint — clean
  • Manual smoke: open a real project with dist/ containing a duplicate stylesheet and verify peek navigates to the source file, not the built copy

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings May 16, 2026 20:32
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds support for merging workspace-root .gitignore patterns into the extension’s exclude globs so Workspace.findFiles is less likely to return build artifacts / ignored outputs when indexing stylesheets.

Changes:

  • Added cssPeek.respectGitignore (default true) and merged .gitignore-derived globs into cssPeek.peekToExclude before searching.
  • Expanded default cssPeek.peekToExclude to cover common artifact directories (dist/, build/, .next/, out/, coverage/, etc.).
  • Introduced a small .gitignore line-to-VS Code glob converter with accompanying tests and a fixture .gitignore.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
client/src/extension.ts Merges .gitignore-derived exclude globs into Workspace.findFiles exclude patterns when enabled.
client/src/gitignore.ts Implements .gitignore line parsing and workspace-root .gitignore reading via vscode.workspace.fs.
package.json Adds new configuration setting and expands default exclude patterns.
tests/src/gitignore.test.ts Adds unit tests for conversion and .gitignore reading behavior.
tests/fixture/.gitignore Adds a fixture .gitignore used by the new test suite.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread package.json
Comment on lines +116 to +121
"cssPeek.respectGitignore": {
"scope": "window",
"type": "boolean",
"default": true,
"description": "When enabled, patterns from the workspace root's .gitignore are merged into cssPeek.peekToExclude so peek does not match files Git ignores. Negation (!pattern) lines and nested .gitignore files are not supported."
},
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Good catch — fixed in 98aa492. I removed the virtual-workspace claim from the PR body and from the readGitignoreGlobs doc comment, and now explicitly note that capabilities.virtualWorkspaces.supported: false and the server's Node fs usage still gate full virtual-workspace support. The .gitignore reader uses vscode.workspace.fs so it isn't the blocker, but I'm not claiming the extension supports virtual workspaces today.

Comment thread client/src/gitignore.ts Outdated
Comment on lines +8 to +15
* negation, or patterns we can't represent as a simple glob).
*
* Best-effort conversion covering common cases (directory names, file names,
* simple globs). When the line could match either a file or a directory, we
* emit both globs since VS Code globs distinguish files from folders.
*
* Known limitations: negation lines (`!pattern`), character classes, and
* patterns with `**` semantics that differ from gitignore are not handled.
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in 98aa492 (Option A — clarified the comment to match behavior). The doc now explicitly enumerates what's skipped (blank, comment, negation, empty-after-stripping) and explicitly states that unsupported constructs (character classes, escape sequences, exotic ** placements) are passed through verbatim and may produce wrong or best-effort matches. I kept the converter dependency-free rather than growing detect-and-warn logic; users with complex needs can disable cssPeek.respectGitignore and manage peekToExclude directly.

pranaygp and others added 2 commits May 16, 2026 17:44
Adds cssPeek.respectGitignore (default true) which merges the workspace
root .gitignore into peekToExclude before discovering stylesheets.

Also expands the default cssPeek.peekToExclude list with common build
artifact directories so peek doesn't surface duplicates from dist/,
build/, .next/, out/, coverage/, and .git/.

Closes #145

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The doc comments previously over-promised: they implied unsupported
gitignore constructs would be detected and skipped, and that this file
working in virtual workspaces meant the extension as a whole did. Neither
is true. Update the comments to accurately describe what is skipped vs.
passed through, and to note that virtual-workspace support is not
declared at the extension level.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@pranaygp pranaygp force-pushed the worktree-agent-a5eebbbaf10c319b0 branch from 98aa492 to 06f123e Compare May 17, 2026 00:45
@pranaygp pranaygp merged commit 827c266 into master May 17, 2026
2 checks passed
@pranaygp pranaygp deleted the worktree-agent-a5eebbbaf10c319b0 branch May 17, 2026 00:46
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.

peek to exclude, ignore gitignore files by defualt

2 participants