aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide/src/lib.rs')
-rw-r--r--crates/ide/src/lib.rs47
1 files changed, 31 insertions, 16 deletions
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs
index 6c94c26b5..b600178ee 100644
--- a/crates/ide/src/lib.rs
+++ b/crates/ide/src/lib.rs
@@ -22,6 +22,7 @@ mod markup;
22mod prime_caches; 22mod prime_caches;
23mod display; 23mod display;
24 24
25mod annotations;
25mod call_hierarchy; 26mod call_hierarchy;
26mod diagnostics; 27mod diagnostics;
27mod expand_macro; 28mod expand_macro;
@@ -63,9 +64,10 @@ use syntax::SourceFile;
63use crate::display::ToNav; 64use crate::display::ToNav;
64 65
65pub use crate::{ 66pub use crate::{
67 annotations::{Annotation, AnnotationConfig, AnnotationKind},
66 call_hierarchy::CallItem, 68 call_hierarchy::CallItem,
67 diagnostics::{Diagnostic, DiagnosticsConfig, Fix, Severity}, 69 diagnostics::{Diagnostic, DiagnosticsConfig, Fix, Severity},
68 display::navigation_target::{NavigationTarget, SymbolKind}, 70 display::navigation_target::NavigationTarget,
69 expand_macro::ExpandedMacro, 71 expand_macro::ExpandedMacro,
70 file_structure::StructureNode, 72 file_structure::StructureNode,
71 folding_ranges::{Fold, FoldKind}, 73 folding_ranges::{Fold, FoldKind},
@@ -73,19 +75,19 @@ pub use crate::{
73 inlay_hints::{InlayHint, InlayHintsConfig, InlayKind}, 75 inlay_hints::{InlayHint, InlayHintsConfig, InlayKind},
74 markup::Markup, 76 markup::Markup,
75 prime_caches::PrimeCachesProgress, 77 prime_caches::PrimeCachesProgress,
76 references::{rename::RenameError, Declaration, ReferenceSearchResult}, 78 references::{rename::RenameError, ReferenceSearchResult},
77 runnables::{Runnable, RunnableKind, TestId}, 79 runnables::{Runnable, RunnableKind, TestId},
78 syntax_highlighting::{ 80 syntax_highlighting::{
79 tags::{Highlight, HlMod, HlMods, HlPunct, HlTag}, 81 tags::{Highlight, HlMod, HlMods, HlPunct, HlTag},
80 HlRange, 82 HlRange,
81 }, 83 },
82}; 84};
83pub use assists::{Assist, AssistConfig, AssistId, AssistKind}; 85pub use hir::{Documentation, Semantics};
84pub use completion::{ 86pub use ide_assists::{Assist, AssistConfig, AssistId, AssistKind};
87pub use ide_completion::{
85 CompletionConfig, CompletionItem, CompletionItemKind, CompletionScore, ImportEdit, 88 CompletionConfig, CompletionItem, CompletionItemKind, CompletionScore, ImportEdit,
86 InsertTextFormat, 89 InsertTextFormat,
87}; 90};
88pub use hir::{Documentation, Semantics};
89pub use ide_db::{ 91pub use ide_db::{
90 base_db::{ 92 base_db::{
91 Canceled, Change, CrateGraph, CrateId, Edition, FileId, FilePosition, FileRange, 93 Canceled, Change, CrateGraph, CrateId, Edition, FileId, FilePosition, FileRange,
@@ -93,13 +95,13 @@ pub use ide_db::{
93 }, 95 },
94 call_info::CallInfo, 96 call_info::CallInfo,
95 label::Label, 97 label::Label,
96 line_index::{LineCol, LineIndex}, 98 line_index::{LineCol, LineColUtf16, LineIndex},
97 search::{FileReference, ReferenceAccess, ReferenceKind, SearchScope}, 99 search::{ReferenceAccess, SearchScope},
98 source_change::{FileSystemEdit, SourceChange}, 100 source_change::{FileSystemEdit, SourceChange},
99 symbol_index::Query, 101 symbol_index::Query,
100 RootDatabase, 102 RootDatabase,
101}; 103};
102pub use ssr::SsrError; 104pub use ide_ssr::SsrError;
103pub use syntax::{TextRange, TextSize}; 105pub use syntax::{TextRange, TextSize};
104pub use text_edit::{Indel, TextEdit}; 106pub use text_edit::{Indel, TextEdit};
105 107
@@ -369,9 +371,7 @@ impl Analysis {
369 position: FilePosition, 371 position: FilePosition,
370 search_scope: Option<SearchScope>, 372 search_scope: Option<SearchScope>,
371 ) -> Cancelable<Option<ReferenceSearchResult>> { 373 ) -> Cancelable<Option<ReferenceSearchResult>> {
372 self.with_db(|db| { 374 self.with_db(|db| references::find_all_refs(&Semantics::new(db), position, search_scope))
373 references::find_all_refs(&Semantics::new(db), position, search_scope).map(|it| it.info)
374 })
375 } 375 }
376 376
377 /// Finds all methods and free functions for the file. Does not return tests! 377 /// Finds all methods and free functions for the file. Does not return tests!
@@ -468,7 +468,7 @@ impl Analysis {
468 config: &CompletionConfig, 468 config: &CompletionConfig,
469 position: FilePosition, 469 position: FilePosition,
470 ) -> Cancelable<Option<Vec<CompletionItem>>> { 470 ) -> Cancelable<Option<Vec<CompletionItem>>> {
471 self.with_db(|db| completion::completions(db, config, position).map(Into::into)) 471 self.with_db(|db| ide_completion::completions(db, config, position).map(Into::into))
472 } 472 }
473 473
474 /// Resolves additional completion data at the position given. 474 /// Resolves additional completion data at the position given.
@@ -478,15 +478,17 @@ impl Analysis {
478 position: FilePosition, 478 position: FilePosition,
479 full_import_path: &str, 479 full_import_path: &str,
480 imported_name: String, 480 imported_name: String,
481 import_for_trait_assoc_item: bool,
481 ) -> Cancelable<Vec<TextEdit>> { 482 ) -> Cancelable<Vec<TextEdit>> {
482 Ok(self 483 Ok(self
483 .with_db(|db| { 484 .with_db(|db| {
484 completion::resolve_completion_edits( 485 ide_completion::resolve_completion_edits(
485 db, 486 db,
486 config, 487 config,
487 position, 488 position,
488 full_import_path, 489 full_import_path,
489 imported_name, 490 imported_name,
491 import_for_trait_assoc_item,
490 ) 492 )
491 })? 493 })?
492 .unwrap_or_default()) 494 .unwrap_or_default())
@@ -520,7 +522,7 @@ impl Analysis {
520 &self, 522 &self,
521 position: FilePosition, 523 position: FilePosition,
522 new_name: &str, 524 new_name: &str,
523 ) -> Cancelable<Result<RangeInfo<SourceChange>, RenameError>> { 525 ) -> Cancelable<Result<SourceChange, RenameError>> {
524 self.with_db(|db| references::rename::rename(db, position, new_name)) 526 self.with_db(|db| references::rename::rename(db, position, new_name))
525 } 527 }
526 528
@@ -547,14 +549,27 @@ impl Analysis {
547 selections: Vec<FileRange>, 549 selections: Vec<FileRange>,
548 ) -> Cancelable<Result<SourceChange, SsrError>> { 550 ) -> Cancelable<Result<SourceChange, SsrError>> {
549 self.with_db(|db| { 551 self.with_db(|db| {
550 let rule: ssr::SsrRule = query.parse()?; 552 let rule: ide_ssr::SsrRule = query.parse()?;
551 let mut match_finder = ssr::MatchFinder::in_context(db, resolve_context, selections); 553 let mut match_finder =
554 ide_ssr::MatchFinder::in_context(db, resolve_context, selections);
552 match_finder.add_rule(rule)?; 555 match_finder.add_rule(rule)?;
553 let edits = if parse_only { Default::default() } else { match_finder.edits() }; 556 let edits = if parse_only { Default::default() } else { match_finder.edits() };
554 Ok(SourceChange::from(edits)) 557 Ok(SourceChange::from(edits))
555 }) 558 })
556 } 559 }
557 560
561 pub fn annotations(
562 &self,
563 file_id: FileId,
564 config: AnnotationConfig,
565 ) -> Cancelable<Vec<Annotation>> {
566 self.with_db(|db| annotations::annotations(db, file_id, config))
567 }
568
569 pub fn resolve_annotation(&self, annotation: Annotation) -> Cancelable<Annotation> {
570 self.with_db(|db| annotations::resolve_annotation(db, annotation))
571 }
572
558 /// Performs an operation on that may be Canceled. 573 /// Performs an operation on that may be Canceled.
559 fn with_db<F, T>(&self, f: F) -> Cancelable<T> 574 fn with_db<F, T>(&self, f: F) -> Cancelable<T>
560 where 575 where