feat(search): search all project files from the Search view
What does this MR do and why?
Hi everyone
Searching across the project has been the one thing I keep missing in the Web IDE. Right now Search (Ctrl+Shift+F) only finds matches in files that are already open, which surprises pretty much everyone (see #409 and &9466). I read through the history of those issues and wanted to try an approach that I think answers the concerns raised in this thread, so here it is behind a feature flag.
The idea: register a TextSearchProvider for the gitlab-web-ide scheme and split the work in two.
- Files you haven't touched are searched on the server with
GET /projects/:id/search?scope=blobs&search_type=basic&ref=<sha>. Basic blob search doesn't use Elasticsearch or Zoekt at all. It goes to Gitaly'sSearchFilesByContent, which is a livegit grepon the ref. We pin it to the commit the Web IDE opened, so results always match the file tree: no index, no lag after a push, and it works on CE. - Files you've changed in the Web IDE are searched locally, straight from the overlay file system (
SourceControlSystem.status()). Their now-stale server results are dropped, and so are results for files you deleted.
Taking the three concerns from the thread one at a time:
- Indexing delay: there isn't one. It's
git grepon the exact sha. I checked this against gitlab.com: a term that only exists on an unmerged branch returns nothing onmainand 8 matching lines on that branch's commit. - VS Code query syntax vs. backend syntax: the server returns a case-insensitive literal superset of candidate lines (Rails escapes the term before Gitaly sees it). Every candidate line is then re-checked in the browser against the real query, so regex, match case and whole word behave exactly like VS Code. For regex queries we send the longest literal the pattern requires, e.g.
fetch\w+FromApi\(sendsFromApi(. - Mixing server and local changes: handled by the split above.
What's in here:
searchProjectBlobsendpoint plus theSearchBlobtype ingitlab-api-client.GitLabTextSearchProvider,createLineMatcherandgetServerSearchTermundervscode-extension-web-ide/src/search/, with unit tests.- The
textSearchProviderproposal enabled (the.d.tswas already vendored). - A new
projectWideTextSearchfeature flag. The provider is only registered when it's on. I also switched it on in the example app so it's easy to try. tsconfig.jest.jsonnow includes the vendoredvscode.proposed.*.d.tsfiles. Without that, ts-jest couldn't see the proposed search types in the new tests.
Limits I've kept on purpose (happy to change any of them):
- At most 2 pages × 100 results per search, then VS Code shows its usual "results limited" message. The search API is rate limited (30 requests per minute by default) and every page re-runs
git grep, so this is kept small. - While the flag is on, search runs when you press Enter, not as you type (
search.searchOnType: false). If the rate limit is hit, a message asks the user to wait a minute. - Multiline search isn't supported (basic search is line based); a message says so.
- A regex with no literal text in it (like
\d+) only searches your local changes, and a message says so.
Follow-ups I'd expect, if this direction works for you:
- The fork patch
vscode-patches/web-ide/0005-feat-Provide-prompt-for-partial-search.patchingitlab-web-ide-vscode-forkstill always shows "Only results from opened files are shown…". It should be removed, or made conditional on the flag, before this is turned on for real. I'm happy to open that MR too. - Pass the flag from Rails in
gitlab-org/gitlab. - Send simple include/exclude globs to the server as
path:andextension:filters, so excluded files don't use up the 2 pages (there's a TODO in the code). - An optional "index this repository" mode (download the archive and search locally) for offline or regex-heavy use, as a separate MR.
Relates to #409
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots or screen recordings
| Before | After |
|---|---|
| Searching any term without opening files returns nothing, because only open editors are searched. | ![]() |
In the "after" screenshot no files are open. registerFileSearchProvider finds exactly the 2 matches git grep finds on that commit. The grey "Only results from opened files…" text is the fork patch mentioned above, not this MR.
How to set up and validate locally
- Check out this branch, run
yarn install, thenyarn start:example(the example app already hasprojectWideTextSearch: true). - Start the Web IDE against a project you know, e.g.
gitlab-org/gitlab-web-ideonmain, with a token. - Without opening any file, press Ctrl+Shift+F, type something and press Enter, e.g.
registerFileSearchProvider. You should get matches from files that aren't open. - Edit a file without committing, then search for text you just typed. The local match should appear, and the file's old server content shouldn't.
- Delete a file and search for something only it contained. It shouldn't come back.
- Try the toggles: match case, whole word, and a regex like
fetch\w+FromApi\(. - Unit tests:
yarn jest packages/vscode-extension-web-ide/src/search.
