diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2019-03-26 22:26:36 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-03-26 22:26:36 +0100 |
| commit | f131f042c2de84e330ec006f8f70780efccc4dca (patch) | |
| tree | ad89427be4c0567f33f8d509a848985aedbc63ec /src/librustdoc/html | |
| parent | fbd34efb32b9efb574899e4335bdc8c6525ac27e (diff) | |
| parent | befe9cac910f6cf1f98b9c145bcad80be659106a (diff) | |
| download | rust-f131f042c2de84e330ec006f8f70780efccc4dca.tar.gz rust-f131f042c2de84e330ec006f8f70780efccc4dca.zip | |
Rollup merge of #59004 - GuillaumeGomez:generics-handling, r=QuietMisdreavus
[rustdoc] Improve "in parameters" search and search more generally Fixes #58230. r? @QuietMisdreavus
Diffstat (limited to 'src/librustdoc/html')
| -rw-r--r-- | src/librustdoc/html/render.rs | 42 | ||||
| -rw-r--r-- | src/librustdoc/html/static/main.js | 30 |
2 files changed, 51 insertions, 21 deletions
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index bead4c78e47..866d8fe682a 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -446,7 +446,7 @@ impl ToJson for Type { } Json::Array(data) } - None => Json::Null + None => Json::Null, } } } @@ -455,19 +455,27 @@ impl ToJson for Type { #[derive(Debug)] struct IndexItemFunctionType { inputs: Vec<Type>, - output: Option<Type>, + output: Option<Vec<Type>>, } impl ToJson for IndexItemFunctionType { fn to_json(&self) -> Json { // If we couldn't figure out a type, just write `null`. - if self.inputs.iter().chain(self.output.iter()).any(|ref i| i.name.is_none()) { + let mut iter = self.inputs.iter(); + if match self.output { + Some(ref output) => iter.chain(output.iter()).any(|ref i| i.name.is_none()), + None => iter.any(|ref i| i.name.is_none()), + } { Json::Null } else { let mut data = Vec::with_capacity(2); data.push(self.inputs.to_json()); if let Some(ref output) = self.output { - data.push(output.to_json()); + if output.len() > 1 { + data.push(output.to_json()); + } else { + data.push(output[0].to_json()); + } } Json::Array(data) } @@ -5025,20 +5033,26 @@ fn make_item_keywords(it: &clean::Item) -> String { } fn get_index_search_type(item: &clean::Item) -> Option<IndexItemFunctionType> { - let decl = match item.inner { - clean::FunctionItem(ref f) => &f.decl, - clean::MethodItem(ref m) => &m.decl, - clean::TyMethodItem(ref m) => &m.decl, - _ => return None + let (all_types, ret_types) = match item.inner { + clean::FunctionItem(ref f) => (&f.all_types, &f.ret_types), + clean::MethodItem(ref m) => (&m.all_types, &m.ret_types), + clean::TyMethodItem(ref m) => (&m.all_types, &m.ret_types), + _ => return None, }; - let inputs = decl.inputs.values.iter().map(|arg| get_index_type(&arg.type_)).collect(); - let output = match decl.output { - clean::FunctionRetTy::Return(ref return_type) => Some(get_index_type(return_type)), - _ => None + let inputs = all_types.iter().map(|arg| { + get_index_type(&arg) + }).filter(|a| a.name.is_some()).collect(); + let output = ret_types.iter().map(|arg| { + get_index_type(&arg) + }).filter(|a| a.name.is_some()).collect::<Vec<_>>(); + let output = if output.is_empty() { + None + } else { + Some(output) }; - Some(IndexItemFunctionType { inputs: inputs, output: output }) + Some(IndexItemFunctionType { inputs, output }) } fn get_index_type(clean_type: &clean::Type) -> Type { diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index fef6910f40a..aad7eb627bf 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -714,7 +714,10 @@ if (!DOMTokenList.prototype.remove) { } lev_distance = Math.min(levenshtein(obj[NAME], val.name), lev_distance); if (lev_distance <= MAX_LEV_DISTANCE) { - lev_distance = Math.min(checkGenerics(obj, val), lev_distance); + // The generics didn't match but the name kinda did so we give it + // a levenshtein distance value that isn't *this* good so it goes + // into the search results but not too high. + lev_distance = Math.ceil((checkGenerics(obj, val) + lev_distance) / 2); } else if (obj.length > GENERICS_DATA && obj[GENERICS_DATA].length > 0) { // We can check if the type we're looking for is inside the generics! var olength = obj[GENERICS_DATA].length; @@ -752,13 +755,26 @@ if (!DOMTokenList.prototype.remove) { var lev_distance = MAX_LEV_DISTANCE + 1; if (obj && obj.type && obj.type.length > OUTPUT_DATA) { - var tmp = checkType(obj.type[OUTPUT_DATA], val, literalSearch); - if (literalSearch === true && tmp === true) { - return true; + var ret = obj.type[OUTPUT_DATA]; + if (!obj.type[OUTPUT_DATA].length) { + ret = [ret]; } - lev_distance = Math.min(tmp, lev_distance); - if (lev_distance === 0) { - return 0; + for (var x = 0; x < ret.length; ++x) { + var r = ret[x]; + if (typeof r === "string") { + r = [r]; + } + var tmp = checkType(r, val, literalSearch); + if (literalSearch === true) { + if (tmp === true) { + return true; + } + continue; + } + lev_distance = Math.min(tmp, lev_distance); + if (lev_distance === 0) { + return 0; + } } } return literalSearch === true ? false : lev_distance; |
