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
25 changes: 17 additions & 8 deletions apps/frilvault-cli/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
use anyhow::Result;

use frilvault_core::{
NoteService, PathResolver, WorkspaceIndexRepository, WorkspaceRepository, WorkspaceService,
YamlNoteRepository,
NoteService, PathResolver, VaultContext, WorkspaceIndexRepository, WorkspaceRepository,
WorkspaceService, YamlNoteRepository,
};

pub fn create_note_service() -> Result<NoteService<YamlNoteRepository>> {
pub fn create_note_service() -> Result<NoteService> {
let workspace_root = std::env::current_dir()?;

let resolver = PathResolver::new(workspace_root);

let workspace_repository = WorkspaceRepository::new(resolver.clone());
workspace_repository.create_if_missing()?;

let note_repository = YamlNoteRepository::new(resolver);
let index_repository = WorkspaceIndexRepository::new(resolver.clone());
index_repository.create_if_missing()?;

let note_repository = YamlNoteRepository::new(resolver.clone());
let vault_context = VaultContext::new(note_repository, index_repository);

Ok(NoteService::new(note_repository))
Ok(NoteService::new(vault_context))
}

pub fn create_workspace_service() -> anyhow::Result<WorkspaceService> {
let workspace_root = std::env::current_dir()?;

let resolver = PathResolver::new(workspace_root);

let note_repository = YamlNoteRepository::new(resolver.clone());
let workspace_repository = WorkspaceRepository::new(resolver.clone());
workspace_repository.create_if_missing()?;

let index_repository = WorkspaceIndexRepository::new(resolver);
let index_repository = WorkspaceIndexRepository::new(resolver.clone());
index_repository.create_if_missing()?;

let note_repository = YamlNoteRepository::new(resolver);
let vault_context = VaultContext::new(note_repository, index_repository.clone());

Ok(WorkspaceService::new(note_repository, index_repository))
Ok(WorkspaceService::new(vault_context, index_repository))
}
1 change: 1 addition & 0 deletions apps/frilvault-cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ pub enum Commands {
Search(SearchCommand),
Repair(RepairCommand),
Doctor,
Health,
Stats,
}
16 changes: 14 additions & 2 deletions apps/frilvault-cli/src/cli/search.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
use clap::Args;
use clap::{Args, ValueEnum};

#[derive(Debug, Args)]
pub struct SearchCommand {
pub keyword: String,
pub keyword: Option<String>,

#[arg(long)]
pub file: Option<String>,

#[arg(long, value_enum)]
pub format: Option<SearchFormatArg>,

#[arg(long, hide = true)]
pub json: bool,
}

#[derive(Debug, Clone, ValueEnum)]
pub enum SearchFormatArg {
Text,
Json,
}
57 changes: 56 additions & 1 deletion apps/frilvault-cli/src/command/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
};

