Skip to content

feat: do file-listing and index on java for file:/// and saf locations#2283

Merged
bajrangCoder merged 8 commits into
mainfrom
filelist/index-on-java-side
Jun 18, 2026
Merged

feat: do file-listing and index on java for file:/// and saf locations#2283
bajrangCoder merged 8 commits into
mainfrom
filelist/index-on-java-side

Conversation

@bajrangCoder

@bajrangCoder bajrangCoder commented Jun 17, 2026

Copy link
Copy Markdown
Member
  • do file listing, indexing(if asked) on native java side for file:/// and saf location to improve the search speed and ui smoothness even searching in big projects on lower end devices
  • improve getSurrounding to show meaning full snippet in search
  • tweaked ui a bit for nicer ux
  • show progress and status when searching
  • improve binary detection

- add cap on file size
- fix issue with include file and its cap
- improve getSurrounding to show meaning full snippet
- tweaked ui a bit for nicer ux
- show progress and status when searching
- improve binary detection
@bajrangCoder bajrangCoder marked this pull request as ready for review June 18, 2026 06:41
@greptile-apps

greptile-apps Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR offloads file-tree listing and search/replace to native Java (WorkspaceIndex.java) for file:/// and SAF content:// workspaces, eliminating the previous JS-worker search index in favour of a SQLite-backed cache and a Cordova bridge. UI improvements include richer match snippets, line-number gutters, and a redesigned result header.

  • WorkspaceIndex.java (~1 400 lines): new SQLite helper managing workspace scanning (files table), optional content indexing (content table), and multi-file search/replace with glob filtering, binary detection, and Cordova event streaming.
  • fileList.js / index.js: JS layer updated to route file: and content: URLs through the native scan/search path while keeping the existing worker path for other schemes; stale-job protection uses a searchVersion counter threaded through every async callback.
  • cmResultView.js / worker.js / styles.scss: display polish — full-line snippets with ellipsis, line-number prefix marks, ghost-text guard on decorations, and chevron/count repositioning.

Confidence Score: 5/5

Safe to merge; the functional logic is sound and no data-loss or correctness bugs were found.

The core scan/search flow is well-structured: the files table delete-and-repopulate is wrapped in a transaction so a mid-scan failure leaves the workspace consistent. Version-gated callbacks prevent stale native jobs from completing against a newer search. The two issues found are storage hygiene nits — orphaned content rows for deleted files accumulate between explicit clear() calls, and the unused lower_text column wastes roughly one text blob per indexed file.

src/plugins/sdcard/src/android/WorkspaceIndex.java — specifically the runScan method (content table cleanup) and indexFile (lower_text column).

Important Files Changed

