Skip to content

Fix search case sensitivity in file search#231

Merged
wonderwhy-er merged 1 commit into
mainfrom
fix-case-sensetivity-for-file-search
Aug 29, 2025
Merged

Fix search case sensitivity in file search#231
wonderwhy-er merged 1 commit into
mainfrom
fix-case-sensetivity-for-file-search

Conversation

@wonderwhy-er

@wonderwhy-er wonderwhy-er commented Aug 29, 2025

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features
    • Added case-sensitivity control for file name searches via an ignoreCase option, aligning behavior with content searches. Improved handling of exact, glob, and substring patterns under both case-sensitive and case-insensitive modes.
  • Documentation
    • Updated search tool docs to describe the ignoreCase parameter with examples for case-sensitive and case-insensitive file searches.
  • Tests
    • Implemented explicit search session cleanup to prevent hanging sessions and consolidated test constants for consistency.

@coderabbitai

coderabbitai Bot commented Aug 29, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Updates search argument construction for file-name searches to use --iglob/--glob based on ignoreCase, while keeping -i for content searches. Adds ignoreCase to StartSearch tool documentation. Tests import and invoke handleStopSearch to clean up sessions and remove a redundant apiLimit. Exposes handleStopSearch from dist/handlers/search-handlers.js.

Changes

Cohort / File(s) Summary
Search flag handling
src/search-manager.ts
Switches file-search glob flag dynamically: --iglob when ignoreCase !== false, else --glob. Applies to exact, glob, and substring patterns. Keeps -i for content searches. Updates inline comments; root path logic unchanged.
Tool docs update
src/server.ts
Expands StartSearch tool description to document ignoreCase (default true) with examples for case-sensitive and case-insensitive file searches. No runtime changes.
Search handlers API
dist/handlers/search-handlers.js
Adds exported handleStopSearch({ sessionId }): Promise<void> for terminating a search session.
Tests and cleanup
test/test_improved_search_truncation.js
Imports handleStopSearch and calls it in a finally cleanup to stop sessions; ignores stop errors. Removes a redundant local apiLimit in favor of a single constant.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Client
  participant Server as Server (StartSearch)
  participant Manager as SearchManager
  participant RG as ripgrep

  Client->>Server: StartSearch({ query, searchType, ignoreCase })
  Server->>Manager: buildArgs(searchType, ignoreCase, pattern)
  alt searchType === "files"
    Note over Manager: Choose globFlag = ignoreCase !== false ? --iglob : --glob
    Manager->>RG: rg [globFlag pattern ...]
  else searchType === "content"
    Note over Manager: Use -i for case-insensitive content search
    Manager->>RG: rg [-i] pattern ...
  end
  RG-->>Manager: matches/none
  Manager-->>Server: results
  Server-->>Client: results
Loading
sequenceDiagram
  autonumber
  participant Test as Test Runner
  participant Search as Search Session
  participant Stop as handleStopSearch

  Test->>Search: start search and await completion
  Note over Test: finally cleanup
  Test->>Stop: handleStopSearch({ sessionId })
  Stop-->>Test: Promise resolved (errors ignored)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Refactor file search #229 — Also modifies src/search-manager.ts around ripgrep args and ignore-case handling for file searches.

Poem

I nose through globs with careful grace,
--iglob here, --glob in place.
A hop, a stop, the sessions end,
No dangling trails around the bend.
With ears attuned to case and rhyme,
I search, I clean—right on time. 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-case-sensetivity-for-file-search

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbit in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbit in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbit gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbit read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbit help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbit ignore or @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbit summary or @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbit or @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/search-manager.ts (1)

305-378: Respect maxResults for files by early-stopping the rg process

-m doesn’t limit --files. Without early termination, large trees will be scanned fully. Kill the process once collected results reach maxResults.

Add this guard in processBufferedOutput (outside this hunk):

// After incrementing totals/pushing a file result:
if (
  session.options.searchType === 'files' &&
  session.options.maxResults &&
  session.totalMatches >= session.options.maxResults &&
  !session.process.killed
) {
  try { session.process.kill('SIGTERM'); } catch {}
}

Optionally also short-circuit parsing once killed.

🧹 Nitpick comments (2)
src/server.ts (1)

