about summary refs log tree commit diff
diff options
context:
space:
mode:
authorroife <roifewu@gmail.com>2023-12-07 15:30:00 +0800
committerroife <roifewu@gmail.com>2023-12-07 15:30:00 +0800
commit9a3167e65e80a26698dfc651cc0cd5c405fbd1a9 (patch)
treebaba19100f745736ad1ff5275728138538054d5a
parent6557151dca7e76832ff770caf1293f3062ea98e9 (diff)
downloadrust-9a3167e65e80a26698dfc651cc0cd5c405fbd1a9.tar.gz
rust-9a3167e65e80a26698dfc651cc0cd5c405fbd1a9.zip
fix: correct calculation for fields in WideChar for line-specific positions
-rw-r--r--lib/line-index/src/lib.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/line-index/src/lib.rs b/lib/line-index/src/lib.rs
index 03371c9c87a..58f266d67f6 100644
--- a/lib/line-index/src/lib.rs
+++ b/lib/line-index/src/lib.rs
@@ -363,7 +363,10 @@ fn analyze_source_file_generic(
             let c = src[i..].chars().next().unwrap();
             char_len = c.len_utf8();
 
-            let pos = TextSize::from(i as u32) + output_offset;
+            // The last element of `lines` represents the offset of the start of
+            // current line. To get the offset inside the line, we subtract it.
+            let pos = TextSize::from(i as u32) + output_offset
+                - lines.last().unwrap_or(&TextSize::default());
 
             if char_len > 1 {
                 assert!((2..=4).contains(&char_len));