44//
55// Copyright (c) 2024, Olof Kraigher olof.kraigher@gmail.com
66use crate :: analysis:: DesignRoot ;
7+ use crate :: completion:: region:: any_ent_to_completion_item;
78use crate :: named_entity:: DesignEnt ;
89use crate :: { AnyEntKind , CompletionItem , Design , EntRef , EntityId , HasEntityId } ;
910use itertools:: Itertools ;
@@ -43,19 +44,15 @@ pub(crate) fn get_visible_entities_from_architecture<'a>(
4344 }
4445 entities
4546 . into_iter ( )
46- . map ( |eid| root. get_ent ( eid) )
47- . map ( |ent| match ent. kind ( ) {
48- AnyEntKind :: Design ( Design :: Entity ( ..) ) => {
49- let architectures = get_architectures_for_entity ( ent, root) ;
50- CompletionItem :: EntityInstantiation ( ent, architectures)
51- }
52- _ => CompletionItem :: Simple ( ent) ,
53- } )
47+ . map ( |eid| any_ent_to_completion_item ( root. get_ent ( eid) , root) )
5448 . collect_vec ( )
5549}
5650
5751/// Returns a vec populated with all architectures that belong to a given entity
58- fn get_architectures_for_entity < ' a > ( ent : EntRef < ' a > , root : & ' a DesignRoot ) -> Vec < EntRef < ' a > > {
52+ pub ( crate ) fn get_architectures_for_entity < ' a > (
53+ ent : EntRef < ' a > ,
54+ root : & ' a DesignRoot ,
55+ ) -> Vec < EntRef < ' a > > {
5956 let Some ( lib_symbol) = ent. library_name ( ) else {
6057 return vec ! [ ] ;
6158 } ;
@@ -111,8 +108,8 @@ end arch;
111108 . search_reference ( code. source ( ) , code. s1 ( "my_other_ent" ) . start ( ) )
112109 . unwrap ( ) ;
113110
114- assert ! ( options. contains( & CompletionItem :: EntityInstantiation ( my_ent, vec![ ] ) ) ) ;
115- assert ! ( options. contains( & CompletionItem :: EntityInstantiation ( my_other_ent, vec![ ] ) ) ) ;
111+ assert ! ( options. contains( & CompletionItem :: Instantiation ( my_ent, vec![ ] ) ) ) ;
112+ assert ! ( options. contains( & CompletionItem :: Instantiation ( my_other_ent, vec![ ] ) ) ) ;
116113 }
117114
118115 #[ test]
@@ -170,7 +167,7 @@ end arch;
170167 . search_reference ( code2. source ( ) , code2. s1 ( "my_ent2" ) . start ( ) )
171168 . unwrap ( ) ;
172169
173- assert ! ( options. contains( & CompletionItem :: EntityInstantiation ( my_ent2, vec![ ] ) ) ) ;
170+ assert ! ( options. contains( & CompletionItem :: Instantiation ( my_ent2, vec![ ] ) ) ) ;
174171
175172 let ent1 = root
176173 . search_reference ( code1. source ( ) , code1. s1 ( "my_ent" ) . start ( ) )
@@ -183,8 +180,8 @@ end arch;
183180 . search_reference ( code3. source ( ) , code3. s1 ( "my_ent2" ) . start ( ) )
184181 . unwrap ( ) ;
185182
186- assert ! ( options. contains( & CompletionItem :: EntityInstantiation ( my_ent2, vec![ ] ) ) ) ;
187- assert ! ( options. contains( & CompletionItem :: EntityInstantiation ( ent1, vec![ ] ) ) ) ;
183+ assert ! ( options. contains( & CompletionItem :: Instantiation ( my_ent2, vec![ ] ) ) ) ;
184+ assert ! ( options. contains( & CompletionItem :: Instantiation ( ent1, vec![ ] ) ) ) ;
188185 }
189186
190187 #[ test]
@@ -238,9 +235,7 @@ end arch;
238235 let applicable_options = options
239236 . into_iter ( )
240237 . filter_map ( |option| match option {
241- CompletionItem :: EntityInstantiation ( ent, architectures) => {
242- Some ( ( ent, architectures) )
243- }
238+ CompletionItem :: Instantiation ( ent, architectures) => Some ( ( ent, architectures) ) ,
244239 _ => None ,
245240 } )
246241 . collect_vec ( ) ;
@@ -253,4 +248,44 @@ end arch;
253248 _ => panic ! ( "Expected entity instantiation" ) ,
254249 }
255250 }
251+
252+ #[ test]
253+ fn component_instantiations ( ) {
254+ let mut builder = LibraryBuilder :: new ( ) ;
255+ let code = builder. code (
256+ "libname" ,
257+ "\
258+ package foo is
259+ component comp_A is
260+ end component;
261+ end foo;
262+
263+ use work.foo.all;
264+
265+ entity my_ent is
266+ end my_ent;
267+
268+ architecture arch1 of my_ent is
269+ component comp_B is
270+ end component;
271+
272+ component comp_C is
273+ end component;
274+ begin
275+ end arch1;
276+ " ,
277+ ) ;
278+
279+ let ( root, diag) = builder. get_analyzed_root ( ) ;
280+ check_no_diagnostics ( & diag[ ..] ) ;
281+ let cursor = code. s1 ( "begin" ) . end ( ) ;
282+ let options = list_completion_options ( & root, code. source ( ) , cursor) ;
283+
284+ for component in [ "comp_A" , "comp_B" , "comp_C" ] {
285+ let entity = root
286+ . search_reference ( code. source ( ) , code. s1 ( component) . start ( ) )
287+ . unwrap ( ) ;
288+ assert ! ( options. contains( & CompletionItem :: Instantiation ( entity, vec![ ] ) ) )
289+ }
290+ }
256291}
0 commit comments