Filename Overview
src/plugins/sdcard/src/android/WorkspaceIndex.java New 1,428-line file implementing native workspace scanning, indexing (SQLite), and search/replace for file:/// and SAF content:// URIs. Two minor storage issues found: content table orphaned rows accumulate on re-scan, and the lower_text column is written but never read.
src/lib/fileList.js Adds native workspace scan path via getAllFilesNative/addNativeEntries and a removeRootTree helper for cascading cleanup; excluded directory handling is consistent with the existing JS path.
src/sidebarApps/searchInFiles/index.js Replaces the JS-worker search index with native Java search; introduces activeSearchTasks/activeReplaceTasks counters, version-gated stale-event guards, and finishSearchTask/finishReplaceTask helpers. Logic appears correct for concurrent native+worker split.
src/sidebarApps/searchInFiles/worker.js Updates getSurrounding to emit full line context (up to 160 chars) with ellipsis trimming, and adds line field to match objects for display parity with native results.
src/sidebarApps/searchInFiles/cmResultView.js UI rework: chevron moved to end of header, count badge driven by fileInfo.count, ghost-text flag suppresses decorations during loading, and line-number prefix detection prevents false match highlights.
src/plugins/sdcard/src/android/SDcard.java Routes five new workspace * action strings to WorkspaceIndex; otherwise unchanged.
src/utils/binaryExtensions.js Adds textExtensionSet and isTextPath export; isBinaryFile now returns false early for known-text extensions before reaching the binary MIME check.
src/sidebarApps/searchInFiles/styles.scss Visual polish: tighter padding, line-number gutter style, chevron repositioned to right of header, striped row backgrounds replaced with border separators.
src/lib/openFolder.js Adds FileList.remove(_path) call on folder close to ensure the cascading removeRootTree cleanup runs when a workspace is removed.
src/plugins/sdcard/index.d.ts Adds TypeScript declarations for WorkspaceFileEntry, WorkspaceEvent union, and the five new SDcard workspace methods.
bun.lock Bumps dompurify, markdown-it, and linkify-it; adds a mermaid-scoped dompurify entry.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant JS as JavaScript (index.js / fileList.js)
    participant Bridge as Cordova Bridge (plugin.js)
    participant Java as WorkspaceIndex.java
    participant DB as SQLite DB

    Note over JS,DB: File-tree listing (native path)
    JS->>Bridge: workspaceScan(options, onEvent)
    Bridge->>Java: scan(options, callback)
    Java->>DB: beginTransaction / delete files
    loop per directory entry
        Java->>DB: replace into files
        Java-->>Bridge: batch event (200 entries)
        Bridge-->>JS: onEvent type batch entries
        JS->>JS: addNativeEntries(root, entries)
    end
    Java->>DB: setTransactionSuccessful / endTransaction
    Java-->>Bridge: done event
    Bridge-->>JS: onEvent type done

    Note over JS,DB: Search (native path)
    JS->>Bridge: workspaceSearch(options, onEvent)
    Bridge->>Java: search(options, callback)
    loop per file
        Java->>DB: query content if useIndex
        alt cache hit
            DB-->>Java: cached text
        else cache miss
            Java->>Java: readFileText
            Java->>DB: replace into content
        end
        Java->>Java: pattern.matcher(content)
        Java-->>Bridge: search-result event
        Bridge-->>JS: appendSearchResult(data)
    end
    Java-->>Bridge: done-searching event
    Bridge-->>JS: finishSearchTask(version)
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant JS as JavaScript (index.js / fileList.js)
    participant Bridge as Cordova Bridge (plugin.js)
    participant Java as WorkspaceIndex.java
    participant DB as SQLite DB

    Note over JS,DB: File-tree listing (native path)
    JS->>Bridge: workspaceScan(options, onEvent)
    Bridge->>Java: scan(options, callback)
    Java->>DB: beginTransaction / delete files
    loop per directory entry
        Java->>DB: replace into files
        Java-->>Bridge: batch event (200 entries)
        Bridge-->>JS: onEvent type batch entries
        JS->>JS: addNativeEntries(root, entries)
    end
    Java->>DB: setTransactionSuccessful / endTransaction
    Java-->>Bridge: done event
    Bridge-->>JS: onEvent type done

    Note over JS,DB: Search (native path)
    JS->>Bridge: workspaceSearch(options, onEvent)
    Bridge->>Java: search(options, callback)
    loop per file
        Java->>DB: query content if useIndex
        alt cache hit
            DB-->>Java: cached text
        else cache miss
            Java->>Java: readFileText
            Java->>DB: replace into content
        end
        Java->>Java: pattern.matcher(content)
        Java-->>Bridge: search-result event
        Bridge-->>JS: appendSearchResult(data)
    end
    Java-->>Bridge: done-searching event
    Bridge-->>JS: finishSearchTask(version)
Loading

Reviews (5): Last reviewed commit: "fix(search): quote native replace-all re..." | Re-trigger Greptile

Comment thread src/plugins/sdcard/src/android/WorkspaceIndex.java
Comment thread src/plugins/sdcard/src/android/WorkspaceIndex.java
@bajrangCoder

This comment was marked as outdated.

@bajrangCoder

This comment was marked as outdated.

@bajrangCoder

This comment was marked as outdated.

@bajrangCoder

This comment was marked as outdated.

@RohitKushvaha01 RohitKushvaha01 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@bajrangCoder bajrangCoder merged commit 28ac6fd into main Jun 18, 2026
10 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in The Code Board - Acode Jun 18, 2026
@bajrangCoder bajrangCoder deleted the filelist/index-on-java-side branch June 18, 2026 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants