Skip to content

Commit

Permalink
Rollup merge of rust-lang#110371 - notriddle:notriddle/search-correct…
Browse files Browse the repository at this point in the history
…ions, r=GuillaumeGomez

rustdoc: restructure type search engine to pick-and-use IDs

Fixes rust-lang#110029

Preview: https://notriddle.com/rustdoc-demo-html-3/search-corrections/std/index.html?search=-%3E%20streaming

![image](https://user-images.githubusercontent.com/1593513/233494900-ae77d5b4-e395-41f8-bbac-53ee55bb4a76.png)

This change makes it so, instead of mixing string distance with type unification, function signature search works by mapping names to IDs at the start, reporting to the user any cases where it had to make corrections, and then matches with IDs when going through the items.

This only changes function searches. Name searches are left alone, and corrections are only done when there's a single item in the search query.
  • Loading branch information
Manishearth authored May 3, 2023
2 parents 84c5179 + 395840c commit 3daf40e
Show file tree
Hide file tree
Showing 6 changed files with 361 additions and 205 deletions.
4 changes: 4 additions & 0 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,10 @@ a.tooltip:hover::after {
background-color: var(--search-error-code-background-color);
}

.search-corrections {
font-weight: normal;
}

#src-sidebar-toggle {
position: sticky;
top: 0;
Expand Down
5 changes: 4 additions & 1 deletion src/librustdoc/html/static/js/externs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function initSearch(searchIndex){}
/**
* @typedef {{
* name: string,
* id: integer,
* fullPath: Array<string>,
* pathWithoutLast: Array<string>,
* pathLast: string,
Expand Down Expand Up @@ -36,6 +37,8 @@ let ParserState;
* args: Array<QueryElement>,
* returned: Array<QueryElement>,
* foundElems: number,
* literalSearch: boolean,
* corrections: Array<{from: string, to: integer}>,
* }}
*/
let ParsedQuery;
Expand Down Expand Up @@ -139,7 +142,7 @@ let FunctionSearchType;

/**
* @typedef {{
* name: (null|string),
* id: (null|number),
* ty: (null|number),
* generics: Array<FunctionType>,
* }}
Expand Down
Loading

0 comments on commit 3daf40e

Please sign in to comment.