Monorepo for Tangled tangled.org

web/search: suggest lang, file and case qualifiers in the repo search bar #4721

Open tomplanche.com
targeting master from tomplanche.com/core:web/repo-search-qualifiers
Open opened by and assigned to tomplanche.com
targeting master from tomplanche.com/core:web/repo-search-qualifiers

Closes #4719.

I was surprised that the search bar on a repository's search page (/<owner>/<repo>/search) was a plain text field while the one on /search suggests the language:, author: and sort: qualifiers and their values as you type. And its empty state tells the user to narrow the search with lang:go, file:readme or case:yes.

This PR gives the repository search bar the same behavior.

Changes #

  • web/src/lib/codeQuery.ts: new CODE_DIALECT for the zoekt qualifiers of the empty state, on the model of REPO_DIALECT.
    • lang: suggests the same languages as language:, the popular ones first.
    • file: is suggested as a key. Its value is a free path pattern, so it has no value list.
    • case: suggests yes, no and auto, and marks any other value as invalid.
    • A qualifier without a value is marked as invalid, as in the other dialects.
  • web/src/lib/repoQuery.ts: export LANGUAGE_OPTIONS so that both dialects share the list.
  • web/src/lib/components/search/CodeSearchView.svelte: in the repository scope, use TicketQueryInput with CODE_DIALECT in place of SearchBar. The clear button goes back to the repository search page without ?q=. The global code search (/search?type=code) keeps its plain field.
  • web/src/lib/codeQuery.test.ts: unit tests for the known keys, the key and value suggestions, the accepted value, and the case: validation.

The query that goes to org.tangled.temp.search.searchCode does not change. Zoekt already applies these qualifiers. This change is only in the UI.

Testing #

  • pnpm test for codeQuery.test.ts and repoQuery.test.ts: 11 tests pass.
  • pnpm check: 0 errors.
  • Manual test on /tangled.org/core/search: key and value suggestions, keyboard navigation (arrows, Tab, Enter, Escape), invalid value highlight, clear button, and submit.
Commits 0