Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions crates/frilvault-core/src/note/note_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,31 @@ impl NoteService {
})
.collect())
}

pub fn list_symbol_notes(
&mut self,
source_file: impl AsRef<Path>,
) -> FrilVaultResult<Vec<NoteView>> {
Ok(self
.list_notes(source_file)?
.into_iter()
.filter(|view| matches!(view.note.anchor, NoteAnchor::Symbol(_)))
.collect())
}

pub fn find_symbol_note(
&mut self,
source_file: impl AsRef<Path>,
symbol: &str,
) -> FrilVaultResult<Option<NoteView>> {
let symbol = symbol.to_lowercase();

Ok(self
.list_symbol_notes(source_file)?
.into_iter()
.find(|view| match &view.note.anchor {
NoteAnchor::Symbol(anchor) => anchor.name.to_lowercase() == symbol,
_ => false,
}))
}
}
75 changes: 75 additions & 0 deletions crates/frilvault-core/src/tests/note_service_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,78 @@ fn search_by_symbol_returns_empty_when_not_found() {

fs::remove_dir_all(workspace_root).unwrap();
}

#[test]
fn list_symbol_notes_returns_only_symbol_notes() {
let workspace_root =
std::env::temp_dir().join(format!("frilvault-test-{}", uuid::Uuid::new_v4()));

fs::create_dir_all(&workspace_root).unwrap();

let mut service = create_test_note_service(&workspace_root);

service
.add_note(AddNoteInput {
source_file: "src/main.rs".into(),
anchor: NoteAnchor::Line(LineAnchor { line: 1, column: 1 }),
content: "line".to_string(),
})
.unwrap();

service
.add_note(AddNoteInput {
source_file: "src/main.rs".into(),
anchor: NoteAnchor::Symbol(SymbolAnchor {
name: "main".to_string(),
kind: SymbolKind::Function,
signature: None,
line_hint: None,
}),
content: "symbol".to_string(),
})
.unwrap();

let results = service.list_symbol_notes("src/main.rs").unwrap();

assert_eq!(results.len(), 1);

match &results[0].note.anchor {
NoteAnchor::Symbol(anchor) => {
assert_eq!(anchor.name, "main");
}
_ => panic!("expected symbol note"),
}

fs::remove_dir_all(workspace_root).unwrap();
}

#[test]
fn find_symbol_note_returns_matching_symbol() {
let workspace_root =
std::env::temp_dir().join(format!("frilvault-test-{}", uuid::Uuid::new_v4()));

fs::create_dir_all(&workspace_root).unwrap();

let mut service = create_test_note_service(&workspace_root);

service
.add_note(AddNoteInput {
source_file: "src/main.rs".into(),
anchor: NoteAnchor::Symbol(SymbolAnchor {
name: "Parser".to_string(),
kind: SymbolKind::Struct,
signature: None,
line_hint: None,
}),
content: "parser note".to_string(),
})
.unwrap();

let result = service.find_symbol_note("src/main.rs", "Parser").unwrap();

assert!(result.is_some());

assert_eq!(result.unwrap().note.content, "parser note");

fs::remove_dir_all(workspace_root).unwrap();
}