Skip to content

Commit ff0c10c

Browse files
committed
rustdoc-search: use lowercase, non-normalized name for type search
The type name ID map has underscores in its names, so the query element should have them, too.
1 parent e484b3e commit ff0c10c

File tree

2 files changed

+72
-4
lines changed

2 files changed

+72
-4
lines changed

src/librustdoc/html/static/js/search.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -2399,15 +2399,19 @@ function initSearch(rawSearchIndex) {
23992399
* @param {boolean} isAssocType
24002400
*/
24012401
function convertNameToId(elem, isAssocType) {
2402-
if (typeNameIdMap.has(elem.normalizedPathLast) &&
2403-
(isAssocType || !typeNameIdMap.get(elem.normalizedPathLast).assocOnly)) {
2404-
elem.id = typeNameIdMap.get(elem.normalizedPathLast).id;
2402+
const loweredName = elem.pathLast.toLowerCase();
2403+
if (typeNameIdMap.has(loweredName) &&
2404+
(isAssocType || !typeNameIdMap.get(loweredName).assocOnly)) {
2405+
elem.id = typeNameIdMap.get(loweredName).id;
24052406
} else if (!parsedQuery.literalSearch) {
24062407
let match = null;
24072408
let matchDist = maxEditDistance + 1;
24082409
let matchName = "";
24092410
for (const [name, {id, assocOnly}] of typeNameIdMap) {
2410-
const dist = editDistance(name, elem.normalizedPathLast, maxEditDistance);
2411+
const dist = Math.min(
2412+
editDistance(name, loweredName, maxEditDistance),
2413+
editDistance(name, elem.normalizedPathLast, maxEditDistance),
2414+
);
24112415
if (dist <= matchDist && dist <= maxEditDistance &&
24122416
(isAssocType || !assocOnly)) {
24132417
if (dist === matchDist && matchName > name) {

tests/rustdoc-js-std/pidt.js

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
const FILTER_CRATE = 'std';
2+
3+
const EXPECTED = [
4+
{
5+
'query': 'pid_t',
6+
'correction': null,
7+
'proposeCorrectionFrom': null,
8+
'proposeCorrectionTo': null,
9+
'others': [
10+
{ 'path': 'std::os::unix::raw', 'name': 'pid_t' },
11+
],
12+
'returned': [
13+
{ 'path': 'std::os::unix::net::SocketCred', 'name': 'set_pid' },
14+
],
15+
'returned': [
16+
{ 'path': 'std::os::unix::net::SocketCred', 'name': 'get_pid' },
17+
],
18+
},
19+
{
20+
'query': 'pidt',
21+
'correction': 'pid_t',
22+
'proposeCorrectionFrom': null,
23+
'proposeCorrectionTo': null,
24+
'others': [
25+
{ 'path': 'std::os::unix::raw', 'name': 'pid_t' },
26+
],
27+
'returned': [
28+
{ 'path': 'std::os::unix::net::SocketCred', 'name': 'set_pid' },
29+
],
30+
'returned': [
31+
{ 'path': 'std::os::unix::net::SocketCred', 'name': 'get_pid' },
32+
],
33+
},
34+
{
35+
'query': 'unix::pid_t',
36+
'correction': null,
37+
'proposeCorrectionFrom': null,
38+
'proposeCorrectionTo': null,
39+
'others': [
40+
{ 'path': 'std::os::unix::raw', 'name': 'pid_t' },
41+
],
42+
'returned': [
43+
{ 'path': 'std::os::unix::net::SocketCred', 'name': 'set_pid' },
44+
],
45+
'returned': [
46+
{ 'path': 'std::os::unix::net::SocketCred', 'name': 'get_pid' },
47+
],
48+
},
49+
{
50+
'query': 'unix::pidt',
51+
'correction': 'pid_t',
52+
'proposeCorrectionFrom': null,
53+
'proposeCorrectionTo': null,
54+
'others': [
55+
{ 'path': 'std::os::unix::raw', 'name': 'pid_t' },
56+
],
57+
'returned': [
58+
{ 'path': 'std::os::unix::net::SocketCred', 'name': 'set_pid' },
59+
],
60+
'returned': [
61+
{ 'path': 'std::os::unix::net::SocketCred', 'name': 'get_pid' },
62+
],
63+
},
64+
];

0 commit comments

Comments
 (0)