Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc-search: use lowercase, non-normalized name for type search #126176

Merged
merged 1 commit into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
62 changes: 62 additions & 0 deletions tests/rustdoc-js/underscoredtype.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const EXPECTED = [
{
'query': 'pid_t',
'correction': null,
'proposeCorrectionFrom': null,
'proposeCorrectionTo': null,
'others': [
{ 'path': 'underscoredtype::unix', 'name': 'pid_t' },
],
'returned': [
{ 'path': 'underscoredtype::unix', 'name': 'set_pid' },
],
'returned': [
{ 'path': 'underscoredtype::unix', 'name': 'get_pid' },
],
},
{
'query': 'pidt',
'correction': 'pid_t',
'proposeCorrectionFrom': null,
'proposeCorrectionTo': null,
'others': [
{ 'path': 'underscoredtype::unix', 'name': 'pid_t' },
],
'returned': [
{ 'path': 'underscoredtype::unix', 'name': 'set_pid' },
],
'returned': [
{ 'path': 'underscoredtype::unix', 'name': 'get_pid' },
],
},
{
'query': 'unix::pid_t',
'correction': null,
'proposeCorrectionFrom': null,
'proposeCorrectionTo': null,
'others': [
{ 'path': 'underscoredtype::unix', 'name': 'pid_t' },
],
'returned': [
{ 'path': 'underscoredtype::unix', 'name': 'set_pid' },
],
'returned': [
{ 'path': 'underscoredtype::unix', 'name': 'get_pid' },
],
},
{
'query': 'unix::pidt',
'correction': 'pid_t',
'proposeCorrectionFrom': null,
'proposeCorrectionTo': null,
'others': [
{ 'path': 'underscoredtype::unix', 'name': 'pid_t' },
],
'returned': [
{ 'path': 'underscoredtype::unix', 'name': 'set_pid' },
],
'returned': [
{ 'path': 'underscoredtype::unix', 'name': 'get_pid' },
],
},
];
8 changes: 8 additions & 0 deletions tests/rustdoc-js/underscoredtype.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pub mod unix {
#[allow(non_camel_case_types)]
pub type pid_t = i32;
pub fn get_pid() -> pid_t {
0
}
pub fn set_pid(_: pid_t) {}
}
Loading