diff options
| author | Mihnea Dobrescu-Balaur <mihnea@linux.com> | 2015-02-26 01:03:06 +0200 |
|---|---|---|
| committer | Mihnea Dobrescu-Balaur <mihnea@linux.com> | 2015-03-14 20:45:27 +0200 |
| commit | 7b7b938be1123631fed4e021fd3ef9562cf81b0c (patch) | |
| tree | c518135a0d0d90e440eaddf8964dd0c3cc5c4d61 /src/librustdoc/html/static | |
| parent | 880fb89bde126aa43fc348d0b93839d3d18a1f51 (diff) | |
| download | rust-7b7b938be1123631fed4e021fd3ef9562cf81b0c.tar.gz rust-7b7b938be1123631fed4e021fd3ef9562cf81b0c.zip | |
Add support to search functions by type to rustdoc.
Diffstat (limited to 'src/librustdoc/html/static')
| -rw-r--r-- | src/librustdoc/html/static/main.js | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index aac3985f0cc..64478bf7227 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -205,6 +205,33 @@ break; } } + // searching by type + } else if (val.search("->") > -1) { + var trimmer = function (s) { return s.trim(); }; + var parts = val.split("->").map(trimmer); + var input = parts[0]; + // sort inputs so that order does not matter + var inputs = input.split(",").map(trimmer).sort(); + var output = parts[1]; + + for (var i = 0; i < nSearchWords; ++i) { + var type = searchIndex[i].type; + if (!type) { + continue; + } + + // sort index inputs so that order does not matter + var typeInputs = type.inputs.map(function (input) { + return input.name; + }).sort(); + + // allow searching for void (no output) functions as well + var typeOutput = type.output ? type.output.name : ""; + if (inputs.toString() === typeInputs.toString() && + output == typeOutput) { + results.push({id: i, index: -1, dontValidate: true}); + } + } } else { // gather matching search results up to a certain maximum val = val.replace(/\_/g, ""); @@ -325,6 +352,11 @@ path = result.item.path.toLowerCase(), parent = result.item.parent; + // this validation does not make sense when searching by types + if (result.dontValidate) { + continue; + } + var valid = validateResult(name, path, split, parent); if (!valid) { result.id = -1; @@ -590,7 +622,8 @@ // (String) name, // (String) full path or empty string for previous path, // (String) description, - // (optional Number) the parent path index to `paths`] + // (Number | null) the parent path index to `paths`] + // (Object | null) the type of the function (if any) var items = rawSearchIndex[crate].items; // an array of [(Number) item type, // (String) name] @@ -615,7 +648,7 @@ var rawRow = items[i]; var row = {crate: crate, ty: rawRow[0], name: rawRow[1], path: rawRow[2] || lastPath, desc: rawRow[3], - parent: paths[rawRow[4]]}; + parent: paths[rawRow[4]], type: rawRow[5]}; searchIndex.push(row); if (typeof row.name === "string") { var word = row.name.toLowerCase(); |
