Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc-search: show type signature on type-driven SERP #117112

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,11 @@ details:not(.toggle) summary {
margin-bottom: .6em;
}

code, pre, a.test-arrow, .code-header {
code, pre, a.test-arrow, .code-header, .search-results .type-signature {
font-family: "Source Code Pro", monospace;
}
.docblock code, .docblock-short code {
.docblock code, .docblock-short code,
.search-results .type-signature strong {
border-radius: 3px;
padding: 0 0.125em;
}
Expand Down Expand Up @@ -681,7 +682,8 @@ ul.block, .block li {
}

.docblock code, .docblock-short code,
pre, .rustdoc.src .example-wrap {
pre, .rustdoc.src .example-wrap,
.search-results .type-signature strong {
background-color: var(--code-block-background-color);
}

Expand Down
553 changes: 434 additions & 119 deletions src/librustdoc/html/static/js/search.js

Large diffs are not rendered by default.

29 changes: 28 additions & 1 deletion src/tools/rustdoc-js/tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,35 @@ function loadSearchJS(doc_folder, resource_suffix) {

return {
doSearch: function(queryStr, filterCrate, currentCrate) {
return searchModule.execQuery(searchModule.parseQuery(queryStr), searchWords,
const results = searchModule.execQuery(searchModule.parseQuery(queryStr), searchWords,
filterCrate, currentCrate);
for (const key in results) {
if (results[key]) {
for (const resultKey in results[key]) {
if (!Object.prototype.hasOwnProperty.call(results[key], resultKey)) {
continue;
}
const entry = results[key][resultKey];
if (!entry) {
continue;
}
if (Object.prototype.hasOwnProperty.call(entry, "displayTypeSignature") &&
entry.displayTypeSignature !== null &&
entry.displayTypeSignature instanceof Array
) {
entry.displayTypeSignature.forEach((value, index) => {
if (index % 2 === 1) {
entry.displayTypeSignature[index] = "*" + value + "*";
} else {
entry.displayTypeSignature[index] = value;
}
});
entry.displayTypeSignature = entry.displayTypeSignature.join("");
}
}
}
}
return results;
},
getCorrections: function(queryStr, filterCrate, currentCrate) {
const parsedQuery = searchModule.parseQuery(queryStr);
Expand Down
12 changes: 6 additions & 6 deletions tests/rustdoc-gui/search-corrections.goml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ assert-css: (".search-corrections", {
})
assert-text: (
".search-corrections",
"Type \"notablestructwithlongnamr\" not found. Showing results for closest type name \"notablestructwithlongname\" instead."
"Type \"NotableStructWithLongNamr\" not found. Showing results for closest type name \"notablestructwithlongname\" instead."
)

// Corrections do get shown on the "In Return Type" tab.
Expand All @@ -35,7 +35,7 @@ assert-css: (".search-corrections", {
})
assert-text: (
".search-corrections",
"Type \"notablestructwithlongnamr\" not found. Showing results for closest type name \"notablestructwithlongname\" instead."
"Type \"NotableStructWithLongNamr\" not found. Showing results for closest type name \"notablestructwithlongname\" instead."
)

// Now, explicit return values
Expand All @@ -52,7 +52,7 @@ assert-css: (".search-corrections", {
})
assert-text: (
".search-corrections",
"Type \"notablestructwithlongnamr\" not found. Showing results for closest type name \"notablestructwithlongname\" instead."
"Type \"NotableStructWithLongNamr\" not found. Showing results for closest type name \"notablestructwithlongname\" instead."
)

// Now, generic correction
Expand All @@ -69,7 +69,7 @@ assert-css: (".search-corrections", {
})
assert-text: (
".search-corrections",
"Type \"notablestructwithlongnamr\" not found and used as generic parameter. Consider searching for \"notablestructwithlongname\" instead."
"Type \"NotableStructWithLongNamr\" not found and used as generic parameter. Consider searching for \"notablestructwithlongname\" instead."
)

// Now, generic correction plus error
Expand All @@ -86,7 +86,7 @@ assert-css: (".search-corrections", {
})
assert-text: (
".search-corrections",
"Type \"notablestructwithlongnamr\" not found and used as generic parameter. Consider searching for \"notablestructwithlongname\" instead."
"Type \"NotableStructWithLongNamr\" not found and used as generic parameter. Consider searching for \"notablestructwithlongname\" instead."
)

go-to: "file://" + |DOC_PATH| + "/test_docs/index.html"
Expand All @@ -102,5 +102,5 @@ assert-css: (".error", {
})
assert-text: (
".error",
"Query parser error: \"Generic type parameter notablestructwithlongnamr does not accept generic parameters\"."
"Query parser error: \"Generic type parameter NotableStructWithLongNamr does not accept generic parameters\"."
)
9 changes: 7 additions & 2 deletions tests/rustdoc-js-std/parser-ident.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const PARSED = [
{
query: "R<!>",
elems: [{
name: "r",
name: "R",
normalizedName: "r",
fullPath: ["r"],
pathWithoutLast: [],
pathLast: "r",
Expand All @@ -28,6 +29,7 @@ const PARSED = [
query: "!",
elems: [{
name: "never",
normalizedName: "never",
fullPath: ["never"],
pathWithoutLast: [],
pathLast: "never",
Expand All @@ -44,6 +46,7 @@ const PARSED = [
query: "a!",
elems: [{
name: "a",
normalizedName: "a",
fullPath: ["a"],
pathWithoutLast: [],
pathLast: "a",
Expand Down Expand Up @@ -78,6 +81,7 @@ const PARSED = [
query: "!::b",
elems: [{
name: "!::b",
normalizedName: "!::b",
fullPath: ["never", "b"],
pathWithoutLast: ["never"],
pathLast: "b",
Expand Down Expand Up @@ -126,7 +130,8 @@ const PARSED = [
pathLast: "b",
generics: [
{
name: "t",
name: "T",
normalizedName: "t",
fullPath: ["t"],
pathWithoutLast: [],
pathLast: "t",
Expand Down
6 changes: 4 additions & 2 deletions tests/rustdoc-js-std/parser-literal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ const PARSED = [
{
query: 'R<P>',
elems: [{
name: "r",
name: "R",
normalizedName: "r",
fullPath: ["r"],
pathWithoutLast: [],
pathLast: "r",
generics: [
{
name: "p",
name: "P",
normalizedName: "p",
fullPath: ["p"],
pathWithoutLast: [],
pathLast: "p",
Expand Down
16 changes: 11 additions & 5 deletions tests/rustdoc-js-std/parser-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const PARSED = [
{
query: 'A::B',
elems: [{
name: "a::b",
name: "A::B",
normalizedName: "a::b",
fullPath: ["a", "b"],
pathWithoutLast: ["a"],
pathLast: "b",
Expand All @@ -19,15 +20,17 @@ const PARSED = [
query: 'A::B,C',
elems: [
{
name: "a::b",
name: "A::B",
normalizedName: "a::b",
fullPath: ["a", "b"],
pathWithoutLast: ["a"],
pathLast: "b",
generics: [],
typeFilter: -1,
},
{
name: "c",
name: "C",
normalizedName: "c",
fullPath: ["c"],
pathWithoutLast: [],
pathLast: "c",
Expand All @@ -45,13 +48,15 @@ const PARSED = [
query: 'A::B<f>,C',
elems: [
{
name: "a::b",
name: "A::B",
normalizedName: "a::b",
fullPath: ["a", "b"],
pathWithoutLast: ["a"],
pathLast: "b",
generics: [
{
name: "f",
normalizedName: "f",
fullPath: ["f"],
pathWithoutLast: [],
pathLast: "f",
Expand All @@ -61,7 +66,8 @@ const PARSED = [
typeFilter: -1,
},
{
name: "c",
name: "C",
normalizedName: "c",
fullPath: ["c"],
pathWithoutLast: [],
pathLast: "c",
Expand Down
6 changes: 3 additions & 3 deletions tests/rustdoc-js-std/parser-returned.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ const PARSED = [
foundElems: 1,
original: "-> F<P>",
returned: [{
name: "f",
name: "F",
fullPath: ["f"],
pathWithoutLast: [],
pathLast: "f",
generics: [
{
name: "p",
name: "P",
fullPath: ["p"],
pathWithoutLast: [],
pathLast: "p",
Expand All @@ -29,7 +29,7 @@ const PARSED = [
foundElems: 1,
original: "-> P",
returned: [{
name: "p",
name: "P",
fullPath: ["p"],
pathWithoutLast: [],
pathLast: "p",
Expand Down
2 changes: 1 addition & 1 deletion tests/rustdoc-js-std/parser-slice-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const PARSED = [
pathLast: "[]",
generics: [
{
name: "d",
name: "D",
fullPath: ["d"],
pathWithoutLast: [],
pathLast: "d",
Expand Down
60 changes: 50 additions & 10 deletions tests/rustdoc-js/generics-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,61 @@ const EXPECTED = [
{
'query': 'Aaaaaaa -> u32',
'others': [
{ 'path': 'generics_impl::Aaaaaaa', 'name': 'bbbbbbb' },
{
'path': 'generics_impl::Aaaaaaa',
'name': 'bbbbbbb',
'displayTypeSignature': '*Aaaaaaa* -> *u32*'
},
],
},
{
'query': 'Aaaaaaa -> bool',
'others': [
{ 'path': 'generics_impl::Aaaaaaa', 'name': 'ccccccc' },
{
'path': 'generics_impl::Aaaaaaa',
'name': 'ccccccc',
'displayTypeSignature': '*Aaaaaaa* -> *bool*'
},
],
},
{
'query': 'Aaaaaaa -> usize',
'others': [
{ 'path': 'generics_impl::Aaaaaaa', 'name': 'read' },
{
'path': 'generics_impl::Aaaaaaa',
'name': 'read',
'displayTypeSignature': '*Aaaaaaa*, [] -> Result<*usize*>'
},
],
},
{
'query': 'Read -> u64',
'others': [
{ 'path': 'generics_impl::Ddddddd', 'name': 'eeeeeee' },
{ 'path': 'generics_impl::Ddddddd', 'name': 'ggggggg' },
{
'path': 'generics_impl::Ddddddd',
'name': 'eeeeeee',
'displayTypeSignature': 'impl *Read* -> *u64*'
},
{
'path': 'generics_impl::Ddddddd',
'name': 'ggggggg',
'displayTypeSignature': 'Ddddddd<impl *Read*> -> *u64*'
},
],
},
{
'query': 'trait:Read -> u64',
'others': [
{ 'path': 'generics_impl::Ddddddd', 'name': 'eeeeeee' },
{ 'path': 'generics_impl::Ddddddd', 'name': 'ggggggg' },
{
'path': 'generics_impl::Ddddddd',
'name': 'eeeeeee',
'displayTypeSignature': 'impl *Read* -> *u64*'
},
{
'path': 'generics_impl::Ddddddd',
'name': 'ggggggg',
'displayTypeSignature': 'Ddddddd<impl *Read*> -> *u64*'
},
],
},
{
Expand All @@ -40,19 +68,31 @@ const EXPECTED = [
{
'query': 'bool -> u64',
'others': [
{ 'path': 'generics_impl::Ddddddd', 'name': 'fffffff' },
{
'path': 'generics_impl::Ddddddd',
'name': 'fffffff',
'displayTypeSignature': '*bool* -> *u64*'
},
],
},
{
'query': 'Ddddddd -> u64',
'others': [
{ 'path': 'generics_impl::Ddddddd', 'name': 'ggggggg' },
{
'path': 'generics_impl::Ddddddd',
'name': 'ggggggg',
'displayTypeSignature': '*Ddddddd* -> *u64*'
},
],
},
{
'query': '-> Ddddddd',
'others': [
{ 'path': 'generics_impl::Ddddddd', 'name': 'hhhhhhh' },
{
'path': 'generics_impl::Ddddddd',
'name': 'hhhhhhh',
'displayTypeSignature': '-> *Ddddddd*'
},
],
},
];
Loading
Loading