Skip to content

Commit

Permalink
Fix line and column indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed Jul 31, 2024
1 parent ad4959b commit 15e813f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions crates/turbopack-core/src/issue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ pub struct IssueSource {
range: Option<Vc<SourceRange>>,
}

/// The end position is the first character after the range
#[turbo_tasks::value]
#[derive(Clone, Debug)]
enum SourceRange {
Expand Down
14 changes: 8 additions & 6 deletions crates/turbopack-mdx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,20 +189,22 @@ impl MdxTransformedAsset {
Err(err) => {
let loc = Vc::cell(err.place.map(|p| {
let (start, end) = match *p {
// markdown's positions are 1-indexed, SourcePos is 0-indexed.
// Both end positions point to the first character after the range
markdown::message::Place::Position(p) => (
SourcePos {
line: p.start.line,
column: p.start.column,
line: p.start.line - 1,
column: p.start.column - 1,
},
SourcePos {
line: p.end.line,
column: p.end.column,
line: p.end.line - 1,
column: p.end.column - 1,
},
),
markdown::message::Place::Point(p) => {
let p = SourcePos {
line: p.line,
column: p.column,
line: p.line - 1,
column: p.column - 1,
};
(p, p)
}
Expand Down

0 comments on commit 15e813f

Please sign in to comment.