Skip to content

Commit

Permalink
Auto merge of #59622 - GuillaumeGomez:improve-one-char-search, r=Quie…
Browse files Browse the repository at this point in the history
…tMisdreavus

Ensure that exact matches come first in rustdoc search

Fixes #59287.

cc @scottmcm

r? @QuietMisdreavus
  • Loading branch information
bors committed Apr 12, 2019
2 parents 2226c09 + 1907367 commit 876a3bc
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -930,10 +930,10 @@ if (!DOMTokenList.prototype.remove) {
returned = checkReturned(ty, output, true);
if (output.name === "*" || returned === true) {
in_args = false;
var module = false;
var is_module = false;

if (input === "*") {
module = true;
is_module = true;
} else {
var allFound = true;
for (var it = 0; allFound === true && it < inputs.length; it++) {
Expand All @@ -955,7 +955,7 @@ if (!DOMTokenList.prototype.remove) {
dontValidate: true,
};
}
if (module === true) {
if (is_module === true) {
results[fullId] = {
id: i,
index: -1,
Expand Down Expand Up @@ -1073,6 +1073,10 @@ if (!DOMTokenList.prototype.remove) {
if (index !== -1 || lev <= MAX_LEV_DISTANCE) {
if (index !== -1 && paths.length < 2) {
lev = 0;
} else if (searchWords[j] === val) {
// Small trick to fix when you're looking for a one letter type
// and there are other short named types.
lev = -1;
}
if (results[fullId] === undefined) {
results[fullId] = {
Expand Down
8 changes: 8 additions & 0 deletions src/test/rustdoc-js/search-short-types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const QUERY = 'P';

const EXPECTED = {
'others': [
{ 'path': 'search_short_types', 'name': 'P' },
{ 'path': 'search_short_types', 'name': 'Ap' },
],
};
68 changes: 68 additions & 0 deletions src/test/rustdoc-js/search-short-types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
macro_rules! imp {
($name:ident) => {
pub struct $name {
pub op: usize,
}
impl $name {
pub fn op() {}
pub fn cmp() {}
pub fn map() {}
pub fn pop() {}
pub fn ptr() {}
pub fn rpo() {}
pub fn drop() {}
pub fn copy() {}
pub fn zip() {}
pub fn sup() {}
pub fn pa() {}
pub fn pb() {}
pub fn pc() {}
pub fn pd() {}
pub fn pe() {}
pub fn pf() {}
pub fn pg() {}
pub fn ph() {}
pub fn pi() {}
pub fn pj() {}
pub fn pk() {}
pub fn pl() {}
pub fn pm() {}
pub fn pn() {}
pub fn po() {}
}
};
($name:ident, $($names:ident),*) => {
imp!($name);
imp!($($names),*);
};
}
macro_rules! en {
($name:ident) => {
pub enum $name {
Ptr,
Rp,
Rpo,
Pt,
Drop,
Dr,
Dro,
Sup,
Op,
Cmp,
Map,
Mp,
}
};
($name:ident, $($names:ident),*) => {
en!($name);
en!($($names),*);
};
}

imp!(Ot, Foo, Cmp, Map, Loc, Lac, Toc, Si, Sig, Sip, Psy, Psi, Py, Pi, Pa, Pb, Pc, Pd);
imp!(Pe, Pf, Pg, Ph, Pj, Pk, Pl, Pm, Pn, Po, Pq, Pr, Ps, Pt, Pu, Pv, Pw, Px, Pz, Ap, Bp, Cp);
imp!(Dp, Ep, Fp, Gp, Hp, Ip, Jp, Kp, Lp, Mp, Np, Op, Pp, Qp, Rp, Sp, Tp, Up, Vp, Wp, Xp, Yp, Zp);

en!(Place, Plac, Plae, Plce, Pace, Scalar, Scalr, Scaar, Sclar, Salar);

pub struct P;

0 comments on commit 876a3bc

Please sign in to comment.