diff options
Diffstat (limited to 'crates/ra_ide_db')
-rw-r--r-- | crates/ra_ide_db/src/search.rs | 40 | ||||
-rw-r--r-- | crates/ra_ide_db/src/symbol_index.rs | 21 |
2 files changed, 43 insertions, 18 deletions
diff --git a/crates/ra_ide_db/src/search.rs b/crates/ra_ide_db/src/search.rs index 589f44771..335a1ad03 100644 --- a/crates/ra_ide_db/src/search.rs +++ b/crates/ra_ide_db/src/search.rs | |||
@@ -124,29 +124,33 @@ impl Definition { | |||
124 | 124 | ||
125 | let vis = self.visibility(db); | 125 | let vis = self.visibility(db); |
126 | 126 | ||
127 | // FIXME: | ||
128 | // The following logic are wrong that it does not search | ||
129 | // for submodules within other files recursively. | ||
130 | |||
131 | if let Some(Visibility::Module(module)) = vis.and_then(|it| it.into()) { | 127 | if let Some(Visibility::Module(module)) = vis.and_then(|it| it.into()) { |
132 | let module: Module = module.into(); | 128 | let module: Module = module.into(); |
133 | let mut res = FxHashMap::default(); | 129 | let mut res = FxHashMap::default(); |
134 | let src = module.definition_source(db); | ||
135 | let file_id = src.file_id.original_file(db); | ||
136 | 130 | ||
137 | match src.value { | 131 | let mut to_visit = vec![module]; |
138 | ModuleSource::Module(m) => { | 132 | let mut is_first = true; |
139 | let range = Some(m.syntax().text_range()); | 133 | while let Some(module) = to_visit.pop() { |
140 | res.insert(file_id, range); | 134 | let src = module.definition_source(db); |
141 | } | 135 | let file_id = src.file_id.original_file(db); |
142 | ModuleSource::SourceFile(_) => { | 136 | match src.value { |
143 | res.insert(file_id, None); | 137 | ModuleSource::Module(m) => { |
144 | res.extend(module.children(db).map(|m| { | 138 | if is_first { |
145 | let src = m.definition_source(db); | 139 | let range = Some(m.syntax().text_range()); |
146 | (src.file_id.original_file(db), None) | 140 | res.insert(file_id, range); |
147 | })); | 141 | } else { |
148 | } | 142 | // We have already added the enclosing file to the search scope, |
143 | // so do nothing. | ||
144 | } | ||
145 | } | ||
146 | ModuleSource::SourceFile(_) => { | ||
147 | res.insert(file_id, None); | ||
148 | } | ||
149 | }; | ||
150 | is_first = false; | ||
151 | to_visit.extend(module.children(db)); | ||
149 | } | 152 | } |
153 | |||
150 | return SearchScope::new(res); | 154 | return SearchScope::new(res); |
151 | } | 155 | } |
152 | 156 | ||
diff --git a/crates/ra_ide_db/src/symbol_index.rs b/crates/ra_ide_db/src/symbol_index.rs index 95be11134..acc31fe3b 100644 --- a/crates/ra_ide_db/src/symbol_index.rs +++ b/crates/ra_ide_db/src/symbol_index.rs | |||
@@ -110,6 +110,27 @@ fn file_symbols(db: &impl SymbolsDatabase, file_id: FileId) -> Arc<SymbolIndex> | |||
110 | Arc::new(SymbolIndex::new(symbols)) | 110 | Arc::new(SymbolIndex::new(symbols)) |
111 | } | 111 | } |
112 | 112 | ||
113 | // Feature: Workspace Symbol | ||
114 | // | ||
115 | // Uses fuzzy-search to find types, modules and functions by name across your | ||
116 | // project and dependencies. This is **the** most useful feature, which improves code | ||
117 | // navigation tremendously. It mostly works on top of the built-in LSP | ||
118 | // functionality, however `#` and `*` symbols can be used to narrow down the | ||
119 | // search. Specifically, | ||
120 | // | ||
121 | // - `Foo` searches for `Foo` type in the current workspace | ||
122 | // - `foo#` searches for `foo` function in the current workspace | ||
123 | // - `Foo*` searches for `Foo` type among dependencies, including `stdlib` | ||
124 | // - `foo#*` searches for `foo` function among dependencies | ||
125 | // | ||
126 | // That is, `#` switches from "types" to all symbols, `*` switches from the current | ||
127 | // workspace to dependencies. | ||
128 | // | ||
129 | // |=== | ||
130 | // | Editor | Shortcut | ||
131 | // | ||
132 | // | VS Code | kbd:[Ctrl+T] | ||
133 | // |=== | ||
113 | pub fn world_symbols(db: &RootDatabase, query: Query) -> Vec<FileSymbol> { | 134 | pub fn world_symbols(db: &RootDatabase, query: Query) -> Vec<FileSymbol> { |
114 | /// Need to wrap Snapshot to provide `Clone` impl for `map_with` | 135 | /// Need to wrap Snapshot to provide `Clone` impl for `map_with` |
115 | struct Snap(salsa::Snapshot<RootDatabase>); | 136 | struct Snap(salsa::Snapshot<RootDatabase>); |