1
Fork 0
Commit graph

76 commits

Author SHA1 Message Date
Michael Howell
59ba74cacb rustdoc: simplify JS search routine by not messing with lev distance
Since the sorting function accounts for an `index` field, there's not much
reason to also be applying changes to the levenshtein distance. Instead,
we can just not treat `lev` as a filter if there's already a non-sentinel
value for `index`.

This change gives slightly more weight to the index and path part, as
search criteria, than it used to. This changes some of the test cases,
but not in any obviously-"worse" way, and, in particular, substring matches
are a bigger deal than levenshtein distances (we're assuming that a typo
is less likely than someone just not typing the entire name).

Based on
https://github.com/rust-lang/rust/pull/103710#issuecomment-1296894296
2023-01-14 12:04:11 -07:00
Michael Howell
d60309b311 rustdoc: use a more evocative name for CSS/JS #titles
This renames the ID, which is only used in search results, to
`#search-tabs`. Also changes the `.count` to a span, so it doesn't need its
display mode to be overridden.
2022-12-22 18:01:46 -07:00
Guillaume Gomez
20f389db89 Add sentence when rustdoc search is running 2022-11-28 17:54:21 +01:00
Michael Howell
7b00534952 rustdoc: fix corner case in search keyboard commands 2022-11-14 13:21:08 -07:00
Michael Howell
4bd6748bb9 rustdoc: get rid of CSS/DOM div.desc span, which isn't really needed 2022-11-04 13:19:33 -07:00
Michael Howell
b30c4d1932 rustdoc: simplify search results CSS and DOM
There is a layout change caused by this commit, but it's subtle. You won't
notice it unless you're looking for it.
2022-11-04 12:40:50 -07:00
Frank Steffahn
16bcc18334 Improve crate selection on rustdoc search results page
Resolves all of issue #93240

Reproduces a similar change as #99086, but with improvements

In particular, this PR inlcludes:
* redesigning the crate-search selector so the background color matches its surroundings
* decrease the font of the dropdown menu to a reaonable size
* add a hover effect
* make the color of the arrow theme-dependent, using a surrounding div, with :after pseudo-element
  that can then be transformed using CSS filters to approximate the desired color
* fix the text "in" to match the title font
* remove the "for xyz" in the "Results for xyz in [All crates]" title when
  searching for search term "xyz"; you can already see what you're searching for
  as it's typed in the search bar!
* in line with #99086, handle super-long crate names appropriately without a long <select>
  element escaping the screen area; the improvement is that we also keep the title
  within a single line now; uses some flex layout shenanigans...
* the margins / paddings are adjusted so the selected label of the <select> fits within
  the rest of that title nicely; also some inconsistency in the way that Firefox renders
  a <select> with "appearance: none" (roughly 4px more padding left and right of the text
  than e.g. Chrome) is worked around, and it now produces a result that looks (essentially)
  identical to Chrome
* the color of the help menu and settings menu border in light theme is made to match with
  the color of the corresponding buttons, like they do (match) in the ayu theme
* the casing of "All crates" changes to "all crates"
* the new tests from #99086 are temporarily disabled, until they can be adapted later
2022-08-10 15:55:26 +02:00
Michael Howell
33cf9ea4a2 Add comments, fixes for 0 sentinel 2022-06-27 14:15:14 -07:00
Michael Howell
6f9a460fef Put back, fix ()-output optimization 2022-06-27 11:21:39 -07:00
Michael Howell
8081096a7f Add documentation 2022-06-27 11:07:16 -07:00
Michael Howell
dc1fc08dc9 rustdoc: reference function signature types from the p array
This reduces the size of the function signature index, because
it's common to have many functions that operate on the same types.

    $ wc -c search-index-old.js search-index-new.js
    5224374 search-index-old.js
    3932314 search-index-new.js

By my math, this reduces the uncompressed size of the search index by 32%.
On compressed signatures, the wins are less drastic, a mere 8%:

    $ wc -c search-index-old.js.gz search-index-new.js.gz
    404532 search-index-old.js.gz
    371635 search-index-new.js.gz
