diff options
Diffstat (limited to 'crates/ra_ide_api/src/lib.rs')
-rw-r--r-- | crates/ra_ide_api/src/lib.rs | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 33bef178a..919d248e2 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs | |||
@@ -299,7 +299,7 @@ impl Analysis { | |||
299 | } | 299 | } |
300 | 300 | ||
301 | /// Gets the syntax tree of the file. | 301 | /// Gets the syntax tree of the file. |
302 | pub fn file_syntax(&self, file_id: FileId) -> TreeArc<SourceFile> { | 302 | pub fn parse(&self, file_id: FileId) -> TreeArc<SourceFile> { |
303 | self.db.source_file(file_id).clone() | 303 | self.db.source_file(file_id).clone() |
304 | } | 304 | } |
305 | 305 | ||
@@ -310,14 +310,15 @@ impl Analysis { | |||
310 | } | 310 | } |
311 | 311 | ||
312 | /// Selects the next syntactic nodes encopasing the range. | 312 | /// Selects the next syntactic nodes encopasing the range. |
313 | pub fn extend_selection(&self, frange: FileRange) -> TextRange { | 313 | pub fn extend_selection(&self, frange: FileRange) -> Cancelable<TextRange> { |
314 | extend_selection::extend_selection(&self.db, frange) | 314 | self.with_db(|db| extend_selection::extend_selection(db, frange)) |
315 | } | 315 | } |
316 | 316 | ||
317 | /// Returns position of the mathcing brace (all types of braces are | 317 | /// Returns position of the mathcing brace (all types of braces are |
318 | /// supported). | 318 | /// supported). |
319 | pub fn matching_brace(&self, file: &SourceFile, offset: TextUnit) -> Option<TextUnit> { | 319 | pub fn matching_brace(&self, position: FilePosition) -> Option<TextUnit> { |
320 | ra_ide_api_light::matching_brace(file, offset) | 320 | let file = self.db.source_file(position.file_id); |
321 | ra_ide_api_light::matching_brace(&file, position.offset) | ||
321 | } | 322 | } |
322 | 323 | ||
323 | /// Returns a syntax tree represented as `String`, for debug purposes. | 324 | /// Returns a syntax tree represented as `String`, for debug purposes. |
@@ -388,8 +389,7 @@ impl Analysis { | |||
388 | &self, | 389 | &self, |
389 | position: FilePosition, | 390 | position: FilePosition, |
390 | ) -> Cancelable<Option<RangeInfo<Vec<NavigationTarget>>>> { | 391 | ) -> Cancelable<Option<RangeInfo<Vec<NavigationTarget>>>> { |
391 | self.db | 392 | self.with_db(|db| goto_definition::goto_definition(db, position)) |
392 | .catch_canceled(|db| goto_definition::goto_definition(db, position)) | ||
393 | } | 393 | } |
394 | 394 | ||
395 | /// Finds all usages of the reference at point. | 395 | /// Finds all usages of the reference at point. |
@@ -404,8 +404,7 @@ impl Analysis { | |||
404 | 404 | ||
405 | /// Computes parameter information for the given call expression. | 405 | /// Computes parameter information for the given call expression. |
406 | pub fn call_info(&self, position: FilePosition) -> Cancelable<Option<CallInfo>> { | 406 | pub fn call_info(&self, position: FilePosition) -> Cancelable<Option<CallInfo>> { |
407 | self.db | 407 | self.with_db(|db| call_info::call_info(db, position)) |
408 | .catch_canceled(|db| call_info::call_info(db, position)) | ||
409 | } | 408 | } |
410 | 409 | ||
411 | /// Returns a `mod name;` declaration which created the current module. | 410 | /// Returns a `mod name;` declaration which created the current module. |
@@ -420,33 +419,28 @@ impl Analysis { | |||
420 | 419 | ||
421 | /// Returns the root file of the given crate. | 420 | /// Returns the root file of the given crate. |
422 | pub fn crate_root(&self, crate_id: CrateId) -> Cancelable<FileId> { | 421 | pub fn crate_root(&self, crate_id: CrateId) -> Cancelable<FileId> { |
423 | Ok(self.db.crate_graph().crate_root(crate_id)) | 422 | self.with_db(|db| db.crate_graph().crate_root(crate_id)) |
424 | } | 423 | } |
425 | 424 | ||
426 | /// Returns the set of possible targets to run for the current file. | 425 | /// Returns the set of possible targets to run for the current file. |
427 | pub fn runnables(&self, file_id: FileId) -> Cancelable<Vec<Runnable>> { | 426 | pub fn runnables(&self, file_id: FileId) -> Cancelable<Vec<Runnable>> { |
428 | self.db | 427 | self.with_db(|db| runnables::runnables(db, file_id)) |
429 | .catch_canceled(|db| runnables::runnables(db, file_id)) | ||
430 | } | 428 | } |
431 | 429 | ||
432 | /// Computes syntax highlighting for the given file. | 430 | /// Computes syntax highlighting for the given file. |
433 | pub fn highlight(&self, file_id: FileId) -> Cancelable<Vec<HighlightedRange>> { | 431 | pub fn highlight(&self, file_id: FileId) -> Cancelable<Vec<HighlightedRange>> { |
434 | self.db | 432 | self.with_db(|db| syntax_highlighting::highlight(db, file_id)) |
435 | .catch_canceled(|db| syntax_highlighting::highlight(db, file_id)) | ||
436 | } | 433 | } |
437 | 434 | ||
438 | /// Computes completions at the given position. | 435 | /// Computes completions at the given position. |
439 | pub fn completions(&self, position: FilePosition) -> Cancelable<Option<Vec<CompletionItem>>> { | 436 | pub fn completions(&self, position: FilePosition) -> Cancelable<Option<Vec<CompletionItem>>> { |
440 | let completions = self | 437 | self.with_db(|db| completion::completions(db, position).map(Into::into)) |
441 | .db | ||
442 | .catch_canceled(|db| completion::completions(db, position))?; | ||
443 | Ok(completions.map(|it| it.into())) | ||
444 | } | 438 | } |
445 | 439 | ||
446 | /// Computes assists (aks code actons aka intentions) for the given | 440 | /// Computes assists (aks code actons aka intentions) for the given |
447 | /// position. | 441 | /// position. |
448 | pub fn assists(&self, frange: FileRange) -> Cancelable<Vec<SourceChange>> { | 442 | pub fn assists(&self, frange: FileRange) -> Cancelable<Vec<SourceChange>> { |
449 | Ok(self.db.assists(frange)) | 443 | self.with_db(|db| db.assists(frange)) |
450 | } | 444 | } |
451 | 445 | ||
452 | /// Computes the set of diagnostics for the given file. | 446 | /// Computes the set of diagnostics for the given file. |