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