2022-06-24 18:16:33 -07:00
Jacob Hoffman-Andrews
27dcebeb3e Improve loading of crates.js and sidebar-items.js
Now that the "All Crates" dropdown is only rendered on the search results page,
there is no need to load crates.js on most pages. Load it only on crate pages.
Also, add the `defer` attribute so it does not block page rendering.

For sidebar-items.js, move the script tag to `<head>`. Since it already has the
defer attribute it won't block loading. The defer attribute does preserve
ordering between scripts, so instead of the callback on load, it can set a
global variable on load, which is slightly simpler. Also, since it is required
to finish rendering the page, beginning its load earlier is better.

Remove generation and handling of sidebar-vars. Everything there can be computed
with information available in JS via other means.

Remove the "other" wrapper in the sidebar. It was unnecessary.

Remove excess script fields
2022-06-20 11:12:55 -07:00
Guillaume Gomez
5fef77d30e Remove weird JS condition 2022-06-18 20:36:42 +02:00
Guillaume Gomez
334f12c28e Add "eqeqeq" eslint rule 2022-05-27 22:30:19 +02:00
Yuki Okushi
b8dd27079c
Rollup merge of #97113 - GuillaumeGomez:search-ui-fixes, r=notriddle
Search GUI fixes

The first fix is about the duplicated "in":

