Skip to content

Commit f5229ce

Browse files
committed
Auto merge of rust-lang#12301 - harpsword:fix_for_crlf_cargo_range_map, r=jonas-schievink
fix: calculate correct postion for Dos line ending in mapping rustc range to ls… fix rust-lang#12293
2 parents 44be090 + dfae0a1 commit f5229ce

File tree

1 file changed

+5
-22
lines changed

1 file changed

+5
-22
lines changed

crates/rust-analyzer/src/diagnostics/to_proto.rs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,13 @@
33
use std::collections::HashMap;
44

55
use flycheck::{Applicability, DiagnosticLevel, DiagnosticSpan};
6-
use ide::TextRange;
76
use itertools::Itertools;
87
use stdx::format_to;
98
use vfs::{AbsPath, AbsPathBuf};
109

1110
use crate::{
12-
from_proto,
13-
global_state::GlobalStateSnapshot,
14-
line_index::OffsetEncoding,
15-
lsp_ext,
16-
to_proto::{self, url_from_abs_path},
17-
Result,
11+
global_state::GlobalStateSnapshot, line_index::OffsetEncoding, lsp_ext,
12+
to_proto::url_from_abs_path,
1813
};
1914

2015
use super::{DiagnosticsMapConfig, Fix};
@@ -70,28 +65,16 @@ fn location(
7065
let file_name = resolve_path(config, workspace_root, &span.file_name);
7166
let uri = url_from_abs_path(&file_name);
7267

73-
let range = range(span, snap, &uri).unwrap_or_else(|_| {
68+
let range = {
7469
let offset_encoding = snap.config.offset_encoding();
7570
lsp_types::Range::new(
7671
position(&offset_encoding, span, span.line_start, span.column_start),
7772
position(&offset_encoding, span, span.line_end, span.column_end),
7873
)
79-
});
74+
};
8075
lsp_types::Location::new(uri, range)
8176
}
8277

83-
fn range(
84-
span: &DiagnosticSpan,
85-
snap: &GlobalStateSnapshot,
86-
uri: &lsp_types::Url,
87-
) -> Result<lsp_types::Range> {
88-
let file_id = from_proto::file_id(snap, &uri)?;
89-
let line_index = snap.file_line_index(file_id)?;
90-
let range =
91-
to_proto::range(&line_index, TextRange::new(span.byte_start.into(), span.byte_end.into()));
92-
Ok(range)
93-
}
94-
9578
fn position(
9679
offset_encoding: &OffsetEncoding,
9780
span: &DiagnosticSpan,
@@ -103,7 +86,7 @@ fn position(
10386
let mut true_column_offset = column_offset;
10487
if let Some(line) = span.text.get(line_index) {
10588
if line.text.chars().count() == line.text.len() {
106-
// all utf-8
89+
// all one byte utf-8 char
10790
return lsp_types::Position {
10891
line: (line_offset as u32).saturating_sub(1),
10992
character: (column_offset as u32).saturating_sub(1),

0 commit comments

Comments
 (0)