Skip to content

Commit eff2b70

Browse files
authored
Rollup merge of #132569 - lolbinarycat:rustdoc-search-path-end-empty-v2, r=notriddle
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 r? `@notriddle`
2 parents fb5bd7f + cd46ff6 commit eff2b70

3 files changed

Lines changed: 21 additions & 13 deletions

File tree

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,6 @@ function createQueryElement(query, parserState, name, generics, isInGenerics) {
692692
constquadcolon=/::\s*::/.exec(path);
693693
if(path.startsWith("::")){
694694
throw["Paths cannot start with ","::"];
695-
}elseif(path.endsWith("::")){
696-
throw["Paths cannot end with ","::"];
697695
}elseif(quadcolon!==null){
698696
throw["Unexpected ",quadcolon[0]];
699697
}
@@ -3974,18 +3972,19 @@ class DocSearch {
39743972

39753973
if(parsedQuery.foundElems===1&&!parsedQuery.hasReturnArrow){
39763974
constelem=parsedQuery.elems[0];
3977-
for(constidofthis.nameTrie.search(elem.normalizedPathLast,this.tailTable)){
3975+
// use arrow functions to preserve `this`.
3976+
consthandleNameSearch=id=>{
39783977
constrow=this.searchIndex[id];
39793978
if(!typePassesFilter(elem.typeFilter,row.ty)||
39803979
(filterCrates!==null&&row.crate!==filterCrates)){
3981-
continue;
3980+
return;
39823981
}
39833982

39843983
letpathDist=0;
39853984
if(elem.fullPath.length>1){
39863985
pathDist=checkPath(elem.pathWithoutLast,row);
39873986
if(pathDist===null){
3988-
continue;
3987+
return;
39893988
}
39903989
}
39913990

@@ -4008,9 +4007,20 @@ class DocSearch {
40084007
maxEditDistance,
40094008
);
40104009
}
4010+
};
4011+
if(elem.normalizedPathLast!==""){
4012+
constlast=elem.normalizedPathLast;
4013+
for(constidofthis.nameTrie.search(last,this.tailTable)){
4014+
handleNameSearch(id);
4015+
}
40114016
}
40124017
constlength=this.searchIndex.length;
4018+
40134019
for(leti=0,nSearchIndex=length;i<nSearchIndex;++i){
4020+
// queries that end in :: bypass the trie
4021+
if(elem.normalizedPathLast===""){
4022+
handleNameSearch(i);
4023+
}
40144024
constrow=this.searchIndex[i];
40154025
if(filterCrates!==null&&row.crate!==filterCrates){
40164026
continue;

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

Lines changed: 0 additions & 8 deletions
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: [],
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
constEXPECTED={
2+
'query': 'Option::',
3+
'others': [
4+
{'path': 'std::option::Option','name': 'get_or_insert_default'},
5+
],
6+
}

0 commit comments

Comments
 (0)