|
4 | 4 | //
|
5 | 5 | // Copyright (c) 2018, Olof Kraigher [email protected]
|
6 | 6 |
|
7 |
| -use crate::analysis::{AnyEnt, DesignRoot, EntRef, Related}; |
8 |
| -use crate::ast::DesignFile; |
| 7 | +use crate::analysis::{AnyEnt, AnyEntKind, DesignRoot, EntRef, Related}; |
| 8 | +use crate::ast::{DesignFile, Designator}; |
9 | 9 | use crate::config::Config;
|
10 | 10 | use crate::data::*;
|
11 | 11 | use crate::syntax::VHDLParser;
|
@@ -237,6 +237,34 @@ impl Project {
|
237 | 237 | }
|
238 | 238 | }
|
239 | 239 |
|
| 240 | + /// Find entity with same name as component in the library |
| 241 | + pub fn find_implementation<'a>( |
| 242 | + &'a self, |
| 243 | + source: &Source, |
| 244 | + cursor: Position, |
| 245 | + ) -> Option<EntRef<'a>> { |
| 246 | + let ent = self.find_declaration(source, cursor)?; |
| 247 | + if !matches!(ent.kind(), AnyEntKind::Component(_)) { |
| 248 | + return None; |
| 249 | + } |
| 250 | + |
| 251 | + let ident = if let Designator::Identifier(ident) = ent.designator() { |
| 252 | + ident |
| 253 | + } else { |
| 254 | + return None; |
| 255 | + }; |
| 256 | + |
| 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()); |
| 263 | + } |
| 264 | + } |
| 265 | + None |
| 266 | + } |
| 267 | + |
240 | 268 | /// Search for the declaration at decl_pos and format it
|
241 | 269 | pub fn format_declaration(&self, ent: &AnyEnt) -> Option<String> {
|
242 | 270 | self.root.format_declaration(ent)
|
|
0 commit comments