diff options
author | Aleksey Kladov <[email protected]> | 2019-01-05 17:00:03 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-05 17:00:03 +0000 |
commit | ee461a211195b093269ead477f01fcf63f20cf34 (patch) | |
tree | 9021f6b236ce24d19a7a419c9f8c9c08c9ff08f4 /crates/ra_analysis/src/imp.rs | |
parent | da32463cbf8dc32229eb13844c71a40df2d3b77e (diff) |
kill approximatelly_resolve_symbol
Diffstat (limited to 'crates/ra_analysis/src/imp.rs')
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 62 |
1 files changed, 1 insertions, 61 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 6df118c20..6ab3c5476 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs | |||
@@ -18,7 +18,7 @@ use crate::{ | |||
18 | AnalysisChange, | 18 | AnalysisChange, |
19 | Cancelable, NavigationTarget, | 19 | Cancelable, NavigationTarget, |
20 | CrateId, db, Diagnostic, FileId, FilePosition, FileRange, FileSystemEdit, | 20 | CrateId, db, Diagnostic, FileId, FilePosition, FileRange, FileSystemEdit, |
21 | Query, ReferenceResolution, RootChange, SourceChange, SourceFileEdit, | 21 | Query, RootChange, SourceChange, SourceFileEdit, |
22 | symbol_index::{LibrarySymbolsQuery, FileSymbol}, | 22 | symbol_index::{LibrarySymbolsQuery, FileSymbol}, |
23 | }; | 23 | }; |
24 | 24 | ||
@@ -139,66 +139,6 @@ impl db::RootDatabase { | |||
139 | pub(crate) fn crate_root(&self, crate_id: CrateId) -> FileId { | 139 | pub(crate) fn crate_root(&self, crate_id: CrateId) -> FileId { |
140 | self.crate_graph().crate_root(crate_id) | 140 | self.crate_graph().crate_root(crate_id) |
141 | } | 141 | } |
142 | pub(crate) fn approximately_resolve_symbol( | ||
143 | &self, | ||
144 | position: FilePosition, | ||
145 | ) -> Cancelable<Option<ReferenceResolution>> { | ||
146 | let file = self.source_file(position.file_id); | ||
147 | let syntax = file.syntax(); | ||
148 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, position.offset) { | ||
149 | let mut rr = ReferenceResolution::new(name_ref.syntax().range()); | ||
150 | if let Some(fn_descr) = | ||
151 | source_binder::function_from_child_node(self, position.file_id, name_ref.syntax())? | ||
152 | { | ||
153 | let scope = fn_descr.scopes(self); | ||
154 | // First try to resolve the symbol locally | ||
155 | if let Some(entry) = scope.resolve_local_name(name_ref) { | ||
156 | rr.resolves_to.push(NavigationTarget { | ||
157 | file_id: position.file_id, | ||
158 | name: entry.name().to_string().into(), | ||
159 | range: entry.ptr().range(), | ||
160 | kind: NAME, | ||
161 | ptr: None, | ||
162 | }); | ||
163 | return Ok(Some(rr)); | ||
164 | }; | ||
165 | } | ||
166 | // If that fails try the index based approach. | ||
167 | rr.resolves_to.extend( | ||
168 | self.index_resolve(name_ref)? | ||
169 | .into_iter() | ||
170 | .map(NavigationTarget::from_symbol), | ||
171 | ); | ||
172 | return Ok(Some(rr)); | ||
173 | } | ||
174 | if let Some(name) = find_node_at_offset::<ast::Name>(syntax, position.offset) { | ||
175 | let mut rr = ReferenceResolution::new(name.syntax().range()); | ||
176 | if let Some(module) = name.syntax().parent().and_then(ast::Module::cast) { | ||
177 | if module.has_semi() { | ||
178 | if let Some(child_module) = | ||
179 | source_binder::module_from_declaration(self, position.file_id, module)? | ||
180 | { | ||
181 | let file_id = child_module.file_id(); | ||
182 | let name = match child_module.name() { | ||
183 | Some(name) => name.to_string().into(), | ||
184 | None => "".into(), | ||
185 | }; | ||
186 | let symbol = NavigationTarget { | ||
187 | file_id, | ||
188 | name, | ||
189 | range: TextRange::offset_len(0.into(), 0.into()), | ||
190 | kind: MODULE, | ||
191 | ptr: None, | ||
192 | }; | ||
193 | rr.resolves_to.push(symbol); | ||
194 | return Ok(Some(rr)); | ||
195 | } | ||
196 | } | ||
197 | } | ||
198 | } | ||
199 | Ok(None) | ||
200 | } | ||
201 | |||
202 | pub(crate) fn find_all_refs( | 142 | pub(crate) fn find_all_refs( |
203 | &self, | 143 | &self, |
204 | position: FilePosition, | 144 | position: FilePosition, |