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's SearchFilesByContent, which is a live git grep on 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:

  1. Indexing delay: there isn't one. It's git grep on the exact sha. I checked this against gitlab.com: a term that only exists on an unmerged branch returns nothing on main and 8 matching lines on that branch's commit.
  2. 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\( sends FromApi(.
  3. Mixing server and local changes: handled by the split above.

What's in here:

  • searchProjectBlobs endpoint plus the SearchBlob type in gitlab-api-client.
  • GitLabTextSearchProvider, createLineMatcher and getServerSearchTerm under vscode-extension-web-ide/src/search/, with unit tests.
  • The textSearchProvider proposal enabled (the .d.ts was already vendored).
  • A new projectWideTextSearch feature 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.json now includes the vendored vscode.proposed.*.d.ts files. 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.patch in gitlab-web-ide-vscode-fork still 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: and extension: 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. Search across unopened files

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

  1. Check out this branch, run yarn install, then yarn start:example (the example app already has projectWideTextSearch: true).
  2. Start the Web IDE against a project you know, e.g. gitlab-org/gitlab-web-ide on main, with a token.
  3. 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.
  4. 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.
  5. Delete a file and search for something only it contained. It shouldn't come back.
  6. Try the toggles: match case, whole word, and a regex like fetch\w+FromApi\(.
  7. Unit tests: yarn jest packages/vscode-extension-web-ide/src/search.
Edited by Badr Shek Salim

Merge request reports

Loading
Loading