Rollup merge of #130009 - notriddle:notriddle/trailing-arrow, r=lolbinarycat,GuillaumeGomez
rustdoc-search: allow trailing `Foo ->` arg search Fixes #129710
This commit is contained in:
commit
04b4523efc
@ -41,6 +41,7 @@ let ParserState;
|
||||
* foundElems: number,
|
||||
* totalElems: number,
|
||||
* literalSearch: boolean,
|
||||
* hasReturnArrow: boolean,
|
||||
* corrections: Array<{from: string, to: integer}> | null,
|
||||
* typeFingerprint: Uint32Array,
|
||||
* error: Array<string> | null,
|
||||
|
@ -657,7 +657,7 @@ function createQueryElement(query, parserState, name, generics, isInGenerics) {
|
||||
}
|
||||
const typeFilter = parserState.typeFilter;
|
||||
parserState.typeFilter = null;
|
||||
if (name === "!") {
|
||||
if (name.trim() === "!") {
|
||||
if (typeFilter !== null && typeFilter !== "primitive") {
|
||||
throw [
|
||||
"Invalid search type: primitive never type ",
|
||||
@ -1795,6 +1795,7 @@ class DocSearch {
|
||||
// Total number of elements (includes generics).
|
||||
totalElems: 0,
|
||||
literalSearch: false,
|
||||
hasReturnArrow: false,
|
||||
error: null,
|
||||
correction: null,
|
||||
proposeCorrectionFrom: null,
|
||||
@ -1823,6 +1824,7 @@ class DocSearch {
|
||||
continue;
|
||||
} else if (c === "-" || c === ">") {
|
||||
if (isReturnArrow(parserState)) {
|
||||
query.hasReturnArrow = true;
|
||||
break;
|
||||
}
|
||||
throw ["Unexpected ", c, " (did you mean ", "->", "?)"];
|
||||
@ -1889,9 +1891,7 @@ class DocSearch {
|
||||
// Get returned elements.
|
||||
getItemsBefore(query, parserState, query.returned, "");
|
||||
// Nothing can come afterward!
|
||||
if (query.returned.length === 0) {
|
||||
throw ["Expected at least one item after ", "->"];
|
||||
}
|
||||
query.hasReturnArrow = true;
|
||||
break;
|
||||
} else {
|
||||
parserState.pos += 1;
|
||||
@ -3249,7 +3249,7 @@ class DocSearch {
|
||||
this.buildFunctionTypeFingerprint(elem, parsedQuery.typeFingerprint, fps);
|
||||
}
|
||||
|
||||
if (parsedQuery.foundElems === 1 && parsedQuery.returned.length === 0) {
|
||||
if (parsedQuery.foundElems === 1 && !parsedQuery.hasReturnArrow) {
|
||||
if (parsedQuery.elems.length === 1) {
|
||||
const elem = parsedQuery.elems[0];
|
||||
const length = this.searchIndex.length;
|
||||
|
@ -251,15 +251,6 @@ const PARSED = [
|
||||
userQuery: "ab'",
|
||||
error: "Unexpected `'` after `b` (not a valid identifier)",
|
||||
},
|
||||
{
|
||||
query: "a->",
|
||||
elems: [],
|
||||
foundElems: 0,
|
||||
original: "a->",
|
||||
returned: [],
|
||||
userQuery: "a->",
|
||||
error: "Expected at least one item after `->`",
|
||||
},
|
||||
{
|
||||
query: '"p" <a>',
|
||||
elems: [],
|
||||
|
@ -94,4 +94,72 @@ const PARSED = [
|
||||
userQuery: "-> !",
|
||||
error: null,
|
||||
},
|
||||
{
|
||||
query: "a->",
|
||||
elems: [{
|
||||
name: "a",
|
||||
fullPath: ["a"],
|
||||
pathWithoutLast: [],
|
||||
pathLast: "a",
|
||||
generics: [],
|
||||
typeFilter: -1,
|
||||
}],
|
||||
foundElems: 1,
|
||||
original: "a->",
|
||||
returned: [],
|
||||
userQuery: "a->",
|
||||
hasReturnArrow: true,
|
||||
error: null,
|
||||
},
|
||||
{
|
||||
query: "!->",
|
||||
elems: [{
|
||||
name: "never",
|
||||
fullPath: ["never"],
|
||||
pathWithoutLast: [],
|
||||
pathLast: "never",
|
||||
generics: [],
|
||||
typeFilter: 1,
|
||||
}],
|
||||
foundElems: 1,
|
||||
original: "!->",
|
||||
returned: [],
|
||||
userQuery: "!->",
|
||||
hasReturnArrow: true,
|
||||
error: null,
|
||||
},
|
||||
{
|
||||
query: "! ->",
|
||||
elems: [{
|
||||
name: "never",
|
||||
fullPath: ["never"],
|
||||
pathWithoutLast: [],
|
||||
pathLast: "never",
|
||||
generics: [],
|
||||
typeFilter: 1,
|
||||
}],
|
||||
foundElems: 1,
|
||||
original: "! ->",
|
||||
returned: [],
|
||||
userQuery: "! ->",
|
||||
hasReturnArrow: true,
|
||||
error: null,
|
||||
},
|
||||
{
|
||||
query: "primitive:!->",
|
||||
elems: [{
|
||||
name: "never",
|
||||
fullPath: ["never"],
|
||||
pathWithoutLast: [],
|
||||
pathLast: "never",
|
||||
generics: [],
|
||||
typeFilter: 1,
|
||||
}],
|
||||
foundElems: 1,
|
||||
original: "primitive:!->",
|
||||
returned: [],
|
||||
userQuery: "primitive:!->",
|
||||
hasReturnArrow: true,
|
||||
error: null,
|
||||
},
|
||||
];
|
||||
|
@ -1,6 +1,13 @@
|
||||
// exact-check
|
||||
|
||||
const EXPECTED = [
|
||||
{
|
||||
'query': '! ->',
|
||||
'others': [
|
||||
{ 'path': 'never_search', 'name': 'impossible' },
|
||||
{ 'path': 'never_search', 'name': 'box_impossible' },
|
||||
],
|
||||
},
|
||||
{
|
||||
'query': '-> !',
|
||||
'others': [
|
||||
|
Loading…
Reference in New Issue
Block a user