mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-01 07:48:45 +00:00
fix: calculate right range for Dos line ending in mapping rustc range to lsp range
This commit is contained in:
parent
187bd7d48a
commit
dfae0a12ef
1 changed files with 5 additions and 22 deletions
|
@ -3,18 +3,13 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use flycheck::{Applicability, DiagnosticLevel, DiagnosticSpan};
|
use flycheck::{Applicability, DiagnosticLevel, DiagnosticSpan};
|
||||||
use ide::TextRange;
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use stdx::format_to;
|
use stdx::format_to;
|
||||||
use vfs::{AbsPath, AbsPathBuf};
|
use vfs::{AbsPath, AbsPathBuf};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
from_proto,
|
global_state::GlobalStateSnapshot, line_index::OffsetEncoding, lsp_ext,
|
||||||
global_state::GlobalStateSnapshot,
|
to_proto::url_from_abs_path,
|
||||||
line_index::OffsetEncoding,
|
|
||||||
lsp_ext,
|
|
||||||
to_proto::{self, url_from_abs_path},
|
|
||||||
Result,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{DiagnosticsMapConfig, Fix};
|
use super::{DiagnosticsMapConfig, Fix};
|
||||||
|
@ -70,28 +65,16 @@ fn location(
|
||||||
let file_name = resolve_path(config, workspace_root, &span.file_name);
|
let file_name = resolve_path(config, workspace_root, &span.file_name);
|
||||||
let uri = url_from_abs_path(&file_name);
|
let uri = url_from_abs_path(&file_name);
|
||||||
|
|
||||||
let range = range(span, snap, &uri).unwrap_or_else(|_| {
|
let range = {
|
||||||
let offset_encoding = snap.config.offset_encoding();
|
let offset_encoding = snap.config.offset_encoding();
|
||||||
lsp_types::Range::new(
|
lsp_types::Range::new(
|
||||||
position(&offset_encoding, span, span.line_start, span.column_start),
|
position(&offset_encoding, span, span.line_start, span.column_start),
|
||||||
position(&offset_encoding, span, span.line_end, span.column_end),
|
position(&offset_encoding, span, span.line_end, span.column_end),
|
||||||
)
|
)
|
||||||
});
|
};
|
||||||
lsp_types::Location::new(uri, range)
|
lsp_types::Location::new(uri, range)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn range(
|
|
||||||
span: &DiagnosticSpan,
|
|
||||||
snap: &GlobalStateSnapshot,
|
|
||||||
uri: &lsp_types::Url,
|
|
||||||
) -> Result<lsp_types::Range> {
|
|
||||||
let file_id = from_proto::file_id(snap, &uri)?;
|
|
||||||
let line_index = snap.file_line_index(file_id)?;
|
|
||||||
let range =
|
|
||||||
to_proto::range(&line_index, TextRange::new(span.byte_start.into(), span.byte_end.into()));
|
|
||||||
Ok(range)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn position(
|
fn position(
|
||||||
offset_encoding: &OffsetEncoding,
|
offset_encoding: &OffsetEncoding,
|
||||||
span: &DiagnosticSpan,
|
span: &DiagnosticSpan,
|
||||||
|
@ -103,7 +86,7 @@ fn position(
|
||||||
let mut true_column_offset = column_offset;
|
let mut true_column_offset = column_offset;
|
||||||
if let Some(line) = span.text.get(line_index) {
|
if let Some(line) = span.text.get(line_index) {
|
||||||
if line.text.chars().count() == line.text.len() {
|
if line.text.chars().count() == line.text.len() {
|
||||||
// all utf-8
|
// all one byte utf-8 char
|
||||||
return lsp_types::Position {
|
return lsp_types::Position {
|
||||||
line: (line_offset as u32).saturating_sub(1),
|
line: (line_offset as u32).saturating_sub(1),
|
||||||
character: (column_offset as u32).saturating_sub(1),
|
character: (column_offset as u32).saturating_sub(1),
|
||||||
|
|
Loading…
Reference in a new issue