Skip to content

Commit

Permalink
Always suggest instantiation completions in the architecture statemen…
Browse files Browse the repository at this point in the history
…ts part
  • Loading branch information
Schottkyc137 committed Jul 28, 2024
1 parent 86eb38e commit ff09201
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 15 deletions.
40 changes: 40 additions & 0 deletions vhdl_lang/src/completion/entity_instantiation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![])));
}
}
17 changes: 2 additions & 15 deletions vhdl_lang/src/completion/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -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) => {
Expand Down

0 comments on commit ff09201

Please sign in to comment.