feat(client): respect .gitignore + better exclude defaults (#145)#164
Conversation
There was a problem hiding this comment.
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(defaulttrue) and merged.gitignore-derived globs intocssPeek.peekToExcludebefore searching. - Expanded default
cssPeek.peekToExcludeto cover common artifact directories (dist/,build/,.next/,out/,coverage/, etc.). - Introduced a small
.gitignoreline-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.
| "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." | ||
| }, |
There was a problem hiding this comment.
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.
| * 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. |
There was a problem hiding this comment.
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.
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>
98aa492 to
06f123e
Compare
Summary
cssPeek.respectGitignoresetting (defaulttrue) that reads the workspace root.gitignoreand merges its patterns intocssPeek.peekToExcludebefore callingWorkspace.findFiles.cssPeek.peekToExcludeto also cover common build artifact directories:**/.git/**,**/dist/**,**/build/**,**/.next/**,**/out/**,**/coverage/**..gitignoreviavscode.workspace.fs.readFile(no new Nodefsdependency added on the client). Note: the extension as a whole does not yet declare virtual-workspace support —package.jsonstill hascapabilities.virtualWorkspaces.supported: falseand the language server uses Nodefs. 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..gitignore-> glob converter lives inclient/src/gitignore.ts.Closes #145
Behavior
When
cssPeek.respectGitignoreistrue:.gitignoreat the workspace root (if any)./).cssPeek.peekToExcludeand passed as the exclude pattern toWorkspace.findFiles.Known limitations / edge cases
The converter is small and dependency-free. It explicitly skips:
#...)!pattern) — skipped to avoid accidentally including files/or trailing/.gitignorefiles 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:
[abc],[!a-z])\#,\!,\)**placements where gitignore semantics differ from VS Code's glob semantics — common shapes (foo/**,**/foo) work, exotic ones may notUsers with complex ignore needs can set
cssPeek.respectGitignoretofalseand managecssPeek.peekToExcludedirectly.Test plan
yarn build— zero TS errorsyarn test— 33 passing (8 new tests coveringgitignoreLineToGlob+readGitignoreGlobswith a fixture.gitignore)yarn lint— cleandist/containing a duplicate stylesheet and verify peek navigates to the source file, not the built copy🤖 Generated with Claude Code