MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / query_code

Function query_code

atomic-cli/src/commands/rpc.rs:6836–6884  ·  view source on GitHub ↗

`query code` uses the same graph-filtered read over both local-service and reactor transports. Preserve the complete domain JSON/human render.

(args: &super::query::QueryCode)

Source from the content-addressed store, hash-verified

6834/// `query code` uses the same graph-filtered read over both local-service and
6835/// reactor transports. Preserve the complete domain JSON/human render.
6836pub fn query_code(args: &super::query::QueryCode) -> CliResult<bool> {
6837 let Some(session) = Service::open()? else {
6838 return Ok(false);
6839 };
6840 let response = session.query_graph(pb::QueryGraphRequest {
6841 repository: Some(session.reference.clone()),
6842 query: Some(pb::query_graph_request::Query::ContentSearch(
6843 pb::ContentSearchQuery {
6844 query: args.pattern.clone(),
6845 paths: Vec::new(),
6846 path_filter: args.path_filter.clone(),
6847 file_type: args.file_type.clone(),
6848 exclude_type: None,
6849 case_insensitive: args.case_insensitive,
6850 max_results: Some(u32::try_from(args.max_results).map_err(|_| {
6851 CliError::Internal(anyhow::anyhow!("max-results exceeds the RPC limit"))
6852 })?),
6853 },
6854 )),
6855 ..Default::default()
6856 })?;
6857 let result = response.content_result.ok_or_else(|| {
6858 CliError::Internal(anyhow::anyhow!(
6859 "the service returned no content search result"
6860 ))
6861 })?;
6862 let result = atomic_repository::ContentSearchResult {
6863 matches: result
6864 .matches
6865 .into_iter()
6866 .map(|m| atomic_repository::ContentMatch {
6867 path: m.path,
6868 line_number: m.line_number,
6869 line_content: m.line_content,
6870 byte_offset: m.byte_offset,
6871 submatch_start: m.submatch_start as usize,
6872 submatch_end: m.submatch_end as usize,
6873 })
6874 .collect(),
6875 total_matches: result.total_matches as usize,
6876 dir_facets: result
6877 .dir_facets
6878 .into_iter()
6879 .map(|facet| (facet.path, facet.count as usize))
6880 .collect(),
6881 };
6882 super::query::print_code_result(&result, args.json)?;
6883 Ok(true)
6884}
6885
6886/// `atomic query plan` over QueryGraph (Plan) — the structured plan
6887/// executes handler-side; the CLI renders the domain PlanResult JSON

Callers 1

runMethod · 0.85

Calls 6

openFunction · 0.85
print_code_resultFunction · 0.85
query_graphMethod · 0.45
cloneMethod · 0.45
collectMethod · 0.45
into_iterMethod · 0.45

Tested by

no test coverage detected