aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/lib.rs')
-rw-r--r--crates/ra_ide/src/lib.rs142
1 files changed, 37 insertions, 105 deletions
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs
index ecac5134e..0fede0d87 100644
--- a/crates/ra_ide/src/lib.rs
+++ b/crates/ra_ide/src/lib.rs
@@ -17,30 +17,33 @@ macro_rules! eprintln {
17 17
18pub mod mock_analysis; 18pub mod mock_analysis;
19 19
20mod markup;
20mod prime_caches; 21mod prime_caches;
21mod status; 22mod display;
23
24mod call_hierarchy;
25mod call_info;
22mod completion; 26mod completion;
23mod runnables; 27mod diagnostics;
28mod expand_macro;
29mod extend_selection;
30mod file_structure;
31mod folding_ranges;
24mod goto_definition; 32mod goto_definition;
25mod goto_type_definition;
26mod goto_implementation; 33mod goto_implementation;
27mod extend_selection; 34mod goto_type_definition;
28mod hover; 35mod hover;
29mod call_hierarchy; 36mod inlay_hints;
30mod call_info; 37mod join_lines;
31mod syntax_highlighting; 38mod matching_brace;
32mod parent_module; 39mod parent_module;
33mod references; 40mod references;
34mod diagnostics; 41mod runnables;
42mod ssr;
43mod status;
44mod syntax_highlighting;
35mod syntax_tree; 45mod syntax_tree;
36mod folding_ranges;
37mod join_lines;
38mod typing; 46mod typing;
39mod matching_brace;
40mod display;
41mod inlay_hints;
42mod expand_macro;
43mod ssr;
44 47
45use std::sync::Arc; 48use std::sync::Arc;
46 49
@@ -59,15 +62,18 @@ use crate::display::ToNav;
59 62
60pub use crate::{ 63pub use crate::{
61 call_hierarchy::CallItem, 64 call_hierarchy::CallItem,
65 call_info::CallInfo,
62 completion::{ 66 completion::{
63 CompletionConfig, CompletionItem, CompletionItemKind, CompletionScore, InsertTextFormat, 67 CompletionConfig, CompletionItem, CompletionItemKind, CompletionScore, InsertTextFormat,
64 }, 68 },
65 diagnostics::Severity, 69 diagnostics::Severity,
66 display::{file_structure, FunctionSignature, NavigationTarget, StructureNode}, 70 display::NavigationTarget,
67 expand_macro::ExpandedMacro, 71 expand_macro::ExpandedMacro,
72 file_structure::StructureNode,
68 folding_ranges::{Fold, FoldKind}, 73 folding_ranges::{Fold, FoldKind},
69 hover::{HoverAction, HoverConfig, HoverGotoTypeData, HoverResult}, 74 hover::{HoverAction, HoverConfig, HoverGotoTypeData, HoverResult},
70 inlay_hints::{InlayHint, InlayHintsConfig, InlayKind}, 75 inlay_hints::{InlayHint, InlayHintsConfig, InlayKind},
76 markup::Markup,
71 references::{Declaration, Reference, ReferenceAccess, ReferenceKind, ReferenceSearchResult}, 77 references::{Declaration, Reference, ReferenceAccess, ReferenceKind, ReferenceSearchResult},
72 runnables::{Runnable, RunnableKind, TestId}, 78 runnables::{Runnable, RunnableKind, TestId},
73 syntax_highlighting::{ 79 syntax_highlighting::{
@@ -75,8 +81,8 @@ pub use crate::{
75 }, 81 },
76}; 82};
77 83
78pub use hir::Documentation; 84pub use hir::{Documentation, Semantics};
79pub use ra_assists::{Assist, AssistConfig, AssistId, ResolvedAssist}; 85pub use ra_assists::{Assist, AssistConfig, AssistId, AssistKind, ResolvedAssist};
80pub use ra_db::{ 86pub use ra_db::{
81 Canceled, CrateGraph, CrateId, Edition, FileId, FilePosition, FileRange, SourceRoot, 87 Canceled, CrateGraph, CrateId, Edition, FileId, FilePosition, FileRange, SourceRoot,
82 SourceRootId, 88 SourceRootId,
@@ -129,14 +135,6 @@ impl<T> RangeInfo<T> {
129 } 135 }
130} 136}
131 137
132/// Contains information about a call site. Specifically the
133/// `FunctionSignature`and current parameter.
134#[derive(Debug)]
135pub struct CallInfo {
136 pub signature: FunctionSignature,
137 pub active_parameter: Option<usize>,
138}
139
140/// `AnalysisHost` stores the current state of the world. 138/// `AnalysisHost` stores the current state of the world.
141#[derive(Debug)] 139#[derive(Debug)]
142pub struct AnalysisHost { 140pub struct AnalysisHost {
@@ -328,7 +326,7 @@ impl Analysis {
328 /// Returns a tree representation of symbols in the file. Useful to draw a 326 /// Returns a tree representation of symbols in the file. Useful to draw a
329 /// file outline. 327 /// file outline.
330 pub fn file_structure(&self, file_id: FileId) -> Cancelable<Vec<StructureNode>> { 328 pub fn file_structure(&self, file_id: FileId) -> Cancelable<Vec<StructureNode>> {
331 self.with_db(|db| file_structure(&db.parse(file_id).tree())) 329 self.with_db(|db| file_structure::file_structure(&db.parse(file_id).tree()))
332 } 330 }
333 331
334 /// Returns a list of the places in the file where type hints can be displayed. 332 /// Returns a list of the places in the file where type hints can be displayed.
@@ -385,7 +383,9 @@ impl Analysis {
385 position: FilePosition, 383 position: FilePosition,
386 search_scope: Option<SearchScope>, 384 search_scope: Option<SearchScope>,
387 ) -> Cancelable<Option<ReferenceSearchResult>> { 385 ) -> Cancelable<Option<ReferenceSearchResult>> {
388 self.with_db(|db| references::find_all_refs(db, position, search_scope).map(|it| it.info)) 386 self.with_db(|db| {
387 references::find_all_refs(&Semantics::new(db), position, search_scope).map(|it| it.info)
388 })
389 } 389 }
390 390
391 /// Returns a short text describing element at position. 391 /// Returns a short text describing element at position.
@@ -487,8 +487,12 @@ impl Analysis {
487 } 487 }
488 488
489 /// Computes the set of diagnostics for the given file. 489 /// Computes the set of diagnostics for the given file.
490 pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> { 490 pub fn diagnostics(
491 self.with_db(|db| diagnostics::diagnostics(db, file_id)) 491 &self,
492 file_id: FileId,
493 enable_experimental: bool,
494 ) -> Cancelable<Vec<Diagnostic>> {
495 self.with_db(|db| diagnostics::diagnostics(db, file_id, enable_experimental))
492 } 496 }
493 497
494 /// Returns the edit required to rename reference at the position to the new 498 /// Returns the edit required to rename reference at the position to the new
@@ -505,9 +509,11 @@ impl Analysis {
505 &self, 509 &self,
506 query: &str, 510 query: &str,
507 parse_only: bool, 511 parse_only: bool,
512 position: FilePosition,
513 selections: Vec<FileRange>,
508 ) -> Cancelable<Result<SourceChange, SsrError>> { 514 ) -> Cancelable<Result<SourceChange, SsrError>> {
509 self.with_db(|db| { 515 self.with_db(|db| {
510 let edits = ssr::parse_search_replace(query, parse_only, db)?; 516 let edits = ssr::parse_search_replace(query, parse_only, db, position, selections)?;
511 Ok(SourceChange::from(edits)) 517 Ok(SourceChange::from(edits))
512 }) 518 })
513 } 519 }
@@ -526,77 +532,3 @@ fn analysis_is_send() {
526 fn is_send<T: Send>() {} 532 fn is_send<T: Send>() {}
527 is_send::<Analysis>(); 533 is_send::<Analysis>();
528} 534}
529
530#[cfg(test)]
531mod tests {
532 use crate::{display::NavigationTarget, mock_analysis::single_file, Query};
533 use ra_syntax::{
534 SmolStr,
535 SyntaxKind::{FN_DEF, STRUCT_DEF},
536 };
537
538 #[test]
539 fn test_world_symbols_with_no_container() {
540 let code = r#"
541 enum FooInner { }
542 "#;
543
544 let mut symbols = get_symbols_matching(code, "FooInner");
545
546 let s = symbols.pop().unwrap();
547
548 assert_eq!(s.name(), "FooInner");
549 assert!(s.container_name().is_none());
550 }
551
552 #[test]
553 fn test_world_symbols_include_container_name() {
554 let code = r#"
555fn foo() {
556 enum FooInner { }
557}
558 "#;
559
560 let mut symbols = get_symbols_matching(code, "FooInner");
561
562 let s = symbols.pop().unwrap();
563
564 assert_eq!(s.name(), "FooInner");
565 assert_eq!(s.container_name(), Some(&SmolStr::new("foo")));
566
567 let code = r#"
568mod foo {
569 struct FooInner;
570}
571 "#;
572
573 let mut symbols = get_symbols_matching(code, "FooInner");
574
575 let s = symbols.pop().unwrap();
576
577 assert_eq!(s.name(), "FooInner");
578 assert_eq!(s.container_name(), Some(&SmolStr::new("foo")));
579 }
580
581 #[test]
582 fn test_world_symbols_are_case_sensitive() {
583 let code = r#"
584fn foo() {}
585
586struct Foo;
587 "#;
588
589 let symbols = get_symbols_matching(code, "Foo");
590
591 let fn_match = symbols.iter().find(|s| s.name() == "foo").map(|s| s.kind());
592 let struct_match = symbols.iter().find(|s| s.name() == "Foo").map(|s| s.kind());
593
594 assert_eq!(fn_match, Some(FN_DEF));
595 assert_eq!(struct_match, Some(STRUCT_DEF));
596 }
597
598 fn get_symbols_matching(text: &str, query: &str) -> Vec<NavigationTarget> {
599 let (analysis, _) = single_file(text);
600 analysis.symbol_search(Query::new(query.into())).unwrap()
601 }
602}