fix(core): match ls ignore globs by relative path#28247
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the file listing tool's ignore logic to better handle complex directory structures. By transitioning to Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
|
📊 PR Size: size/M
|
🛑 Action Required: Evaluation ApprovalSteering changes have been detected in this PR. To prevent regressions, a maintainer must approve the evaluation run before this PR can be merged. Maintainers:
Once approved, the evaluation results will be posted here automatically. |
There was a problem hiding this comment.
Code Review
This pull request updates the LSTool to support workspace-relative and globstar ignore patterns by integrating picomatch and matching against relative paths. While the new functionality is well-tested, compiling the glob patterns with picomatch inside the loop for every file is inefficient. It is recommended to compile and cache these matchers on the invocation instance to avoid performance degradation in directories with many files.
| for (const pattern of patterns) { | ||
| // Convert glob pattern to RegExp | ||
| const regexPattern = pattern | ||
| .replace(/[.+^${}()|[\]\\]/g, '\\$&') | ||
| .replace(/\*/g, '.*') | ||
| .replace(/\?/g, '.'); | ||
| const regex = new RegExp(`^${regexPattern}$`); | ||
| if (regex.test(filename)) { | ||
| const normalizedPattern = pattern.replace(/\\/g, '/'); | ||
| const hasPathSeparator = normalizedPattern.includes('/'); | ||
| const matcher = picomatch(normalizedPattern, { dot: true }); | ||
|
|
||
| if (matcher(hasPathSeparator ? normalizedPath : filename)) { | ||
| return true; | ||
| } | ||
| } |
There was a problem hiding this comment.
Compiling glob patterns with picomatch inside the loop for every single file is highly inefficient. For directories with many files, this will repeatedly parse and compile the same patterns, leading to significant performance degradation.
To optimize this, compile the matchers once and cache them on the invocation instance (this) to avoid global state and prevent race conditions in concurrent environments.
const self = this as any;
if (!self._compiledMatchers) {
self._compiledMatchers = patterns.map((pattern) => {
const normalizedPattern = pattern.replace(/\\/g, '/');
return {
hasPathSeparator: normalizedPattern.includes('/'),
matcher: picomatch(normalizedPattern, { dot: true }),
};
});
}
for (const { hasPathSeparator, matcher } of self._compiledMatchers) {
if (matcher(hasPathSeparator ? normalizedPath : filename)) {
return true;
}
}References
- Avoid module-level global variables for state like caches to prevent race conditions and memory issues in concurrent environments. Instead, use session-scoped or instance-scoped state.
|
Hi there! Thank you for your interest in contributing to Gemini CLI. To ensure we maintain high code quality and focus on our prioritized roadmap, we only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'. This PR will be closed in 7 days if it remains without that designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding. |
Summary
lsignore patterns containing path separators against workspace-relative paths instead of only basenamespicomatchso**glob patterns work as expected*.logFixes #28207
Verification
npm ci --ignore-scriptsnpx vitest run packages/core/src/tools/ls.test.ts(25 passed)npm run generatenpm run typecheck --workspace @google/gemini-cli-corenpx prettier --check packages/core/src/tools/ls.ts packages/core/src/tools/ls.test.ts