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.
This commit is contained in:
parent
e484b3efa5
commit
8865b8c639
@ -2399,15 +2399,19 @@ function initSearch(rawSearchIndex) {
|
|||||||
* @param {boolean} isAssocType
|
* @param {boolean} isAssocType
|
||||||
*/
|
*/
|
||||||
function convertNameToId(elem, isAssocType) {
|
function convertNameToId(elem, isAssocType) {
|
||||||
if (typeNameIdMap.has(elem.normalizedPathLast) &&
|
const loweredName = elem.pathLast.toLowerCase();
|
||||||
(isAssocType || !typeNameIdMap.get(elem.normalizedPathLast).assocOnly)) {
|
if (typeNameIdMap.has(loweredName) &&
|
||||||
elem.id = typeNameIdMap.get(elem.normalizedPathLast).id;
|
(isAssocType || !typeNameIdMap.get(loweredName).assocOnly)) {
|
||||||
|
elem.id = typeNameIdMap.get(loweredName).id;
|
||||||
} else if (!parsedQuery.literalSearch) {
|
} else if (!parsedQuery.literalSearch) {
|
||||||
let match = null;
|
let match = null;
|
||||||
let matchDist = maxEditDistance + 1;
|
let matchDist = maxEditDistance + 1;
|
||||||
let matchName = "";
|
let matchName = "";
|
||||||
for (const [name, {id, assocOnly}] of typeNameIdMap) {
|
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 &&
|
if (dist <= matchDist && dist <= maxEditDistance &&
|
||||||
(isAssocType || !assocOnly)) {
|
(isAssocType || !assocOnly)) {
|
||||||
if (dist === matchDist && matchName > name) {
|
if (dist === matchDist && matchName > name) {
|
||||||
|
62
tests/rustdoc-js/underscoredtype.js
Normal file
62
tests/rustdoc-js/underscoredtype.js
Normal file
@ -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
tests/rustdoc-js/underscoredtype.rs
Normal file
8
tests/rustdoc-js/underscoredtype.rs
Normal file
@ -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…
Reference in New Issue
Block a user