add readme, docs, fmt
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
# signal-gateway-code-tool
|
||||
|
||||
A tool that can be provided to the `signal-gateway-assistant`, which allows it
|
||||
to fetch and read code without giving it shell access.
|
||||
|
||||
If configured with a github read-only access token, and if you give it a route
|
||||
to query the current git SHA of your deployed binary, it can transparently fetch the code
|
||||
corresponding to that.
|
||||
@@ -72,7 +72,10 @@ impl CachedFile {
|
||||
pub fn line_range(&self, start: Option<u32>, end: Option<u32>) -> impl Iterator<Item = &str> {
|
||||
let total_lines = self.line_count();
|
||||
let start_line = start.unwrap_or(1).saturating_sub(1); // Convert to 0-indexed
|
||||
let end_line = end.unwrap_or(total_lines).min(total_lines).saturating_sub(1); // Convert to 0-indexed
|
||||
let end_line = end
|
||||
.unwrap_or(total_lines)
|
||||
.min(total_lines)
|
||||
.saturating_sub(1); // Convert to 0-indexed
|
||||
|
||||
LineRangeIter {
|
||||
content: &self.content,
|
||||
@@ -93,7 +96,6 @@ impl CachedFile {
|
||||
Err(pos) => pos as u32 + 1, // pos is the number of newlines before idx
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// Iterator over a range of lines.
|
||||
@@ -118,7 +120,9 @@ impl<'a> Iterator for LineRangeIter<'a> {
|
||||
let start = if line == 0 {
|
||||
0
|
||||
} else {
|
||||
self.newline_indices.get(line - 1).map(|&i| i as usize + 1)?
|
||||
self.newline_indices
|
||||
.get(line - 1)
|
||||
.map(|&i| i as usize + 1)?
|
||||
};
|
||||
|
||||
// Get end offset: at this line's newline, or end of content for last line
|
||||
|
||||
@@ -421,7 +421,10 @@ impl CodeTool {
|
||||
if context == 0 {
|
||||
// No context, just print matches
|
||||
for &line_num in &file_matches {
|
||||
let line = file.line_range(Some(line_num), Some(line_num)).next().unwrap_or("");
|
||||
let line = file
|
||||
.line_range(Some(line_num), Some(line_num))
|
||||
.next()
|
||||
.unwrap_or("");
|
||||
writeln!(&mut output, "{}:{}: {}", path, line_num, line)
|
||||
.map_err(|e| format!("Format error: {e}"))?;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user