321-322: Add content-mode examples mirroring files-mode

Consider adding examples for case-sensitive/insensitive content search to match the new files examples, e.g., searchType="content", pattern="README", ignoreCase=false and ignoreCase=true.

src/search-manager.ts (1)

357-368: Substring matching now applies to full paths, not just basenames

--(i)glob "*pattern*" matches anywhere in the path. If the UX promise is “file names,” this broadens scope (e.g., matches by directory names). Either (a) document that matching applies to full paths, or (b) post-filter by basename before storing results.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 036e93a and 3b027d7.

📒 Files selected for processing (3)
  • src/search-manager.ts (2 hunks)
  • src/server.ts (1 hunks)
  • test/test_improved_search_truncation.js (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/search-manager.ts (2)
src/tools/search.ts (2)
  • searchCodeFallback (149-257)
  • searchCode (16-146)
src/tools/filesystem.ts (2)
  • searchFilesNodeJS (972-1026)
  • searchFiles (905-969)
test/test_improved_search_truncation.js (3)
test/test-search-code-edge-cases.js (2)
  • teardownEdgeCases (113-141)
  • searchAndWaitForCompletion (29-66)
src/handlers/search-handlers.ts (1)
  • handleStopSearch (171-206)
test/test_search_truncation.js (1)
  • searchAndWaitForCompletion (7-44)
🔇 Additional comments (3)
src/server.ts (1)

315-315: Clarify or implement case-insensitive content filtering
The ignoreCase option currently only applies to file names—content searches still use -g (case-sensitive), so the docs are incorrect. Either switch to --iglob for content when ignoreCase !== false or update the doc to state that content filters remain case-sensitive.

src/search-manager.ts (1)

320-323: Separation of case handling is correct

Using -i for content and glob-based flags for files is sound. No issues here.

test/test_improved_search_truncation.js (1)

2-2: Good: explicit session cleanup

Importing and calling handleStopSearch prevents dangling searches. Nice addition.

Comment thread src/search-manager.ts
Comment on lines +344 to 350
// For file search: use --iglob for case-insensitive or --glob for case-sensitive
if (options.ignoreCase !== false) {
args.push('--iglob', p);
} else {
args.push('--glob', p);
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Make content-mode file filters honor ignoreCase (use --iglob/--glob)

Currently content mode uses -g (case-sensitive). Switch to --iglob/--glob to align with docs and files-mode behavior.

Apply this diff:

-        if (options.searchType === 'content') {
-          args.push('-g', p);
-        } else {
+        if (options.searchType === 'content') {
+          if (options.ignoreCase !== false) {
+            args.push('--iglob', p);
+          } else {
+            args.push('--glob', p);
+          }
+        } else {
           // For file search: use --iglob for case-insensitive or --glob for case-sensitive
           if (options.ignoreCase !== false) {
             args.push('--iglob', p);
           } else {
             args.push('--glob', p);
           }
         }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// For file search: use --iglob for case-insensitive or --glob for case-sensitive
if (options.ignoreCase !== false) {
args.push('--iglob', p);
} else {
args.push('--glob', p);
}
}
if (options.searchType === 'content') {
if (options.ignoreCase !== false) {
args.push('--iglob', p);
} else {
args.push('--glob', p);
}
} else {
// For file search: use --iglob for case-insensitive or --glob for case-sensitive
if (options.ignoreCase !== false) {
args.push('--iglob', p);
} else {
args.push('--glob', p);
}
}
🤖 Prompt for AI Agents
In src/search-manager.ts around lines 344 to 350, the content-mode file filter
currently uses the short case-sensitive -g flag; update logic to use long flags
--iglob for case-insensitive (when options.ignoreCase !== false) and --glob for
case-sensitive to match docs and files-mode behavior. Replace the '-g' usage for
content-mode filters with the conditional push of '--iglob' or '--glob' (same
predicate as files-mode) so file filter behavior honors options.ignoreCase.

@wonderwhy-er wonderwhy-er merged commit 3505d21 into main Aug 29, 2025
2 checks passed
@wonderwhy-er wonderwhy-er deleted the fix-case-sensetivity-for-file-search branch September 10, 2025 08:49
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