web/search: suggest lang, file and case qualifiers in the repo search bar #
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: newCODE_DIALECTfor the zoekt qualifiers of the empty state, on the model ofREPO_DIALECT.lang:suggests the same languages aslanguage:, the popular ones first.file:is suggested as a key. Its value is a free path pattern, so it has no value list.case:suggestsyes,noandauto, 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: exportLANGUAGE_OPTIONSso that both dialects share the list.web/src/lib/components/search/CodeSearchView.svelte: in the repository scope, useTicketQueryInputwithCODE_DIALECTin place ofSearchBar. 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 thecase: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 testforcodeQuery.test.tsandrepoQuery.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.