Skip to content

Commit 38c6073

Browse files
committed
rustdoc search: allow queries to end in an empty path segment
fixes #129707 this can be used to show all items in a module, or all associated items for a type. currently sufferes slightly due to case insensitivity, so `Option::` will also show items in the `option::` module. it disables the checking of the last path element, otherwise only items with short names will be shown
1 parent 7028d93 commit 38c6073

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/librustdoc/html/static/js/search.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,6 @@ function createQueryElement(query, parserState, name, generics, isInGenerics) {
681681
const quadcolon = /::\s*::/.exec(path);
682682
if (path.startsWith("::")) {
683683
throw ["Paths cannot start with ", "::"];
684-
} else if (path.endsWith("::")) {
685-
throw ["Paths cannot end with ", "::"];
686684
} else if (quadcolon !== null) {
687685
throw ["Unexpected ", quadcolon[0]];
688686
}
@@ -3029,10 +3027,16 @@ class DocSearch {
30293027
return;
30303028
}
30313029

3032-
const dist = editDistance(row.normalizedName, elem.normalizedPathLast, maxEditDistance);
3033-
3034-
if (index === -1 && dist > maxEditDistance) {
3035-
return;
3030+
let dist = 0;
3031+
if (elem.pathLast === "") {
3032+
if (path_dist > 0) {
3033+
return;
3034+
}
3035+
} else {
3036+
dist = editDistance(row.normalizedName, elem.normalizedPathLast, maxEditDistance);
3037+
if (index === -1 && dist > maxEditDistance) {
3038+
return;
3039+
}
30363040
}
30373041

30383042
addIntoResults(results_others, fullId, pos, index, dist, path_dist, maxEditDistance);
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const EXPECTED = {
2+
'query': 'Option::',
3+
'others': [
4+
{ 'path': 'std::option::Option', 'name': 'get_or_insert_default' },
5+
],
6+
}

0 commit comments

Comments
 (0)