Skip to content

Fix search on Linux - #94

Merged
Tkaixiang merged 1 commit into
Tkaixiang:trunkfrom
GalileoNio:trunk
Apr 16, 2026
Merged

Tkaixiang merged 1 commit into
Tkaixiang:trunkfrom
GalileoNio:trunk

Conversation

@GalileoNio

Copy link
Copy Markdown

This PR fixes two issues that completely break the sidebar search functionality in certain scenarios. It happened on my ArchLinux, I am not sure whether it also happens on other platforms.

Fixes

1. Crash when no file is opened

File: src/renderer/src/components/sideBar/search.vue
When the search sidebar is opened without any active file, searchMatches.value is undefined. The destructuring const { selectedText } = searchMatches.value throws a TypeError, causing the search panel to fail initialization.
Fix: Use optional chaining: searchMatches.value?.selectedText.

2. Ripgrep errors aborting the entire search

File: src/renderer/src/node/ripgrepSearcher.js
When ripgrep encounters permission-denied files or broken symlinks, it exits with code 2. The current implementation rejects the whole promise on code > 1, discarding all valid results found in accessible files. Additionally, non-JSON lines in stdout (e.g., warning messages mixed into output in some environments) can cause unhandled JSON.parse exceptions.
Fixes:

  • Wrap each stdout line in try/catch to skip unparseable output.
  • Handle the remaining output buffer in the close event so the last line isn't lost.
  • Do not reject on exit code 2; instead, log the stderr as a warning and resolve with whatever results were already found.

@GalileoNio GalileoNio changed the title Fix search in Linux Fix search on Linux Apr 16, 2026
@Tkaixiang
Tkaixiang requested a review from Copilot April 16, 2026 10:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses Linux-specific breakages in the sidebar “Find in Folder” search by preventing a crash when no editor file is active and by making ripgrep-based search more resilient to partial filesystem read errors and non-JSON stdout output.

Changes:

  • Prevents a TypeError in the search sidebar when no file is open by avoiding destructuring on undefined.
  • Improves ripgrep search robustness by tolerating exit code 2, skipping unparseable stdout lines, and processing any remaining stdout buffer on process close.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/renderer/src/node/ripgrepSearcher.js Makes ripgrep searching tolerant of partial errors and non-JSON stdout, and processes leftover buffered output.
src/renderer/src/components/sideBar/search.vue Avoids crashing search sidebar initialization when there is no active file selection.

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

@Tkaixiang

Copy link
Copy Markdown
Owner

lgtm, thanks for this :)

@Tkaixiang
Tkaixiang merged commit e2bfdae into Tkaixiang:trunk Apr 16, 2026
4 checks passed
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.

3 participants