3
3
use std:: collections:: HashMap ;
4
4
5
5
use flycheck:: { Applicability , DiagnosticLevel , DiagnosticSpan } ;
6
- use ide:: TextRange ;
7
6
use itertools:: Itertools ;
8
7
use stdx:: format_to;
9
8
use vfs:: { AbsPath , AbsPathBuf } ;
10
9
11
10
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,
18
13
} ;
19
14
20
15
use super :: { DiagnosticsMapConfig , Fix } ;
@@ -70,28 +65,16 @@ fn location(
70
65
let file_name = resolve_path ( config, workspace_root, & span. file_name ) ;
71
66
let uri = url_from_abs_path ( & file_name) ;
72
67
73
- let range = range ( span , snap , & uri ) . unwrap_or_else ( |_| {
68
+ let range = {
74
69
let offset_encoding = snap. config . offset_encoding ( ) ;
75
70
lsp_types:: Range :: new (
76
71
position ( & offset_encoding, span, span. line_start , span. column_start ) ,
77
72
position ( & offset_encoding, span, span. line_end , span. column_end ) ,
78
73
)
79
- } ) ;
74
+ } ;
80
75
lsp_types:: Location :: new ( uri, range)
81
76
}
82
77
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
-
95
78
fn position (
96
79
offset_encoding : & OffsetEncoding ,
97
80
span : & DiagnosticSpan ,
@@ -103,7 +86,7 @@ fn position(
103
86
let mut true_column_offset = column_offset;
104
87
if let Some ( line) = span. text . get ( line_index) {
105
88
if line. text . chars ( ) . count ( ) == line. text . len ( ) {
106
- // all utf-8
89
+ // all one byte utf-8 char
107
90
return lsp_types:: Position {
108
91
line : ( line_offset as u32 ) . saturating_sub ( 1 ) ,
109
92
character : ( column_offset as u32 ) . saturating_sub ( 1 ) ,
0 commit comments