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
6 changes: 5 additions & 1 deletion crates/ctx-exec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,11 @@ impl StreamCompressor {
}

fn omit_marker(n: usize) -> String {
format!("... [{n} lines omitted]")
if n == 1 {
"... [1 line omitted]".to_string()
} else {
format!("... [{n} lines omitted]")
}
}

fn saved_pct(original: usize, compressed: usize) -> u32 {
Expand Down
17 changes: 17 additions & 0 deletions crates/ctx-exec/tests/compress_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,3 +556,20 @@ fn stream_compressor_with_no_pushes_is_empty() {
assert_eq!(result.stats.saved_percent, 0);
assert!(!result.stats.compression_ineffective());
}

#[test]
fn singular_omission_run_says_line_not_lines() {
// One line between the head and tail windows: the marker must read
// "[1 line omitted]", not "[1 lines omitted]".
let options = CompressOptions {
head_lines: 1,
tail_lines: 1,
collapse_threshold: 2,
..opts()
};
let result = compress("a\nb\nc\n", &options).unwrap();
assert_eq!(
String::from_utf8_lossy(&result.text),
"a\n... [1 line omitted]\nc"
);
}
13 changes: 0 additions & 13 deletions crates/ctx-symbol/src/lang/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,6 @@ impl Language for CLang {
.map(|s| s.trim().to_string())
}

fn signature(&self, node: &tree_sitter::Node, source: &str) -> String {
let start = node.start_byte();
let text = source
.get(start..node.end_byte().min(source.len()))
.unwrap_or("…");
let line = text.split('\n').next().unwrap_or("").trim();
if line.is_empty() {
"…".to_string()
} else {
line.to_string()
}
}

fn has_doc_comment(&self, _node: &tree_sitter::Node) -> bool {
true
}
Expand Down
13 changes: 0 additions & 13 deletions crates/ctx-symbol/src/lang/cpp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,6 @@ impl Language for CppLang {
.map(|s| s.trim().to_string())
}

fn signature(&self, node: &tree_sitter::Node, source: &str) -> String {
let start = node.start_byte();
let text = source
.get(start..node.end_byte().min(source.len()))
.unwrap_or("…");
let line = text.split('\n').next().unwrap_or("").trim();
if line.is_empty() {
"…".to_string()
} else {
line.to_string()
}
}

fn has_doc_comment(&self, _node: &tree_sitter::Node) -> bool {
true
}
Expand Down
13 changes: 0 additions & 13 deletions crates/ctx-symbol/src/lang/csharp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,6 @@ impl Language for CSharpLang {
.map(|s| s.trim().to_string())
}

fn signature(&self, node: &tree_sitter::Node, source: &str) -> String {
let start = node.start_byte();
let text = source
.get(start..node.end_byte().min(source.len()))
.unwrap_or("…");
let line = text.split('\n').next().unwrap_or("").trim();
if line.is_empty() {
"…".to_string()
} else {
line.to_string()
}
}

fn has_doc_comment(&self, _node: &tree_sitter::Node) -> bool {
true
}
Expand Down
13 changes: 0 additions & 13 deletions crates/ctx-symbol/src/lang/go.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,6 @@ impl Language for GoLang {
.map(|s| s.trim().to_string())
}

fn signature(&self, node: &tree_sitter::Node, source: &str) -> String {
let start = node.start_byte();
let text = source
.get(start..node.end_byte().min(source.len()))
.unwrap_or("…");
let line = text.split('\n').next().unwrap_or("").trim();
if line.is_empty() {
"…".to_string()
} else {
line.to_string()
}
}

fn has_doc_comment(&self, _node: &tree_sitter::Node) -> bool {
true
}
Expand Down
14 changes: 0 additions & 14 deletions crates/ctx-symbol/src/lang/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,4 @@ impl Language for HtmlLang {
}
None
}

fn signature(&self, node: &tree_sitter::Node, source: &str) -> String {
// `<tag id="value">` — the opening line only.
let start = node.start_byte();
let text = source
.get(start..node.end_byte().min(source.len()))
.unwrap_or("…");
let line = text.split('\n').next().unwrap_or("").trim();
if line.is_empty() {
"…".to_string()
} else {
line.to_string()
}
}
}
13 changes: 0 additions & 13 deletions crates/ctx-symbol/src/lang/java.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,6 @@ impl Language for JavaLang {
.map(|s| s.trim().to_string())
}

fn signature(&self, node: &tree_sitter::Node, source: &str) -> String {
let start = node.start_byte();
let text = source
.get(start..node.end_byte().min(source.len()))
.unwrap_or("…");
let line = text.split('\n').next().unwrap_or("").trim();
if line.is_empty() {
"…".to_string()
} else {
line.to_string()
}
}

fn has_doc_comment(&self, _node: &tree_sitter::Node) -> bool {
true
}
Expand Down
26 changes: 1 addition & 25 deletions crates/ctx-symbol/src/lang/javascript.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! JavaScript language backend.

use crate::lang::util::string_value;
use crate::language::Language;
use crate::symbol::SymbolKind;
use std::path::Path;
Expand Down Expand Up @@ -50,19 +51,6 @@ impl Language for JavaScriptLang {
.map(|s| s.trim().to_string())
}

fn signature(&self, node: &tree_sitter::Node, source: &str) -> String {
let start = node.start_byte();
let text = source
.get(start..node.end_byte().min(source.len()))
.unwrap_or("…");
let line = text.split('\n').next().unwrap_or("").trim();
if line.is_empty() {
"…".to_string()
} else {
line.to_string()
}
}

fn has_doc_comment(&self, _node: &tree_sitter::Node) -> bool {
true
}
Expand Down Expand Up @@ -106,15 +94,3 @@ impl Language for JavaScriptLang {
.unwrap_or_default()
}
}

/// Text of a string literal node without its quotes.
fn string_value(node: tree_sitter::Node, source: &str) -> Option<String> {
let text = node.utf8_text(source.as_bytes()).ok()?.trim();
let unquoted = text.strip_prefix(['\'', '"'])?;
Some(
unquoted
.strip_suffix(['\'', '"'])
.unwrap_or(unquoted)
.to_string(),
)
}
22 changes: 1 addition & 21 deletions crates/ctx-symbol/src/lang/lua.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,6 @@ impl Language for LuaLang {
.map(|s| s.trim().to_string())
}

fn signature(&self, node: &tree_sitter::Node, source: &str) -> String {
let start = node.start_byte();
let text = source
.get(start..node.end_byte().min(source.len()))
.unwrap_or("…");
let line = text.split('\n').next().unwrap_or("").trim();
if line.is_empty() {
"…".to_string()
} else {
line.to_string()
}
}

fn has_doc_comment(&self, _node: &tree_sitter::Node) -> bool {
true
}
Expand Down Expand Up @@ -111,12 +98,5 @@ fn string_value(node: tree_sitter::Node, source: &str) -> Option<String> {
{
return Some(text.trim().to_string());
}
let text = node.utf8_text(source.as_bytes()).ok()?.trim();
let unquoted = text.strip_prefix(['\'', '"'])?;
Some(
unquoted
.strip_suffix(['\'', '"'])
.unwrap_or(unquoted)
.to_string(),
)
crate::lang::util::string_value(node, source)
}
13 changes: 0 additions & 13 deletions crates/ctx-symbol/src/lang/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,6 @@ impl Language for MarkdownLang {
Some(cleaned.to_string())
}

/// The full heading line as written (`## Sub heading`).
fn signature(&self, node: &tree_sitter::Node, source: &str) -> String {
let text = source
.get(node.start_byte()..node.end_byte().min(source.len()))
.unwrap_or("…");
let line = text.split('\n').next().unwrap_or("").trim();
if line.is_empty() {
"…".to_string()
} else {
line.to_string()
}
}

