assistant: Show a warning indicator when the user needs to run cargo doc
(#14262)
This PR updates the `/docs` slash command to show a warning to the user if a crate's docs cannot be indexed due to the target directory not containing docs: <img width="782" alt="Screenshot 2024-07-11 at 5 11 46 PM" src="https://github.com/user-attachments/assets/2f54f7a1-97f4-4d2d-b51f-57ba31e50a2f"> Release Notes: - N/A
This commit is contained in:
parent
c18e9aedcd
commit
906688f012
3 changed files with 68 additions and 18 deletions
|
@ -158,6 +158,11 @@ impl RustdocProvider for LocalProvider {
|
|||
) -> Result<Option<String>> {
|
||||
let mut local_cargo_doc_path = self.cargo_workspace_root.join("target/doc");
|
||||
local_cargo_doc_path.push(crate_name.as_ref());
|
||||
|
||||
if !self.fs.is_dir(&local_cargo_doc_path).await {
|
||||
bail!("docs directory for '{crate_name}' does not exist. run `cargo doc`");
|
||||
}
|
||||
|
||||
if let Some(item) = item {
|
||||
local_cargo_doc_path.push(item.url_path());
|
||||
} else {
|
||||
|
|
|
@ -57,6 +57,7 @@ pub struct IndexedDocsStore {
|
|||
provider: Box<dyn IndexedDocsProvider + Send + Sync + 'static>,
|
||||
indexing_tasks_by_package:
|
||||
RwLock<HashMap<PackageName, Shared<Task<Result<(), Arc<anyhow::Error>>>>>>,
|
||||
latest_errors_by_package: RwLock<HashMap<PackageName, Arc<str>>>,
|
||||
}
|
||||
|
||||
impl IndexedDocsStore {
|
||||
|
@ -86,9 +87,14 @@ impl IndexedDocsStore {
|
|||
database_future,
|
||||
provider,
|
||||
indexing_tasks_by_package: RwLock::new(HashMap::default()),
|
||||
latest_errors_by_package: RwLock::new(HashMap::default()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn latest_error_for_package(&self, package: &PackageName) -> Option<Arc<str>> {
|
||||
self.latest_errors_by_package.read().get(package).cloned()
|
||||
}
|
||||
|
||||
/// Returns whether the package with the given name is currently being indexed.
|
||||
pub fn is_indexing(&self, package: &PackageName) -> bool {
|
||||
self.indexing_tasks_by_package.read().contains_key(package)
|
||||
|
@ -125,16 +131,31 @@ impl IndexedDocsStore {
|
|||
}
|
||||
});
|
||||
|
||||
let index_task = async {
|
||||
let database = this
|
||||
.database_future
|
||||
.clone()
|
||||
.await
|
||||
.map_err(|err| anyhow!(err))?;
|
||||
this.provider.index(package, database).await
|
||||
let index_task = {
|
||||
let package = package.clone();
|
||||
async {
|
||||
let database = this
|
||||
.database_future
|
||||
.clone()
|
||||
.await
|
||||
.map_err(|err| anyhow!(err))?;
|
||||
this.provider.index(package, database).await
|
||||
}
|
||||
};
|
||||
|
||||
index_task.await.map_err(Arc::new)
|
||||
let result = index_task.await.map_err(Arc::new);
|
||||
match &result {
|
||||
Ok(_) => {
|
||||
this.latest_errors_by_package.write().remove(&package);
|
||||
}
|
||||
Err(err) => {
|
||||
this.latest_errors_by_package
|
||||
.write()
|
||||
.insert(package, err.to_string().into());
|
||||
}
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
})
|
||||
.shared();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue