Add Code Symbols tool (#27733)
Lets you get all the code symbols in the project (like the Code Symbols panel) or in a particular file (like the Outline panel), optionally paginated and filtering results by regex. The tool gives the files, lines, and numbers of all of these, which means they can be used in conjunction with the read file tool to read subsets of large files without having to open the entire large file and poke around in it. <img width="621" alt="Screenshot 2025-03-29 at 12 00 21 PM" src="https://github.com/user-attachments/assets/d78259d7-2746-44c0-ac18-2e21f2505c0a" /> Release Notes: - N/A
This commit is contained in:
parent
5b2adfbb50
commit
9b40770e9f
9 changed files with 592 additions and 9 deletions
|
@ -28,7 +28,7 @@ pub struct PathSearchToolInput {
|
|||
/// Optional starting position for paginated results (0-based).
|
||||
/// When not provided, starts from the beginning.
|
||||
#[serde(default)]
|
||||
pub offset: Option<usize>,
|
||||
pub offset: u32,
|
||||
}
|
||||
|
||||
const RESULTS_PER_PAGE: usize = 50;
|
||||
|
@ -73,7 +73,7 @@ impl Tool for PathSearchTool {
|
|||
cx: &mut App,
|
||||
) -> Task<Result<String>> {
|
||||
let (offset, glob) = match serde_json::from_value::<PathSearchToolInput>(input) {
|
||||
Ok(input) => (input.offset.unwrap_or(0), input.glob),
|
||||
Ok(input) => (input.offset, input.glob),
|
||||
Err(err) => return Task::ready(Err(anyhow!(err))),
|
||||
};
|
||||
|
||||
|
@ -116,10 +116,10 @@ impl Tool for PathSearchTool {
|
|||
matches.sort();
|
||||
|
||||
let total_matches = matches.len();
|
||||
let response = if total_matches > offset + RESULTS_PER_PAGE {
|
||||
let paginated_matches: Vec<_> = matches
|
||||
let response = if total_matches > RESULTS_PER_PAGE + offset as usize {
|
||||
let paginated_matches: Vec<_> = matches
|
||||
.into_iter()
|
||||
.skip(offset)
|
||||
.skip(offset as usize)
|
||||
.take(RESULTS_PER_PAGE)
|
||||
.collect();
|
||||
|
||||
|
@ -127,7 +127,7 @@ impl Tool for PathSearchTool {
|
|||
"Found {} total matches. Showing results {}-{} (provide 'offset' parameter for more results):\n\n{}",
|
||||
total_matches,
|
||||
offset + 1,
|
||||
offset + paginated_matches.len(),
|
||||
offset as usize + paginated_matches.len(),
|
||||
paginated_matches.join("\n")
|
||||
)
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue