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
8 changes: 4 additions & 4 deletions src/mcp/literal_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl CodesearchService {
&effective_query,
snippet_regex.as_ref(),
) {
let match_line = chunk.start_line + match_offset + 1;
let match_line = chunk.start_line + match_offset;
items.push(LiteralSearchResultItem {
path: ctx.prefix_sourced_path(alias, &chunk.path),
start_line: match_line,
Expand Down Expand Up @@ -189,7 +189,7 @@ impl CodesearchService {
&effective_query,
snippet_regex.as_ref(),
) {
let match_line = chunk.start_line + match_offset + 1;
let match_line = chunk.start_line + match_offset;
items.push(LiteralSearchResultItem {
path: chunk.path,
start_line: match_line,
Expand Down Expand Up @@ -423,7 +423,7 @@ impl CodesearchService {
let (match_offset, snippet) = match_info.unwrap_or_else(|| {
(0, chunk.content.lines().next().unwrap_or("").to_string())
});
let match_line = chunk.start_line + match_offset + 1;
let match_line = chunk.start_line + match_offset;
items.push(LiteralSearchResultItem {
path: ctx.prefix_sourced_path(&fts_hit.alias, &chunk.path),
start_line: match_line,
Expand Down Expand Up @@ -506,7 +506,7 @@ impl CodesearchService {
let (match_offset, snippet) = match_info.unwrap_or_else(|| {
(0, chunk.content.lines().next().unwrap_or("").to_string())
});
let match_line = chunk.start_line + match_offset + 1;
let match_line = chunk.start_line + match_offset;
Some(LiteralSearchResultItem {
path: chunk.path,
start_line: match_line,
Expand Down
2 changes: 1 addition & 1 deletion src/mcp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ fn parse_import_lines(content: &str, start_line: usize) -> Vec<ImportItem> {
imported,
// `start_line` is the chunk's 0-based first line and `offset`
// is 0-based within it; the response emits 1-based lines.
line: start_line + offset + 1,
line: start_line + offset,
kind,
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/mcp/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1320,8 +1320,8 @@ impl CodesearchService {
.map(|r| SearchResultItem {
chunk_id: Some(r.id),
path: r.path,
// Chunks store 0-indexed lines; every response emits 1-based
// editor lines, so the conversion happens once, here.
// Chunks store 1-based editor lines; responses pass them
// through unchanged.
start_line: r.start_line,
end_line: r.end_line,
kind: r.kind,
Expand Down
14 changes: 8 additions & 6 deletions src/mcp/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1220,19 +1220,21 @@ fn test_match_line_for_literal_regex() {
#[test]
fn test_parse_import_lines_detects_common_forms() {
let content = "use std::fs;\nimport os\nfrom pkg import thing\n#include <stdio.h>\nconst x = require('x')\nlet y = 1;";
// `10` is the chunk's 0-based first line; emitted lines are 1-based.
// `10` is the chunk's 1-based first line (the chunk starts on editor
// line 10); match lines are start_line + the 0-based offset within the
// chunk.
let imports = super::parse_import_lines(content, 10);
assert_eq!(imports.len(), 5);
assert_eq!(imports[0].kind, "use");
assert_eq!(imports[0].line, 11);
assert_eq!(imports[0].line, 10);
assert_eq!(imports[1].kind, "import");
assert_eq!(imports[1].line, 12);
assert_eq!(imports[1].line, 11);
assert_eq!(imports[2].kind, "import");
assert_eq!(imports[2].line, 13);
assert_eq!(imports[2].line, 12);
assert_eq!(imports[3].kind, "include");
assert_eq!(imports[3].line, 14);
assert_eq!(imports[3].line, 13);
assert_eq!(imports[4].kind, "require");
assert_eq!(imports[4].line, 15);
assert_eq!(imports[4].line, 14);
}

// === Project/group routing tests ===
Expand Down
6 changes: 3 additions & 3 deletions src/serve/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5936,14 +5936,14 @@ async fn group_literal_search_relaxed_fallback_covers_partial_term_hits() {
let mut vs = stores.vector_store.write().await;
let rich = crate::chunker::Chunk::new(
"create package documents quickly".to_string(),
0,
1,
3,
crate::chunker::ChunkKind::Comment,
"docs/create.md".to_string(),
);
let poor = crate::chunker::Chunk::new(
"package".to_string(),
0,
1,
1,
crate::chunker::ChunkKind::Comment,
"docs/other.md".to_string(),
Expand Down Expand Up @@ -6016,7 +6016,7 @@ async fn group_literal_search_relaxed_fallback_covers_partial_term_hits() {
assert_eq!(items[0]["path"], "partial/docs/create.md", "got: {text}");
assert_eq!(
items[0]["start_line"], 1,
"responses must emit 1-based editor lines (chunk starts at 0-based line 0): {text}"
"responses must emit 1-based editor lines (the chunk starts on editor line 1): {text}"
);
assert_eq!(
parsed["relaxed_fallback"],
Expand Down
Loading