Skip to content

Commit 8ab783c

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 d4822c2 commit 8ab783c

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

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

+10-6
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,6 @@ function createQueryElement(query, parserState, name, generics, isInGenerics) {
692692
const quadcolon = /::\s*::/.exec(path);
693693
if (path.startsWith("::")) {
694694
throw ["Paths cannot start with ", "::"];
695-
} else if (path.endsWith("::")) {
696-
throw ["Paths cannot end with ", "::"];
697695
} else if (quadcolon !== null) {
698696
throw ["Unexpected ", quadcolon[0]];
699697
}
@@ -3669,10 +3667,16 @@ class DocSearch {
36693667
return;
36703668
}
36713669

3672-
const dist = editDistance(row.normalizedName, elem.normalizedPathLast, maxEditDistance);
3673-
3674-
if (index === -1 && dist > maxEditDistance) {
3675-
return;
3670+
let dist = 0;
3671+
if (elem.pathLast === "") {
3672+
if (path_dist > 0) {
3673+
return;
3674+
}
3675+
} else {
3676+
dist = editDistance(row.normalizedName, elem.normalizedPathLast, maxEditDistance);
3677+
if (index === -1 && dist > maxEditDistance) {
3678+
return;
3679+
}
36763680
}
36773681

36783682
addIntoResults(results_others, fullId, pos, index, dist, path_dist, maxEditDistance);

tests/rustdoc-js-std/parser-errors.js

-8
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,6 @@ const PARSED = [
143143
returned: [],
144144
error: "Unexpected `:: ::`",
145145
},
146-
{
147-
query: "a::b::",
148-
elems: [],
149-
foundElems: 0,
150-
userQuery: "a::b::",
151-
returned: [],
152-
error: "Paths cannot end with `::`",
153-
},
154146
{
155147
query: ":a",
156148
elems: [],
+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)