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.rs122
1 files changed, 23 insertions, 99 deletions
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs
index dcfa186dc..dc9192d42 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::{
@@ -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.
@@ -528,77 +526,3 @@ fn analysis_is_send() {
528 fn is_send<T: Send>() {} 526 fn is_send<T: Send>() {}
529 is_send::<Analysis>(); 527 is_send::<Analysis>();
530} 528}
531
532#[cfg(test)]
533mod tests {
534 use crate::{display::NavigationTarget, mock_analysis::single_file, Query};
535 use ra_syntax::{
536 SmolStr,
537 SyntaxKind::{FN_DEF, STRUCT_DEF},
538 };
539
540 #[test]
541 fn test_world_symbols_with_no_container() {
542 let code = r#"
543 enum FooInner { }
544 "#;
545
546 let mut symbols = get_symbols_matching(code, "FooInner");
547
548 let s = symbols.pop().unwrap();
549
550 assert_eq!(s.name(), "FooInner");
551 assert!(s.container_name().is_none());
552 }
553
554 #[test]
555 fn test_world_symbols_include_container_name() {
556 let code = r#"
557fn foo() {
558 enum FooInner { }
559}
560 "#;
561
562 let mut symbols = get_symbols_matching(code, "FooInner");
563
564 let s = symbols.pop().unwrap();
565
566 assert_eq!(s.name(), "FooInner");
567 assert_eq!(s.container_name(), Some(&SmolStr::new("foo")));
568
569 let code = r#"
570mod foo {
571 struct FooInner;
572}
573 "#;
574
575 let mut symbols = get_symbols_matching(code, "FooInner");
576
577 let s = symbols.pop().unwrap();
578
579 assert_eq!(s.name(), "FooInner");
580 assert_eq!(s.container_name(), Some(&SmolStr::new("foo")));
581 }
582
583 #[test]
584 fn test_world_symbols_are_case_sensitive() {
585 let code = r#"
586fn foo() {}
587
588struct Foo;
589 "#;
590
591 let symbols = get_symbols_matching(code, "Foo");
592
593 let fn_match = symbols.iter().find(|s| s.name() == "foo").map(|s| s.kind());
594 let struct_match = symbols.iter().find(|s| s.name() == "Foo").map(|s| s.kind());
595
596 assert_eq!(fn_match, Some(FN_DEF));
597 assert_eq!(struct_match, Some(STRUCT_DEF));
598 }
599
600 fn get_symbols_matching(text: &str, query: &str) -> Vec<NavigationTarget> {
601 let (analysis, _) = single_file(text);
602 analysis.symbol_search(Query::new(query.into())).unwrap()
603 }
604}