|
4 | 4 | //
|
5 | 5 | // Copyright (c) 2018, Olof Kraigher [email protected]
|
6 | 6 |
|
7 |
| -use crate::analysis::{AnyEnt, AnyEntKind, DesignRoot, EntRef, Related}; |
| 7 | +use crate::analysis::{AnyEnt, AnyEntKind, Design, DesignRoot, EntRef, Related}; |
| 8 | +use crate::ast::search::FindAllEnt; |
8 | 9 | use crate::ast::{DesignFile, Designator};
|
9 | 10 | use crate::config::Config;
|
10 | 11 | use crate::data::*;
|
@@ -237,32 +238,50 @@ impl Project {
|
237 | 238 | }
|
238 | 239 | }
|
239 | 240 |
|
240 |
| - /// Find entity with same name as component in the library |
| 241 | + fn get_library(&self, source: &Source) -> Option<Symbol> { |
| 242 | + let file = self.files.get(source.file_name())?; |
| 243 | + file.library_names.iter().next().cloned() |
| 244 | + } |
| 245 | + |
241 | 246 | pub fn find_implementation<'a>(
|
242 | 247 | &'a self,
|
243 | 248 | source: &Source,
|
244 | 249 | cursor: Position,
|
245 |
| - ) -> Option<EntRef<'a>> { |
| 250 | + ) -> Option<Vec<EntRef<'a>>> { |
246 | 251 | let ent = self.find_declaration(source, cursor)?;
|
247 |
| - if !matches!(ent.kind(), AnyEntKind::Component(_)) { |
248 |
| - return None; |
249 |
| - } |
250 | 252 |
|
251 | 253 | let ident = if let Designator::Identifier(ident) = ent.designator() {
|
252 | 254 | ident
|
253 | 255 | } else {
|
254 | 256 | return None;
|
255 | 257 | };
|
256 | 258 |
|
257 |
| - let decl_pos = ent.decl_pos()?; |
258 |
| - |
259 |
| - let file = self.files.get(decl_pos.source().file_name())?; |
260 |
| - for library_name in file.library_names.iter() { |
261 |
| - if let Some(design) = self.root.get_design_entity(library_name, ident) { |
262 |
| - return Some(design.into()); |
| 259 | + match ent.kind() { |
| 260 | + // Find entity with same name as component in the library |
| 261 | + AnyEntKind::Component(_) => { |
| 262 | + let decl_pos = ent.decl_pos()?; |
| 263 | + let library_name = self.get_library(decl_pos.source())?; |
| 264 | + let design = self.root.get_design_entity(&library_name, ident)?; |
| 265 | + Some(vec![design.into()]) |
| 266 | + } |
| 267 | + // Find all components with same name as entity in the library |
| 268 | + AnyEntKind::Design(Design::Entity(..)) => { |
| 269 | + let decl_pos = ent.decl_pos()?; |
| 270 | + let library_name = self.get_library(decl_pos.source())?; |
| 271 | + |
| 272 | + let mut searcher = FindAllEnt::new(&self.root, |ent| { |
| 273 | + matches!(ent.kind(), AnyEntKind::Component(_)) |
| 274 | + && matches!( |
| 275 | + ent.designator(), |
| 276 | + Designator::Identifier(comp_ident) if comp_ident == ident |
| 277 | + ) |
| 278 | + }); |
| 279 | + |
| 280 | + let _ = self.root.search_library(&library_name, &mut searcher); |
| 281 | + Some(searcher.result) |
263 | 282 | }
|
| 283 | + _ => None, |
264 | 284 | }
|
265 |
| - None |
266 | 285 | }
|
267 | 286 |
|
268 | 287 | /// Search for the declaration at decl_pos and format it
|
|
0 commit comments