MCPcopy Create free account
hub / github.com/dada-lang/dada / try_source

Function try_source

components/dada-debug/src/source.rs:3–22  ·  view source on GitHub ↗
(path: &str, line: u32, _column: u32)

Source from the content-addressed store, hash-verified

1use serde::Serialize;
2
3pub fn try_source(path: &str, line: u32, _column: u32) -> anyhow::Result<String> {
4 const WINDOW: u32 = 10;
5 let source = std::fs::read_to_string(path)?;
6 let start_from = line.saturating_sub(WINDOW);
7 let excerpt = source
8 .lines()
9 .skip(start_from as usize)
10 .take((WINDOW * 2) as usize)
11 .collect::<Vec<&str>>()
12 .join("\n");
13 crate::hbs::render(
14 "source",
15 &SourceArgs {
16 path,
17 source: excerpt,
18 line,
19 start_from,
20 },
21 )
22}
23
24#[derive(Serialize)]
25struct SourceArgs<'a> {

Callers 1

sourceFunction · 0.85

Calls 2

joinMethod · 0.80
renderFunction · 0.70

Tested by

no test coverage detected