]> git.proxmox.com Git - rustc.git/blobdiff - src/tools/rust-analyzer/lib/line-index/src/lib.rs
New upstream version 1.76.0+dfsg1
[rustc.git] / src / tools / rust-analyzer / lib / line-index / src / lib.rs
index 03371c9c87af953bc2cc1a49c42d566556f1ae08..58f266d67f629710052dadd4e82c9bf072ddb9f0 100644 (file)
@@ -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));