@@ -317,24 +317,24 @@ impl Analysis {
317
317
}
318
318
319
319
/// Debug info about the current state of the analysis
320
- pub fn status ( & self ) -> String {
321
- status:: status ( & * self . db )
320
+ pub fn status ( & self ) -> Cancelable < String > {
321
+ self . with_db ( |db| status:: status ( & * db ) )
322
322
}
323
323
324
324
/// Gets the text of the source file.
325
- pub fn file_text ( & self , file_id : FileId ) -> Arc < String > {
326
- self . db . file_text ( file_id)
325
+ pub fn file_text ( & self , file_id : FileId ) -> Cancelable < Arc < String > > {
326
+ self . with_db ( |db| db . file_text ( file_id) )
327
327
}
328
328
329
329
/// Gets the syntax tree of the file.
330
- pub fn parse ( & self , file_id : FileId ) -> SourceFile {
331
- self . db . parse ( file_id) . tree ( )
330
+ pub fn parse ( & self , file_id : FileId ) -> Cancelable < SourceFile > {
331
+ self . with_db ( |db| db . parse ( file_id) . tree ( ) )
332
332
}
333
333
334
334
/// Gets the file's `LineIndex`: data structure to convert between absolute
335
335
/// offsets and line/column representation.
336
- pub fn file_line_index ( & self , file_id : FileId ) -> Arc < LineIndex > {
337
- self . db . line_index ( file_id)
336
+ pub fn file_line_index ( & self , file_id : FileId ) -> Cancelable < Arc < LineIndex > > {
337
+ self . with_db ( |db| db . line_index ( file_id) )
338
338
}
339
339
340
340
/// Selects the next syntactic nodes encompassing the range.
@@ -344,58 +344,67 @@ impl Analysis {
344
344
345
345
/// Returns position of the matching brace (all types of braces are
346
346
/// supported).
347
- pub fn matching_brace ( & self , position : FilePosition ) -> Option < TextUnit > {
348
- let parse = self . db . parse ( position. file_id ) ;
349
- let file = parse. tree ( ) ;
350
- matching_brace:: matching_brace ( & file, position. offset )
347
+ pub fn matching_brace ( & self , position : FilePosition ) -> Cancelable < Option < TextUnit > > {
348
+ self . with_db ( |db| {
349
+ let parse = db. parse ( position. file_id ) ;
350
+ let file = parse. tree ( ) ;
351
+ matching_brace:: matching_brace ( & file, position. offset )
352
+ } )
351
353
}
352
354
353
355
/// Returns a syntax tree represented as `String`, for debug purposes.
354
356
// FIXME: use a better name here.
355
- pub fn syntax_tree ( & self , file_id : FileId , text_range : Option < TextRange > ) -> String {
356
- syntax_tree:: syntax_tree ( & self . db , file_id, text_range)
357
+ pub fn syntax_tree (
358
+ & self ,
359
+ file_id : FileId ,
360
+ text_range : Option < TextRange > ,
361
+ ) -> Cancelable < String > {
362
+ self . with_db ( |db| syntax_tree:: syntax_tree ( & db, file_id, text_range) )
357
363
}
358
364
359
365
/// Returns an edit to remove all newlines in the range, cleaning up minor
360
366
/// stuff like trailing commas.
361
- pub fn join_lines ( & self , frange : FileRange ) -> SourceChange {
362
- let parse = self . db . parse ( frange. file_id ) ;
363
- let file_edit = SourceFileEdit {
364
- file_id : frange. file_id ,
365
- edit : join_lines:: join_lines ( & parse. tree ( ) , frange. range ) ,
366
- } ;
367
- SourceChange :: source_file_edit ( "join lines" , file_edit)
367
+ pub fn join_lines ( & self , frange : FileRange ) -> Cancelable < SourceChange > {
368
+ self . with_db ( |db| {
369
+ let parse = db. parse ( frange. file_id ) ;
370
+ let file_edit = SourceFileEdit {
371
+ file_id : frange. file_id ,
372
+ edit : join_lines:: join_lines ( & parse. tree ( ) , frange. range ) ,
373
+ } ;
374
+ SourceChange :: source_file_edit ( "join lines" , file_edit)
375
+ } )
368
376
}
369
377
370
378
/// Returns an edit which should be applied when opening a new line, fixing
371
379
/// up minor stuff like continuing the comment.
372
- pub fn on_enter ( & self , position : FilePosition ) -> Option < SourceChange > {
373
- typing:: on_enter ( & self . db , position)
380
+ pub fn on_enter ( & self , position : FilePosition ) -> Cancelable < Option < SourceChange > > {
381
+ self . with_db ( |db| typing:: on_enter ( & db, position) )
374
382
}
375
383
376
384
/// Returns an edit which should be applied after `=` was typed. Primarily,
377
385
/// this works when adding `let =`.
378
386
// FIXME: use a snippet completion instead of this hack here.
379
- pub fn on_eq_typed ( & self , position : FilePosition ) -> Option < SourceChange > {
380
- let parse = self . db . parse ( position. file_id ) ;
381
- let file = parse. tree ( ) ;
382
- let edit = typing:: on_eq_typed ( & file, position. offset ) ?;
383
- Some ( SourceChange :: source_file_edit (
384
- "add semicolon" ,
385
- SourceFileEdit { edit, file_id : position. file_id } ,
386
- ) )
387
+ pub fn on_eq_typed ( & self , position : FilePosition ) -> Cancelable < Option < SourceChange > > {
388
+ self . with_db ( |db| {
389
+ let parse = db. parse ( position. file_id ) ;
390
+ let file = parse. tree ( ) ;
391
+ let edit = typing:: on_eq_typed ( & file, position. offset ) ?;
392
+ Some ( SourceChange :: source_file_edit (
393
+ "add semicolon" ,
394
+ SourceFileEdit { edit, file_id : position. file_id } ,
395
+ ) )
396
+ } )
387
397
}
388
398
389
399
/// Returns an edit which should be applied when a dot ('.') is typed on a blank line, indenting the line appropriately.
390
- pub fn on_dot_typed ( & self , position : FilePosition ) -> Option < SourceChange > {
391
- typing:: on_dot_typed ( & self . db , position)
400
+ pub fn on_dot_typed ( & self , position : FilePosition ) -> Cancelable < Option < SourceChange > > {
401
+ self . with_db ( |db| typing:: on_dot_typed ( & db, position) )
392
402
}
393
403
394
404
/// Returns a tree representation of symbols in the file. Useful to draw a
395
405
/// file outline.
396
- pub fn file_structure ( & self , file_id : FileId ) -> Vec < StructureNode > {
397
- let parse = self . db . parse ( file_id) ;
398
- file_structure ( & parse. tree ( ) )
406
+ pub fn file_structure ( & self , file_id : FileId ) -> Cancelable < Vec < StructureNode > > {
407
+ self . with_db ( |db| file_structure ( & db. parse ( file_id) . tree ( ) ) )
399
408
}
400
409
401
410
/// Returns a list of the places in the file where type hints can be displayed.
@@ -404,9 +413,8 @@ impl Analysis {
404
413
}
405
414
406
415
/// Returns the set of folding ranges.
407
- pub fn folding_ranges ( & self , file_id : FileId ) -> Vec < Fold > {
408
- let parse = self . db . parse ( file_id) ;
409
- folding_ranges:: folding_ranges ( & parse. tree ( ) )
416
+ pub fn folding_ranges ( & self , file_id : FileId ) -> Cancelable < Vec < Fold > > {
417
+ self . with_db ( |db| folding_ranges:: folding_ranges ( & db. parse ( file_id) . tree ( ) ) )
410
418
}
411
419
412
420
/// Fuzzy searches for a symbol.
0 commit comments