/// Extend the heading's range to its enclosing `section`, i.e. through
/// the whole chapter including nested subsections.
fn definition_byte_range(&self, node: &tree_sitter::Node) -> std::ops::Range<usize> {
Expand Down
1 change: 1 addition & 0 deletions crates/ctx-symbol/src/lang/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ pub mod python;
pub mod ruby;
pub mod rust;
pub mod typescript;
pub(crate) mod util;
13 changes: 0 additions & 13 deletions crates/ctx-symbol/src/lang/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,6 @@ impl Language for PythonLang {
.map(|s| s.trim().to_string())
}

fn signature(&self, node: &tree_sitter::Node, source: &str) -> String {
let start = node.start_byte();
let text = source
.get(start..node.end_byte().min(source.len()))
.unwrap_or("…");
let line = text.split('\n').next().unwrap_or("").trim();
if line.is_empty() {
"…".to_string()
} else {
line.to_string()
}
}

fn has_doc_comment(&self, _node: &tree_sitter::Node) -> bool {
true
}
Expand Down
26 changes: 1 addition & 25 deletions crates/ctx-symbol/src/lang/ruby.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Ruby language backend.

use crate::lang::util::string_value;
use crate::language::Language;
use crate::symbol::SymbolKind;
use std::path::Path;
Expand Down Expand Up @@ -40,19 +41,6 @@ impl Language for RubyLang {
.map(|s| s.trim().to_string())
}

fn signature(&self, node: &tree_sitter::Node, source: &str) -> String {
let start = node.start_byte();
let text = source
.get(start..node.end_byte().min(source.len()))
.unwrap_or("…");
let line = text.split('\n').next().unwrap_or("").trim();
if line.is_empty() {
"…".to_string()
} else {
line.to_string()
}
}

fn has_doc_comment(&self, _node: &tree_sitter::Node) -> bool {
true
}
Expand Down Expand Up @@ -111,15 +99,3 @@ impl Language for RubyLang {
.unwrap_or_default()
}
}

/// Text of a string literal node without its quotes.
fn string_value(node: tree_sitter::Node, source: &str) -> Option<String> {
let text = node.utf8_text(source.as_bytes()).ok()?.trim();
let unquoted = text.strip_prefix(['\'', '"'])?;
Some(
unquoted
.strip_suffix(['\'', '"'])
.unwrap_or(unquoted)
.to_string(),
)
}
13 changes: 0 additions & 13 deletions crates/ctx-symbol/src/lang/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,6 @@ impl Language for RustLang {
.map(|s| s.trim().to_string())
}

fn signature(&self, node: &tree_sitter::Node, source: &str) -> String {
let start = node.start_byte();
let text = source
.get(start..node.end_byte().min(source.len()))
.unwrap_or("…");
let line = text.split('\n').next().unwrap_or("").trim();
if line.is_empty() {
"…".to_string()
} else {
line.to_string()
}
}

fn has_doc_comment(&self, _node: &tree_sitter::Node) -> bool {
true
}
Expand Down
26 changes: 1 addition & 25 deletions crates/ctx-symbol/src/lang/typescript.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! TypeScript / JavaScript language backend.

use crate::lang::util::string_value;
use crate::language::Language;
use crate::symbol::SymbolKind;
use std::path::Path;
Expand Down Expand Up @@ -65,19 +66,6 @@ impl Language for TypeScriptLang {
.map(|s| s.trim().to_string())
}

fn signature(&self, node: &tree_sitter::Node, source: &str) -> String {
let start = node.start_byte();
let text = source
.get(start..node.end_byte().min(source.len()))
.unwrap_or("…");
let line = text.split('\n').next().unwrap_or("").trim();
if line.is_empty() {
"…".to_string()
} else {
line.to_string()
}
}

fn has_doc_comment(&self, _node: &tree_sitter::Node) -> bool {
true
}
Expand Down Expand Up @@ -134,15 +122,3 @@ impl Language for TypeScriptLang {
vec![target]
}
}

/// Text of a string literal node without its quotes.
fn string_value(node: tree_sitter::Node, source: &str) -> Option<String> {
let text = node.utf8_text(source.as_bytes()).ok()?.trim();
let unquoted = text.strip_prefix(['\'', '"'])?;
Some(
unquoted
.strip_suffix(['\'', '"'])
.unwrap_or(unquoted)
.to_string(),
)
}
13 changes: 13 additions & 0 deletions crates/ctx-symbol/src/lang/util.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//! Helpers shared by language backends.

/// Text of a string literal node without its quotes.
pub(crate) fn string_value(node: tree_sitter::Node, source: &str) -> Option<String> {
let text = node.utf8_text(source.as_bytes()).ok()?.trim();
let unquoted = text.strip_prefix(['\'', '"'])?;
Some(
unquoted
.strip_suffix(['\'', '"'])
.unwrap_or(unquoted)
.to_string(),
)
}
Loading
Loading