assistant: Add basic glob support for expanding items in /docs
(#14370)
This PR updates the `/docs` slash command with basic globbing support for expanding docs. A `*` can be added to the item path to signify the end of a prefix match. For example: ``` # This will match any documentation items starting with `auk::`. # In this case, it will pull in the docs for each item in the crate. /docs docs-rs auk::* # This will match any documentation items starting with `auk::visitor::`, # which will pull in docs for the `visitor` module. /docs docs-rs auk::visitor::* ``` https://github.com/user-attachments/assets/5e1e21f1-241b-483f-9cd1-facc3aa76365 Release Notes: - N/A
This commit is contained in:
parent
fe3fe945a9
commit
3deb000f70
2 changed files with 70 additions and 20 deletions
|
@ -103,6 +103,15 @@ impl IndexedDocsStore {
|
|||
.await
|
||||
}
|
||||
|
||||
pub async fn load_many_by_prefix(&self, prefix: String) -> Result<Vec<(String, MarkdownDocs)>> {
|
||||
self.database_future
|
||||
.clone()
|
||||
.await
|
||||
.map_err(|err| anyhow!(err))?
|
||||
.load_many_by_prefix(prefix)
|
||||
.await
|
||||
}
|
||||
|
||||
pub fn index(
|
||||
self: Arc<Self>,
|
||||
package: PackageName,
|
||||
|
@ -257,6 +266,28 @@ impl IndexedDocsDatabase {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn load_many_by_prefix(&self, prefix: String) -> Task<Result<Vec<(String, MarkdownDocs)>>> {
|
||||
let env = self.env.clone();
|
||||
let entries = self.entries;
|
||||
|
||||
self.executor.spawn(async move {
|
||||
let txn = env.read_txn()?;
|
||||
let results = entries
|
||||
.iter(&txn)?
|
||||
.filter_map(|entry| {
|
||||
let (key, value) = entry.ok()?;
|
||||
if key.starts_with(&prefix) {
|
||||
Some((key, value))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
Ok(results)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn insert(&self, key: String, docs: String) -> Task<Result<()>> {
|
||||
let env = self.env.clone();
|
||||
let entries = self.entries;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue