Skip to content

Commit

Permalink
rustdoc-search: use lowercase, non-normalized name for type search
Browse files Browse the repository at this point in the history
The type name ID map has underscores in its names, so the query
element should have them, too.
  • Loading branch information
notriddle committed Jun 8, 2024
1 parent e484b3e commit d16ddb6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -2399,15 +2399,19 @@ function initSearch(rawSearchIndex) {
* @param {boolean} isAssocType
*/
function convertNameToId(elem, isAssocType) {
if (typeNameIdMap.has(elem.normalizedPathLast) &&
(isAssocType || !typeNameIdMap.get(elem.normalizedPathLast).assocOnly)) {
elem.id = typeNameIdMap.get(elem.normalizedPathLast).id;
const loweredName = elem.pathLast.toLowerCase();
if (typeNameIdMap.has(loweredName) &&
(isAssocType || !typeNameIdMap.get(loweredName).assocOnly)) {
elem.id = typeNameIdMap.get(loweredName).id;
} else if (!parsedQuery.literalSearch) {
let match = null;
let matchDist = maxEditDistance + 1;
let matchName = "";
for (const [name, {id, assocOnly}] of typeNameIdMap) {
const dist = editDistance(name, elem.normalizedPathLast, maxEditDistance);
const dist = Math.min(
editDistance(name, loweredName, maxEditDistance),
editDistance(name, elem.normalizedPathLast, maxEditDistance),
);
if (dist <= matchDist && dist <= maxEditDistance &&
(isAssocType || !assocOnly)) {
if (dist === matchDist && matchName > name) {
Expand Down
34 changes: 34 additions & 0 deletions tests/rustdoc-js-std/pidt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const FILTER_CRATE = 'std';

const EXPECTED = [
{
'query': 'pid_t',
'correction': null,
'proposeCorrectionFrom': null,
'proposeCorrectionTo': null,
'others': [
{ 'path': 'std::os::unix::raw', 'name': 'pid_t' },
],
'returned': [
{ 'path': 'std::os::unix::net::SocketCred', 'name': 'set_pid' },
],
'returned': [
{ 'path': 'std::os::unix::net::SocketCred', 'name': 'get_pid' },
],
},
{
'query': 'pidt',
'correction': 'pid_t',
'proposeCorrectionFrom': null,
'proposeCorrectionTo': null,
'others': [
{ 'path': 'std::os::unix::raw', 'name': 'pid_t' },
],
'returned': [
{ 'path': 'std::os::unix::net::SocketCred', 'name': 'set_pid' },
],
'returned': [
{ 'path': 'std::os::unix::net::SocketCred', 'name': 'get_pid' },
],
},
];

0 comments on commit d16ddb6

Please sign in to comment.