Promote package suggestions to a first-class concept on IndexedDocsProviders (#16177)

This PR promotes package suggestions to a first-class concept on the
`IndexedDocsProvider` trait.

This will allow any implementer of `IndexedDocsProvider` to provide a
list of package names to suggest for use with `/docs`.

For the docs.rs provider we use the 250 most popular Rust crates (as
identified [here](https://lib.rs/std)), and for the rustdoc provider we
use the packages in the Cargo workspace.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-08-13 16:01:58 -04:00 committed by GitHub
parent bd71e9192c
commit a81e355dc5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 328 additions and 93 deletions

View file

@ -39,6 +39,13 @@ pub trait IndexedDocsProvider {
/// Returns the path to the database for this provider.
fn database_path(&self) -> PathBuf;
/// Returns a list of packages as suggestions to be included in the search
/// results.
///
/// This can be used to provide completions for known packages (e.g., from the
/// local project or a registry) before a package has been indexed.
async fn suggest_packages(&self) -> Result<Vec<PackageName>>;
/// Indexes the package with the given name.
async fn index(&self, package: PackageName, database: Arc<IndexedDocsDatabase>) -> Result<()>;
}
@ -122,6 +129,12 @@ impl IndexedDocsStore {
.await
}
pub fn suggest_packages(self: Arc<Self>) -> Task<Result<Vec<PackageName>>> {
let this = self.clone();
self.executor
.spawn(async move { this.provider.suggest_packages().await })
}
pub fn index(
self: Arc<Self>,
package: PackageName,