pub fn execute(command: AddCommand) -> Result<()> {
let service = create_note_service()?;
let mut service = create_note_service()?;

let anchor = create_anchor(&command)?;

Expand Down Expand Up @@ -55,3 +55,58 @@ impl From<SymbolKindArg> for SymbolKind {
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn create_anchor_builds_line_anchor() {
let command = AddCommand {
file: "src/main.rs".to_string(),
line: Some(12),
column: Some(3),
symbol: None,
kind: SymbolKindArg::Unknown,
signature: None,
line_hint: None,
content: "note".to_string(),
};

let anchor = create_anchor(&command).unwrap();

match anchor {
NoteAnchor::Line(line) => {
assert_eq!(line.line, 12);
assert_eq!(line.column, 3);
}
_ => panic!("expected line anchor"),
}
}

#[test]
fn create_anchor_builds_symbol_anchor() {
let command = AddCommand {
file: "src/main.rs".to_string(),
line: None,
column: None,
symbol: Some("main".to_string()),
kind: SymbolKindArg::Function,
signature: Some("fn main()".to_string()),
line_hint: Some(1),
content: "note".to_string(),
};

let anchor = create_anchor(&command).unwrap();

match anchor {
NoteAnchor::Symbol(symbol) => {
assert_eq!(symbol.name, "main");
assert_eq!(symbol.kind, SymbolKind::Function);
assert_eq!(symbol.signature.as_deref(), Some("fn main()"));
assert_eq!(symbol.line_hint, Some(1));
}
_ => panic!("expected symbol anchor"),
}
}
}
2 changes: 1 addition & 1 deletion apps/frilvault-cli/src/command/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use uuid::Uuid;
use crate::{app::create_note_service, cli::delete::DeleteCommand};

pub fn execute(command: DeleteCommand) -> Result<()> {
let service = create_note_service()?;
let mut service = create_note_service()?;

service.delete_note(&command.file, Uuid::parse_str(&command.id)?)?;

Expand Down
2 changes: 1 addition & 1 deletion apps/frilvault-cli/src/command/doctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use anyhow::Result;
use crate::app::create_workspace_service;

pub fn execute() -> Result<()> {
let service = create_workspace_service()?;
let mut service = create_workspace_service()?;

let health = service.health_check()?;

Expand Down
2 changes: 1 addition & 1 deletion apps/frilvault-cli/src/command/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
};

pub fn execute(command: ListCommand) -> Result<()> {
let service = create_note_service()?;
let mut service = create_note_service()?;

let notes = service.list_notes(&command.file)?;

Expand Down
2 changes: 1 addition & 1 deletion apps/frilvault-cli/src/command/repair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use anyhow::Result;
use crate::{app::create_workspace_service, cli::repair::RepairCommand};

pub fn execute(command: RepairCommand) -> Result<()> {
let service = create_workspace_service()?;
let mut service = create_workspace_service()?;

if command.apply {
let repaired = service.apply_repairs()?;
Expand Down
22 changes: 15 additions & 7 deletions apps/frilvault-cli/src/command/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,27 @@ use anyhow::Result;

use crate::{
app::create_note_service,
cli::search::SearchCommand,
cli::search::{SearchCommand, SearchFormatArg},
output::{OutputFormat, print_notes},
};

pub fn execute(command: SearchCommand) -> Result<()> {
let service = create_note_service()?;
let mut service = create_note_service()?;

let results = service.search_notes(&command.keyword)?;
let results = match (command.keyword.as_deref(), command.file.as_deref()) {
(Some(keyword), Some(file)) => service
.search_notes(keyword)?
.into_iter()
.filter(|note| note.source_file.to_string_lossy() == file)
.collect(),
(Some(keyword), None) => service.search_notes(keyword)?,
(None, Some(file)) => service.list_notes(file)?,
(None, None) => anyhow::bail!("search requires either a keyword or --file"),
};

let format = if command.json {
OutputFormat::Json
} else {
OutputFormat::Text
let format = match (command.format, command.json) {
(Some(SearchFormatArg::Json), _) | (None, true) => OutputFormat::Json,
_ => OutputFormat::Text,
};

print_notes(&results, format)?;
Expand Down
2 changes: 1 addition & 1 deletion apps/frilvault-cli/src/command/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use anyhow::Result;
use crate::app::create_workspace_service;

pub fn execute() -> Result<()> {
let service = create_workspace_service()?;
let mut service = create_workspace_service()?;

let stats = service.stats()?;

Expand Down
2 changes: 1 addition & 1 deletion apps/frilvault-cli/src/command/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use uuid::Uuid;
use crate::{app::create_note_service, cli::update::UpdateCommand};

pub fn execute(command: UpdateCommand) -> Result<()> {
let service = create_note_service()?;
let mut service = create_note_service()?;

service.update_note(
&command.file,
Expand Down
7 changes: 7 additions & 0 deletions apps/frilvault-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ fn main() -> Result<()> {
command::doctor::execute()?;
}

Commands::Health => {
command::doctor::execute()?;
}

Commands::Stats => command::stats::execute()?,

Commands::Repair(cmd) => {
Expand All @@ -43,3 +47,6 @@ fn main() -> Result<()> {

Ok(())
}

#[cfg(test)]
mod tests;
2 changes: 1 addition & 1 deletion apps/frilvault-cli/src/output.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use frilvault_core::{NoteAnchor, NoteView};
use frilvault_core::{NoteAnchor, note_view::NoteView};

#[derive(Debug, Clone, Copy)]
pub enum OutputFormat {
Expand Down
70 changes: 70 additions & 0 deletions apps/frilvault-cli/src/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use clap::Parser;

use crate::cli::{Cli, Commands, add::SymbolKindArg, list::ListFormatArg, search::SearchFormatArg};

#[test]
fn parses_list_format_json() {
let cli = Cli::parse_from(["flvt", "list", "--file", "src/main.rs", "--format", "json"]);

match cli.command {
Commands::List(command) => {
assert_eq!(command.file, "src/main.rs");
assert!(matches!(command.format, Some(ListFormatArg::Json)));
assert!(!command.json);
}
_ => panic!("expected list command"),
}
}

#[test]
fn parses_search_with_file_and_json_format() {
let cli = Cli::parse_from([
"flvt",
"search",
"--file",
"src/main.rs",
"--format",
"json",
]);

match cli.command {
Commands::Search(command) => {
assert_eq!(command.keyword, None);
assert_eq!(command.file.as_deref(), Some("src/main.rs"));
assert!(matches!(command.format, Some(SearchFormatArg::Json)));
}
_ => panic!("expected search command"),
}
}

#[test]
fn parses_health_command_alias() {
let cli = Cli::parse_from(["flvt", "health"]);

assert!(matches!(cli.command, Commands::Health));
}

#[test]
fn parses_symbol_add_command() {
let cli = Cli::parse_from([
"flvt",
"add",
"--file",
"src/main.rs",
"--symbol",
"main",
"--kind",
"function",
"--content",
"note",
]);

match cli.command {
Commands::Add(command) => {
assert_eq!(command.symbol.as_deref(), Some("main"));
assert!(matches!(command.kind, SymbolKindArg::Function));
assert_eq!(command.content, "note");
}
_ => panic!("expected add command"),
}
}
3 changes: 3 additions & 0 deletions apps/vscode-extension/media/frilvault-symbol-note.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 0 additions & 20 deletions apps/vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@
"command": "frilvault.addNote",
"title": "FrilVault: Add Note"
},
{
"command": "frilvault.editNote",
"title": "FrilVault: Edit Note"
},
{
"command": "frilvault.deleteNote",
"title": "FrilVault: Delete Note"
},
{
"command": "frilvault.searchNotes",
"title": "FrilVault: Search Notes"
Expand Down Expand Up @@ -76,18 +68,6 @@
"group": "navigation"
}
],
"view/item/context": [
{
"command": "frilvault.editNote",
"when": "view == frilvault.notes",
"group": "inline"
},
{
"command": "frilvault.deleteNote",
"when": "view == frilvault.notes",
"group": "inline"
}
],
"editor/context": [
{
"command": "frilvault.addNote",
Expand Down
Loading