Skip to content

Commit

Permalink
Tracked the issue down to sourcepos being wrong on lines with unicode…
Browse files Browse the repository at this point in the history
… right parentheses. See kivikakk/comrak#495
  • Loading branch information
ryanpeach committed Dec 17, 2024
1 parent 081b091 commit fcb3374
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
7 changes: 7 additions & 0 deletions DEBUGGING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# rust-lldb

https://dev.to/bmatcuk/debugging-rust-with-rust-lldb-j1f

Run `just test-debug` to run the tests in debug mode using lldb.

Now use `r <test_name>` to run a specific test. https://users.rust-lang.org/t/running-a-single-test-under-a-debugger/44460
10 changes: 10 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,13 @@ test:

test-print test_name:
RUNNING_TESTS=true RUST_LOG=trace RUST_BACKTRACE=1 cargo test -- --test-threads=1 {{test_name}}

[macos]
test-debug test_name breakpoint:
#!/bin/bash
TEST_OUTPUT=$(RUNNING_TESTS=true cargo test --no-run 2>&1 >/dev/null)
DEP1=$(echo $TEST_OUTPUT | grep -ohe 'Executable tests/logseq/main.rs (target/debug/deps/logseq-[a-z0-9]*' | awk -F'[()]' '{print $2}')
echo $DEP1
RUNNING_TESTS=true RUST_LOG=debug RUST_BACKTRACE=full rust-lldb $DEP1 \
-o "b {{breakpoint}}" \
-o "r {{test_name}}"
10 changes: 7 additions & 3 deletions src/file/content/wikilink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,13 @@ impl Visitor for WikilinkVisitor {
(sourcepos_start_offset_bytes + capture_start_byte).into(),
alias.char_len(),
);
let span = repair_span_due_to_frontmatter(span, node);
self.wikilinks
.push(Wikilink::builder().alias(alias.clone()).span(span).build());
let span_repaired = repair_span_due_to_frontmatter(span, node);
self.wikilinks.push(
Wikilink::builder()
.alias(alias.clone())
.span(span_repaired)
.build(),
);
}
};
match data {
Expand Down
7 changes: 5 additions & 2 deletions src/rules/unlinked_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ impl Visitor for UnlinkedTextVisitor {
continue;
}
let alias = Alias::new(&patterns[found.pattern().as_usize()]);
if "lorem" == alias.to_string() {
println!("Found lorem");
}
let text_without_frontmatter = remove_frontmatter_from_source(source, node);
let sourcepos_start_offset_bytes = SourceOffset::from_location(
text_without_frontmatter,
Expand All @@ -191,7 +194,7 @@ impl Visitor for UnlinkedTextVisitor {
let byte_length = found.end() - found.start();
let offset_bytes = sourcepos_start_offset_bytes + found.start();
let span = SourceSpan::new(offset_bytes.into(), byte_length);
let span = repair_span_due_to_frontmatter(span, node);
let span_repaired = repair_span_due_to_frontmatter(span, node);

// Dont match inside wikilinks
if let Some(parent) = parent {
Expand All @@ -201,7 +204,7 @@ impl Visitor for UnlinkedTextVisitor {
}
}

self.new_unlinked_texts.push((alias, span));
self.new_unlinked_texts.push((alias, span_repaired));
}
}
Ok(())
Expand Down

0 comments on commit fcb3374

Please sign in to comment.