feat(files): move workspace indexing and search to native for saf/files#2529
feat(files): move workspace indexing and search to native for saf/files#2529bajrangCoder wants to merge 4 commits into
Conversation
Greptile SummaryThis PR moves workspace file indexing and project-wide search for SAF and
Confidence Score: 5/5Safe to merge; the native indexing path is well-guarded by availability checks and falls back gracefully for non-native providers. The architectural split between native and JS providers is cleanly implemented. The Java Job.cancel()/setSignal() protocol is correct under concurrent access thanks to volatile fields and a post-assignment if (cancelled) guard. SQL inputs are fully parameterised. The rAF drain pipeline in searchInFiles carries proper version guards so stale batches are discarded safely. All observations are style-level with no impact on correctness. Files Needing Attention: WorkspaceIndex.java is the most complex file; the batch-clear loop and the Termux ~/storage exclusion regex are worth a second read, but neither introduces a defect. Important Files Changed
Sequence DiagramsequenceDiagram
participant UI as WebView (JS)
participant FI as fileIndex.js
participant CB as Cordova Bridge
participant WI as WorkspaceIndex.java
participant DB as SQLite DB
Note over UI,DB: Workspace open (SAF / file://)
UI->>FI: scan(root)
FI->>CB: "sdcard.workspaceScan({id, rootUrl, ...})"
CB->>WI: scan(options, callback)
WI->>DB: beginTransaction / INSERT files
WI-->>CB: event type done
CB-->>FI: resolve(event)
FI-->>UI: Promise resolves
Note over UI,DB: Quick Open (findFile palette)
UI->>FI: "query({roots, text, limit})"
FI->>CB: sdcard.workspaceQuery(options)
CB->>WI: query(options, callback)
WI->>DB: SELECT files WHERE name LIKE ?
DB-->>WI: Cursor (paginated)
WI-->>CB: "{entries[], cursor, hasMore}"
CB-->>FI: resolve(result)
FI-->>UI: entries[]
Note over UI,DB: Project-wide search
UI->>CB: "sdcard.workspaceSearch({roots, batchResults:true})"
CB->>WI: search(options, callback)
WI->>DB: mergeIndexedFiles(roots)
WI->>WI: searchInContent per file
WI-->>CB: event type search-results data:[...]
CB-->>UI: enqueueNativeSearchResults(batch, version)
UI->>UI: "rAF drain -> appendSearchResult x4/frame"
WI-->>CB: event type done-searching
CB-->>UI: finishSearchTask(version)
Reviews (2): Last reviewed commit: "Merge branch 'main' into feat/native-wor..." | Re-trigger Greptile |
- incrementally update native workspace indexes - stop nested folder creation from refreshing every workspace - serialize index writes and fix scan cancellation ownership - keep FileTree state synchronized after copy and move operations - insert new sidebar entries without rebuilding expanded directories
Summary
Moves file indexing and project-wide search for SAF and
file://workspaces to the Android native layer.This prevents large workspaces, such as Termux home, from creating a complete file tree in the WebView.
Changes
fileIndexplugin API.node_modules.~/storage.Breaking changes
acode.require("fileList")is deprecated.It now contains files from non-native providers only. Plugins using it for SAF or
file://workspaces must migrate to:Differences from
fileList:fileIndexis asynchronous.Treeobjects.search-resultsevents.The native index database version is also updated. Existing generated indexes will be rebuilt automatically.
Compatibility
file://: native index and search.sdcard.workspaceSearch()keeps single-result events unlessbatchResults: trueis provided.