diff options
| author | bors <bors@rust-lang.org> | 2015-08-04 19:37:50 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-08-04 19:37:50 +0000 |
| commit | eb11d65d08c3e28cfe3387eaa946d56bdc016900 (patch) | |
| tree | 25327531fda116bb94693eda878848db2f3f0d6f | |
| parent | c980aba9a88704717229da3c1ec02685333c0db2 (diff) | |
| parent | acf9d6768e93bbffce7e57de647042af7d40b33d (diff) | |
Auto merge of #27515 - Eljay:rustdoc-search, r=alexcrichton
Some small changes to (hopefully) make search more useful:
* Less strict filtering, e.g:
* searching for "fn: foo" now matches methods and trait functions as well.
* searching for types also matches primitive types.
* searching for const will also match associated constants (but there aren't any in std yet)
* Changed searching for types to use the actual keyword "type" instead of the strange C-like "typedef".
* Added const and macro to allowed keywords.
| -rw-r--r-- | src/librustdoc/html/layout.rs | 4 | ||||
| -rw-r--r-- | src/librustdoc/html/static/main.js | 34 |
2 files changed, 29 insertions, 9 deletions
diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index 18f8ce3385f..51dc8c6e477 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -113,8 +113,8 @@ r##"<!DOCTYPE html> <p> Accepted types are: <code>fn</code>, <code>mod</code>, <code>struct</code>, <code>enum</code>, - <code>trait</code>, <code>typedef</code> (or - <code>tdef</code>). + <code>trait</code>, <code>type</code>, <code>macro</code>, + and <code>const</code>. </p> <p> diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 1d2cc38b4fc..f1351893915 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -230,6 +230,28 @@ } } + function typePassesFilter(filter, type) { + // No filter + if (filter < 0) return true; + + // Exact match + if (filter === type) return true; + + // Match related items + var name = itemTypes[type]; + switch (itemTypes[filter]) { + case "constant": + return (name == "associatedconstant"); + case "fn": + return (name == "method" || name == "tymethod"); + case "type": + return (name == "primitive"); + } + + // No match + return false; + } + // quoted values mean literal search var nSearchWords = searchWords.length; if ((val.charAt(0) === "\"" || val.charAt(0) === "'") && @@ -239,7 +261,7 @@ for (var i = 0; i < nSearchWords; ++i) { if (searchWords[i] === val) { // filter type: ... queries - if (typeFilter < 0 || typeFilter === searchIndex[i].ty) { + if (typePassesFilter(typeFilter, searchIndex[i].ty)) { results.push({id: i, index: -1}); } } @@ -285,7 +307,7 @@ searchWords[j].replace(/_/g, "").indexOf(val) > -1) { // filter type: ... queries - if (typeFilter < 0 || typeFilter === searchIndex[j].ty) { + if (typePassesFilter(typeFilter, searchIndex[j].ty)) { results.push({ id: j, index: searchWords[j].replace(/_/g, "").indexOf(val), @@ -295,7 +317,7 @@ } else if ( (lev_distance = levenshtein(searchWords[j], val)) <= MAX_LEV_DISTANCE) { - if (typeFilter < 0 || typeFilter === searchIndex[j].ty) { + if (typePassesFilter(typeFilter, searchIndex[j].ty)) { results.push({ id: j, index: 0, @@ -451,11 +473,9 @@ var matches, type, query, raw = $('.search-input').val(); query = raw; - matches = query.match(/^(fn|mod|struct|enum|trait|t(ype)?d(ef)?)\s*:\s*/i); + matches = query.match(/^(fn|mod|struct|enum|trait|type|const|macro)\s*:\s*/i); if (matches) { - type = matches[1].replace(/^td$/, 'typedef') - .replace(/^tdef$/, 'typedef') - .replace(/^typed$/, 'typedef'); + type = matches[1].replace(/^const$/, 'constant'); query = query.substring(matches[0].length); } |
