diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-13 16:17:10 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-13 16:17:10 +0000 |
commit | 65266c644a31e6b321e5afb3c5a2ee75be76cb0c (patch) | |
tree | adde5d96c9f4b0ecd33fd49d8c9fd13004135cab /crates/ra_ide_api/tests/test | |
parent | 74d03d57e77b791b6973497f17a35136ddc295ab (diff) | |
parent | 3973974de133867c46727ed516b0445d7f1cb63f (diff) |
Merge #813
813: Add support for container_name in workspace/symbol query r=matklad a=vipentti
Currently this does not fill in the container_info if a type is defined on the top level in a file.
e.g. `foo.rs`
```rust
enum Foo { }
```
`Foo` will have None as the container_name, however
```rust
mod foo_mod {
enum Foo { }
}
```
`Foo` has `foo_mod` as the container_name.
This closes #559
Co-authored-by: Ville Penttinen <[email protected]>
Diffstat (limited to 'crates/ra_ide_api/tests/test')
-rw-r--r-- | crates/ra_ide_api/tests/test/main.rs | 52 |
1 files changed, 50 insertions, 2 deletions
diff --git a/crates/ra_ide_api/tests/test/main.rs b/crates/ra_ide_api/tests/test/main.rs index 7d1695cfd..4cf842452 100644 --- a/crates/ra_ide_api/tests/test/main.rs +++ b/crates/ra_ide_api/tests/test/main.rs | |||
@@ -1,9 +1,9 @@ | |||
1 | use insta::assert_debug_snapshot_matches; | 1 | use insta::assert_debug_snapshot_matches; |
2 | use ra_ide_api::{ | 2 | use ra_ide_api::{ |
3 | mock_analysis::{single_file, single_file_with_position, MockAnalysis}, | 3 | mock_analysis::{single_file, single_file_with_position, MockAnalysis}, |
4 | AnalysisChange, CrateGraph, FileId, Query, | 4 | AnalysisChange, CrateGraph, FileId, Query, NavigationTarget, |
5 | }; | 5 | }; |
6 | use ra_syntax::TextRange; | 6 | use ra_syntax::{TextRange, SmolStr}; |
7 | 7 | ||
8 | #[test] | 8 | #[test] |
9 | fn test_unresolved_module_diagnostic() { | 9 | fn test_unresolved_module_diagnostic() { |
@@ -49,6 +49,11 @@ fn get_all_refs(text: &str) -> Vec<(FileId, TextRange)> { | |||
49 | analysis.find_all_refs(position).unwrap() | 49 | analysis.find_all_refs(position).unwrap() |
50 | } | 50 | } |
51 | 51 | ||
52 | fn get_symbols_matching(text: &str, query: &str) -> Vec<NavigationTarget> { | ||
53 | let (analysis, _) = single_file(text); | ||
54 | analysis.symbol_search(Query::new(query.into())).unwrap() | ||
55 | } | ||
56 | |||
52 | #[test] | 57 | #[test] |
53 | fn test_find_all_refs_for_local() { | 58 | fn test_find_all_refs_for_local() { |
54 | let code = r#" | 59 | let code = r#" |
@@ -91,6 +96,49 @@ fn test_find_all_refs_for_fn_param() { | |||
91 | } | 96 | } |
92 | 97 | ||
93 | #[test] | 98 | #[test] |
99 | fn test_world_symbols_with_no_container() { | ||
100 | let code = r#" | ||
101 | enum FooInner { } | ||
102 | "#; | ||
103 | |||
104 | let mut symbols = get_symbols_matching(code, "FooInner"); | ||
105 | |||
106 | let s = symbols.pop().unwrap(); | ||
107 | |||
108 | assert_eq!(s.name(), "FooInner"); | ||
109 | assert!(s.container_name().is_none()); | ||
110 | } | ||
111 | |||
112 | #[test] | ||
113 | fn test_world_symbols_include_container_name() { | ||
114 | let code = r#" | ||
115 | fn foo() { | ||
116 | enum FooInner { } | ||
117 | } | ||
118 | "#; | ||
119 | |||
120 | let mut symbols = get_symbols_matching(code, "FooInner"); | ||
121 | |||
122 | let s = symbols.pop().unwrap(); | ||
123 | |||
124 | assert_eq!(s.name(), "FooInner"); | ||
125 | assert_eq!(s.container_name(), Some(&SmolStr::new("foo"))); | ||
126 | |||
127 | let code = r#" | ||
128 | mod foo { | ||
129 | struct FooInner; | ||
130 | } | ||
131 | "#; | ||
132 | |||
133 | let mut symbols = get_symbols_matching(code, "FooInner"); | ||
134 | |||
135 | let s = symbols.pop().unwrap(); | ||
136 | |||
137 | assert_eq!(s.name(), "FooInner"); | ||
138 | assert_eq!(s.container_name(), Some(&SmolStr::new("foo"))); | ||
139 | } | ||
140 | |||
141 | #[test] | ||
94 | #[ignore] | 142 | #[ignore] |
95 | fn world_symbols_include_stuff_from_macros() { | 143 | fn world_symbols_include_stuff_from_macros() { |
96 | let (analysis, _) = single_file( | 144 | let (analysis, _) = single_file( |