diff --git a/vhdl_lang/src/completion/entity_instantiation.rs b/vhdl_lang/src/completion/entity_instantiation.rs index d606adaa..0b62e553 100644 --- a/vhdl_lang/src/completion/entity_instantiation.rs +++ b/vhdl_lang/src/completion/entity_instantiation.rs @@ -288,4 +288,44 @@ end arch1; assert!(options.contains(&CompletionItem::Instantiation(entity, vec![]))) } } + + #[test] + fn complete_entities_in_block() { + let mut builder = LibraryBuilder::new(); + let code = builder.code( + "libname", + "\ +entity my_ent is +end my_ent; + +entity my_other_ent is +end my_other_ent; + +entity my_third_ent is +end my_third_ent; + +architecture arch of my_third_ent is +begin + foo: block is + begin + end block foo; +end arch; + ", + ); + + let (root, _) = builder.get_analyzed_root(); + let cursor = code.s("begin", 2).end(); + let options = list_completion_options(&root, code.source(), cursor); + + let my_ent = root + .search_reference(code.source(), code.s1("my_ent").start()) + .unwrap(); + + let my_other_ent = root + .search_reference(code.source(), code.s1("my_other_ent").start()) + .unwrap(); + + assert!(options.contains(&CompletionItem::Instantiation(my_ent, vec![]))); + assert!(options.contains(&CompletionItem::Instantiation(my_other_ent, vec![]))); + } } diff --git a/vhdl_lang/src/completion/generic.rs b/vhdl_lang/src/completion/generic.rs index 9b875e05..bfd8f8de 100644 --- a/vhdl_lang/src/completion/generic.rs +++ b/vhdl_lang/src/completion/generic.rs @@ -47,26 +47,13 @@ impl<'a> CompletionSearcher<'a> { impl<'a> CompletionSearcher<'a> { /// Add entity instantiation completions that are visible from within an architecture body - fn add_entity_instantiations(&mut self, ctx: &dyn TokenAccess, body: &ArchitectureBody) { + fn add_entity_instantiations(&mut self, body: &ArchitectureBody) { let Some(ent_id) = body.ident.decl.get() else { return; }; let Some(ent) = DesignEnt::from_any(self.root.get_ent(ent_id)) else { return; }; - // Early-exit for when we are inside a statement. - for statement in &body.statements { - let pos = &statement.statement.pos(ctx); - - // Early exit. The cursor is below the current statement. - if pos.start() > self.cursor { - break; - } - - if pos.contains(self.cursor) { - return; - } - } self.completions .extend(get_visible_entities_from_architecture(self.root, &ent)); } @@ -85,7 +72,7 @@ impl<'a> Searcher for CompletionSearcher<'a> { if !body.get_pos(ctx).contains(self.cursor) { return NotFinished; } - self.add_entity_instantiations(ctx, body); + self.add_entity_instantiations(body); body.ident.decl.get() } DeclarationItem::Package(package) => {