assistant: Populate /docs rustdoc
with workspace crates (#16172)
This PR makes the `/docs` slash command populate the list with all of the workspace crates when using the local rustdoc provider. The workspace crates are shown in the search results when a crate is not already indexed: <img width="577" alt="Screenshot 2024-08-13 at 2 18 39 PM" src="https://github.com/user-attachments/assets/39bee576-8e1a-4b21-a9f8-7951ebae4cc3"> These crates are shown with an `(unindexed)` suffix to convey this: <img width="570" alt="Screenshot 2024-08-13 at 2 18 45 PM" src="https://github.com/user-attachments/assets/4eeb07f7-378f-44d4-ae11-4ffe45a23964"> Release Notes: - N/A
This commit is contained in:
parent
b1a581e81b
commit
ac30ed0754
4 changed files with 61 additions and 1 deletions
|
@ -72,6 +72,9 @@ impl DocsSlashCommand {
|
|||
});
|
||||
|
||||
if let Some((fs, cargo_workspace_root)) = index_provider_deps.log_err() {
|
||||
// List the workspace crates once to prime the cache.
|
||||
LocalRustdocProvider::list_workspace_crates().ok();
|
||||
|
||||
indexed_docs_registry.register_provider(Box::new(LocalRustdocProvider::new(
|
||||
fs,
|
||||
cargo_workspace_root,
|
||||
|
@ -230,6 +233,29 @@ impl SlashCommand for DocsSlashCommand {
|
|||
}
|
||||
|
||||
let items = store.search(package).await;
|
||||
|
||||
if provider == LocalRustdocProvider::id() {
|
||||
let items = build_completions(provider.clone(), items);
|
||||
let workspace_crates = LocalRustdocProvider::list_workspace_crates()?;
|
||||
|
||||
let mut all_items = items;
|
||||
let workspace_crate_completions = workspace_crates
|
||||
.into_iter()
|
||||
.filter(|crate_name| {
|
||||
!all_items
|
||||
.iter()
|
||||
.any(|item| item.label.as_str() == crate_name.as_ref())
|
||||
})
|
||||
.map(|crate_name| ArgumentCompletion {
|
||||
label: format!("{crate_name} (unindexed)"),
|
||||
new_text: format!("{provider} {crate_name}"),
|
||||
run_command: true,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
all_items.extend(workspace_crate_completions);
|
||||
return Ok(all_items);
|
||||
}
|
||||
|
||||
if items.is_empty() {
|
||||
if provider == DocsDotRsProvider::id() {
|
||||
return Ok(std::iter::once(ArgumentCompletion {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue