Allow extensions to suggest packages for /docs completions (#16185)

This PR gives extensions the ability to suggest packages to show up in
`/docs` completions by default.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-08-13 16:50:57 -04:00 committed by GitHub
parent c6a1d9aa33
commit aa12ae0e3c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 64 additions and 1 deletions

View file

@ -31,7 +31,25 @@ impl IndexedDocsProvider for ExtensionIndexedDocsProvider {
}
async fn suggest_packages(&self) -> Result<Vec<PackageName>> {
Ok(Vec::new())
self.extension
.call({
let id = self.id.clone();
|extension, store| {
async move {
let packages = extension
.call_suggest_docs_packages(store, id.as_ref())
.await?
.map_err(|err| anyhow!("{err:?}"))?;
Ok(packages
.into_iter()
.map(|package| PackageName::from(package.as_str()))
.collect())
}
.boxed()
}
})
.await
}
async fn index(&self, package: PackageName, database: Arc<IndexedDocsDatabase>) -> Result<()> {

View file

@ -291,6 +291,19 @@ impl Extension {
}
}
pub async fn call_suggest_docs_packages(
&self,
store: &mut Store<WasmState>,
provider: &str,
) -> Result<Result<Vec<String>, String>> {
match self {
Extension::V010(ext) => ext.call_suggest_docs_packages(store, provider).await,
Extension::V001(_) | Extension::V004(_) | Extension::V006(_) => Err(anyhow!(
"`suggest_docs_packages` not available prior to v0.1.0"
)),
}
}
pub async fn call_index_docs(
&self,
store: &mut Store<WasmState>,