diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-05-04 13:00:30 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-05-04 13:00:30 +0100 |
commit | d9f1b5fc7cdeedce99874f7cf2111ab09d8b3429 (patch) | |
tree | fa313d4e4134087a545744532e2215b3abbdc7c9 /crates/hir_def | |
parent | 6d812efcd9e632a47ba85086c0a9dc72d13ff732 (diff) | |
parent | 5a78d96d0ea1e9d71d8bfe999b4af7cd1b85cebe (diff) |
Merge #8719
8719: Fix block comment intra doc link injection ranges r=Veykril a=Veykril
bors r+
Co-authored-by: Lukas Tobias Wirth <[email protected]>
Diffstat (limited to 'crates/hir_def')
-rw-r--r-- | crates/hir_def/src/attr.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/crates/hir_def/src/attr.rs b/crates/hir_def/src/attr.rs index d9294d93a..0171d8a92 100644 --- a/crates/hir_def/src/attr.rs +++ b/crates/hir_def/src/attr.rs | |||
@@ -484,10 +484,10 @@ impl AttrsWithOwner { | |||
484 | let mut buf = String::new(); | 484 | let mut buf = String::new(); |
485 | let mut mapping = Vec::new(); | 485 | let mut mapping = Vec::new(); |
486 | for (doc, idx) in docs { | 486 | for (doc, idx) in docs { |
487 | // str::lines doesn't yield anything for the empty string | ||
488 | if !doc.is_empty() { | 487 | if !doc.is_empty() { |
489 | for line in doc.split('\n') { | 488 | let mut base_offset = 0; |
490 | let line = line.trim_end(); | 489 | for raw_line in doc.split('\n') { |
490 | let line = raw_line.trim_end(); | ||
491 | let line_len = line.len(); | 491 | let line_len = line.len(); |
492 | let (offset, line) = match line.char_indices().nth(indent) { | 492 | let (offset, line) = match line.char_indices().nth(indent) { |
493 | Some((offset, _)) => (offset, &line[offset..]), | 493 | Some((offset, _)) => (offset, &line[offset..]), |
@@ -498,9 +498,13 @@ impl AttrsWithOwner { | |||
498 | mapping.push(( | 498 | mapping.push(( |
499 | TextRange::new(buf_offset.try_into().ok()?, buf.len().try_into().ok()?), | 499 | TextRange::new(buf_offset.try_into().ok()?, buf.len().try_into().ok()?), |
500 | idx, | 500 | idx, |
501 | TextRange::new(offset.try_into().ok()?, line_len.try_into().ok()?), | 501 | TextRange::at( |
502 | (base_offset + offset).try_into().ok()?, | ||
503 | line_len.try_into().ok()?, | ||
504 | ), | ||
502 | )); | 505 | )); |
503 | buf.push('\n'); | 506 | buf.push('\n'); |
507 | base_offset += raw_line.len() + 1; | ||
504 | } | 508 | } |
505 | } else { | 509 | } else { |
506 | buf.push('\n'); | 510 | buf.push('\n'); |