@@ -165,7 +165,6 @@ mod helpers {
165
165
166
166
use ra_db:: { fixture:: WithFixture , FileId , FileRange , SourceDatabaseExt } ;
167
167
use ra_ide_db:: { symbol_index:: SymbolsDatabase , RootDatabase } ;
168
- use ra_syntax:: TextRange ;
169
168
use test_utils:: { add_cursor, assert_eq_text, extract_range_or_offset, RangeOrOffset } ;
170
169
171
170
use crate :: { AssistCtx , AssistHandler } ;
@@ -175,8 +174,7 @@ mod helpers {
175
174
let ( mut db, file_id) = RootDatabase :: with_single_file ( text) ;
176
175
// FIXME: ideally, this should be done by the above `RootDatabase::with_single_file`,
177
176
// but it looks like this might need specialization? :(
178
- let local_roots = vec ! [ db. file_source_root( file_id) ] ;
179
- db. set_local_roots ( Arc :: new ( local_roots) ) ;
177
+ db. set_local_roots ( Arc :: new ( vec ! [ db. file_source_root( file_id) ] ) ) ;
180
178
( db, file_id)
181
179
}
182
180
@@ -206,19 +204,32 @@ mod helpers {
206
204
}
207
205
208
206
fn check ( assist : AssistHandler , before : & str , expected : ExpectedResult ) {
209
- let ( range_or_offset, before) = extract_range_or_offset ( before) ;
210
- let range: TextRange = range_or_offset. into ( ) ;
207
+ let ( text_without_caret, file_with_caret_id, range_or_offset, db) =
208
+ if before. contains ( "//-" ) {
209
+ let ( mut db, position) = RootDatabase :: with_position ( before) ;
210
+ db. set_local_roots ( Arc :: new ( vec ! [ db. file_source_root( position. file_id) ] ) ) ;
211
+ (
212
+ db. file_text ( position. file_id ) . as_ref ( ) . to_owned ( ) ,
213
+ position. file_id ,
214
+ RangeOrOffset :: Offset ( position. offset ) ,
215
+ db,
216
+ )
217
+ } else {
218
+ let ( range_or_offset, text_without_caret) = extract_range_or_offset ( before) ;
219
+ let ( db, file_id) = with_single_file ( & text_without_caret) ;
220
+ ( text_without_caret, file_id, range_or_offset, db)
221
+ } ;
222
+
223
+ let frange = FileRange { file_id : file_with_caret_id, range : range_or_offset. into ( ) } ;
211
224
212
- let ( db, file_id) = with_single_file ( & before) ;
213
- let frange = FileRange { file_id, range } ;
214
225
let sema = Semantics :: new ( & db) ;
215
226
let assist_ctx = AssistCtx :: new ( & sema, frange, true ) ;
216
227
217
228
match ( assist ( assist_ctx) , expected) {
218
229
( Some ( assist) , ExpectedResult :: After ( after) ) => {
219
230
let action = assist. 0 [ 0 ] . action . clone ( ) . unwrap ( ) ;
220
231
221
- let mut actual = action. edit . apply ( & before ) ;
232
+ let mut actual = action. edit . apply ( & text_without_caret ) ;
222
233
match action. cursor_position {
223
234
None => {
224
235
if let RangeOrOffset :: Offset ( before_cursor_pos) = range_or_offset {
@@ -237,7 +248,7 @@ mod helpers {
237
248
( Some ( assist) , ExpectedResult :: Target ( target) ) => {
238
249
let action = assist. 0 [ 0 ] . action . clone ( ) . unwrap ( ) ;
239
250
let range = action. target . expect ( "expected target on action" ) ;
240
- assert_eq_text ! ( & before [ range] , target) ;
251
+ assert_eq_text ! ( & text_without_caret [ range] , target) ;
241
252
}
242
253
( Some ( _) , ExpectedResult :: NotApplicable ) => panic ! ( "assist should not be applicable!" ) ,
243
254
( None , ExpectedResult :: After ( _) ) | ( None , ExpectedResult :: Target ( _) ) => {
0 commit comments