@@ -11,7 +11,7 @@ use ra_ide_api::{
11
11
FileId , FilePosition , FileRange , FoldKind , Query , RangeInfo , RunnableKind , Severity , Cancelable ,
12
12
AssistId ,
13
13
} ;
14
- use ra_syntax:: { AstNode , SyntaxKind , TextUnit } ;
14
+ use ra_syntax:: { AstNode , SyntaxKind , TextUnit , TextRange } ;
15
15
use ra_prof:: profile;
16
16
use rustc_hash:: FxHashMap ;
17
17
use serde:: { Serialize , Deserialize } ;
@@ -39,10 +39,15 @@ pub fn handle_syntax_tree(world: ServerWorld, params: req::SyntaxTreeParams) ->
39
39
Ok ( res)
40
40
}
41
41
42
+ // FIXME: drop this API
42
43
pub fn handle_extend_selection (
43
44
world : ServerWorld ,
44
45
params : req:: ExtendSelectionParams ,
45
46
) -> Result < req:: ExtendSelectionResult > {
47
+ log:: error!(
48
+ "extend selection is deprecated and will be removed soon,
49
+ use the new selection range API in LSP" ,
50
+ ) ;
46
51
let file_id = params. text_document . try_conv_with ( & world) ?;
47
52
let line_index = world. analysis ( ) . file_line_index ( file_id) ;
48
53
let selections = params
@@ -55,6 +60,46 @@ pub fn handle_extend_selection(
55
60
Ok ( req:: ExtendSelectionResult { selections } )
56
61
}
57
62
63
+ pub fn handle_selection_range (
64
+ world : ServerWorld ,
65
+ params : req:: SelectionRangeParams ,
66
+ ) -> Result < Vec < req:: SelectionRange > > {
67
+ let file_id = params. text_document . try_conv_with ( & world) ?;
68
+ let line_index = world. analysis ( ) . file_line_index ( file_id) ;
69
+ params
70
+ . positions
71
+ . into_iter ( )
72
+ . map_conv_with ( & line_index)
73
+ . map ( |position| {
74
+ let mut ranges = Vec :: new ( ) ;
75
+ {
76
+ let mut range = TextRange :: from_to ( position, position) ;
77
+ loop {
78
+ ranges. push ( range) ;
79
+ let frange = FileRange { file_id, range } ;
80
+ let next = world. analysis ( ) . extend_selection ( frange) ?;
81
+ if next == range {
82
+ break ;
83
+ } else {
84
+ range = next
85
+ }
86
+ }
87
+ }
88
+ let mut range = req:: SelectionRange {
89
+ range : ranges. last ( ) . unwrap ( ) . conv_with ( & line_index) ,
90
+ parent : None ,
91
+ } ;
92
+ for r in ranges. iter ( ) . rev ( ) . skip ( 1 ) {
93
+ range = req:: SelectionRange {
94
+ range : r. conv_with ( & line_index) ,
95
+ parent : Some ( Box :: new ( range) ) ,
96
+ }
97
+ }
98
+ Ok ( range)
99
+ } )
100
+ . collect ( )
101
+ }
102
+
58
103
pub fn handle_find_matching_brace (
59
104
world : ServerWorld ,
60
105
params : req:: FindMatchingBraceParams ,
0 commit comments