![Screenshot from 2022-05-17 13-25-53](https://user-images.githubusercontent.com/3050060/168814186-a4e9064f-4325-469c-8bf6-46ea2737a24f.png)

The second fix is about the `<select>` broken style:

![Screenshot from 2022-05-17 13-37-03](https://user-images.githubusercontent.com/3050060/168814182-b1c5ae66-d8cf-4fd5-a227-5aa8cd8453ab.png)
![Screenshot from 2022-05-17 13-36-55](https://user-images.githubusercontent.com/3050060/168814184-be9e56f8-fad4-477c-899e-9abff4d4910c.png)

You can test it [here](https://rustdoc.crud.net/imperio/search-ui-fixes/doc/foo/index.html?search=test).

r? `@notriddle`
2022-05-18 07:41:00 +09:00
Jacob Hoffman-Andrews
453979462a rustdoc: make search.js a module
Previously, search.js relied on the DOM and the `window` object. It can now be
loaded in the absence of the DOM, for instance by Node. The same is true of
search-index.js.

This allows removing a lot of code from src/tools/rustdoc-js/tester.js that
tried to parse search.js and extract specific functions that were needed for
testing.
2022-05-17 09:26:18 -07:00
Guillaume Gomez
d765b73a01 Fix duplicated "in" in the search result text 2022-05-17 13:15:49 +02:00
Guillaume Gomez
5d84c0c569 Add new eslint rule about brace style 2022-05-15 13:59:51 +02:00
Michael Howell
d3fd6bfd30 rustdoc: fix GUI crash when searching for magic JS property values 2022-05-12 14:15:31 -07:00
Yuki Okushi
d34915f691
Rollup merge of #96879 - notriddle:notriddle/search-ranking, r=GuillaumeGomez
rustdoc: search result ranking fix

# Before

![image](https://user-images.githubusercontent.com/1593513/167477286-91049761-67f9-4a73-8fb7-09dbb19ca76c.png)

# After

![image](https://user-images.githubusercontent.com/1593513/167477345-6733bc0f-4bb2-4625-9f7f-094031e36414.png)
2022-05-11 00:09:35 +09:00
Michael Howell
360d6e4b7d rustdoc: search result ranking fix 2022-05-09 11:49:05 -07:00
Michael Howell
521d2c3d3c Remove unused param from search.js::checkPath 2022-05-08 22:19:40 -07:00
Guillaume Gomez
14897180ae Enforce quote rule for JS source code 2022-05-07 20:50:55 +02:00
Folyd
a8ede1248d Change eslint rules from configuration comments to configuration files 2022-05-07 11:47:30 +08:00
Guillaume Gomez
93b86d69b6
Rollup merge of #96748 - GuillaumeGomez:reexports-in-search, r=notriddle
Fixes reexports in search

Fixes #96681.

At some point we stopped reexporting items in search so this PR fixes it.

It also adds a regression test.

r? ```@notriddle```
2022-05-06 20:05:41 +02:00
Guillaume Gomez
fcb0bce25c
Rollup merge of #96590 - notriddle:notriddle/tab-bar-fn-search, r=GuillaumeGomez,jsha
rustdoc: when running a function-signature search, tweak the tab bar

# Before

![In Names (7) / In Parameters (0) / In Return types (0)](https://user-images.githubusercontent.com/1593513/166122875-ffdeafe6-8d4d-4e61-84a6-f5986b50ac35.png)

# After

![In Function Signature (7)](https://user-images.githubusercontent.com/1593513/166122883-9a3d7515-3235-4ee3-8c4b-5401d109e099.png)
2022-05-06 20:05:38 +02:00
Guillaume Gomez
279dee5374 Fix reexports missing from the search index 2022-05-06 13:52:21 +02:00
Michael Howell
4c183cd2d4 rustdoc: fix JS error when rendering parse error 2022-05-05 09:39:47 -07:00
Michael Howell
8b2147b497 rustdoc: fix keyboard shortcuts and console log on search page 2022-05-05 09:39:45 -07:00
Michael Howell
21a121332b rustdoc: change the "In Function Signatures" to context-sensitive
* If it's just `-> a`, use "In Function Return Types"
* If it's just `a b`, use "In Function Parameters"
* Otherwise, still use "In Function Signatures"
2022-05-05 09:37:29 -07:00
Michael Howell
6c8a2d4715 rustdoc: when running a function-signature search, tweak the tab bar 2022-05-05 09:37:29 -07:00
Guillaume Gomez
1e204ddb3b Use "strict" mode in JS scripts 2022-05-05 11:07:14 +02:00
Folyd
67ebeea7a0 Move callback to the () => {} syntax.
Fix lint

Fix main.js

Restore anonymous functions

Fix

Fix more
2022-05-04 11:10:48 +08:00
Guillaume Gomez
9625ed8be7 Move settings into full JS 2022-04-30 13:12:41 +02:00
Dylan DPC
bfb13ec691
Rollup merge of #96390 - GuillaumeGomez:es6-part2, r=notriddle
Switch JS code to ES6 - part 2

Part of #93058.

It's based on https://github.com/rust-lang/rust/pull/96361 so it needs to wait for it to be merged first.

r? `@notriddle`
2022-04-29 23:54:37 +02:00
Guillaume Gomez
ae93e6e3b8 Small JS code improvements 2022-04-26 20:59:32 +02:00
Guillaume Gomez
45cdb2be10 Update rustdoc search parser to handle ! correctly 2022-04-26 20:57:45 +02:00
Guillaume Gomez
4280c816fa Update search.js to ES6 2022-04-24 15:36:02 +02:00
Guillaume Gomez
4d26bde4f0 Extend handleSingleArg documentation 2022-04-20 21:11:39 +02:00
Guillaume Gomez
8d0e10cfbe Correctly handle single : 2022-04-18 23:11:42 +02:00
Guillaume Gomez
299e8ee25e Add an extra check over filter type 2022-04-18 21:43:19 +02:00
Guillaume Gomez
d7d538a8c4 Fix some corner cases 2022-04-18 20:59:09 +02:00
Guillaume Gomez
6f35475ba5 Parse idents the same way in both quote string elements and "normal" elements 2022-04-18 20:59:09 +02:00
Guillaume Gomez
a6051c76db Remove unnecessary elem.name.length === 0 since the rustdoc search eBNF does not allow elements without a name 2022-04-18 20:59:09 +02:00
Guillaume Gomez
51b4005003 Update the eBNF to allow generics bracket to not be closed if it's EOF 2022-04-18 20:59:09 +02:00
Guillaume Gomez
e03a950747 Handle separators in their own functions and fix missing handling of tabs 2022-04-18 20:59:09 +02:00
Guillaume Gomez
da829d8d9d Improve the BNF description a bit and fix some issues 2022-04-18 20:59:09 +02:00
Guillaume Gomez
1f5c4c2b30 Forbid rustdoc search query to end with -> 2022-04-18 20:59:09 +02:00
Guillaume Gomez
8e29ed43d9 Add isIdentCharacter function to ensure that unexpected characters are handled correctly 2022-04-18 20:59:09 +02:00
Guillaume Gomez
f9251eef68 Replace unneeded use of regex with a simple if 2022-04-18 20:59:09 +02:00