MCPcopy Create free account
hub / github.com/douglance/devsql / run

Method run

crates/devsql/src/tools/context.rs:42–138  ·  view source on GitHub ↗
(&self, ctx: CommandContext)

Source from the content-addressed store, hash-verified

40#[async_trait::async_trait]
41impl CommandHandler for ContextHandler {
42 async fn run(&self, ctx: CommandContext) -> CommandResult {
43 let file = match ctx.args.get("file").and_then(|v| v.as_str()) {
44 Some(f) => f.to_string(),
45 None => {
46 return CommandResult::Error {
47 code: "MISSING_ARG".into(),
48 message: "Missing required argument: file".into(),
49 retryable: false,
50 exit_code: Some(1),
51 cta: None,
52 };
53 }
54 };
55
56 let include_symbols = ctx
57 .options
58 .get("symbols")
59 .and_then(|v| v.as_bool())
60 .unwrap_or(true); // default to true -- symbols are the main value
61
62 let (mut engine, _repo_path) = match engine_from_options(&ctx.options) {
63 Ok(v) => v,
64 Err(e) => return e,
65 };
66
67 // Load source_files and symbols tables
68 let mut tables = vec!["source_files"];
69 if include_symbols {
70 tables.push("symbols");
71 }
72 if let Err(e) = engine.load_code_tables(&tables) {
73 return CommandResult::Error {
74 code: "LOAD_ERROR".into(),
75 message: format!("Failed to load code tables: {e}"),
76 retryable: false,
77 exit_code: Some(1),
78 cta: None,
79 };
80 }
81
82 // Query source files matching the path
83 let files_sql = format!(
84 "SELECT path, language, line_count, size_bytes \
85 FROM source_files \
86 WHERE path LIKE '%{file}%'"
87 );
88
89 let file_rows = match engine.query(&files_sql) {
90 Ok(rows) => rows,
91 Err(e) => {
92 return CommandResult::Error {
93 code: "QUERY_ERROR".into(),
94 message: format!("File query failed: {e}"),
95 retryable: false,
96 exit_code: Some(1),
97 cta: None,
98 };
99 }

Callers

nothing calls this directly

Calls 3

engine_from_optionsFunction · 0.85
load_code_tablesMethod · 0.80
queryMethod · 0.80

Tested by

no test coverage detected