Skip to content

Commit

Permalink
Improved completions (#313)
Browse files Browse the repository at this point in the history
This commit adds specific completions for selected names and attributes. It also extends the completion capabilities to entities, packages and package bodies (previously, this was only possible in architectures). Furthermore, all visible symbols from entities, packages and architectures are included for the generic completion provider. Previously, only symbols in the declarative part of architectures were includes.
  • Loading branch information
Schottkyc137 committed Jun 30, 2024
1 parent a367577 commit 16d9e5e
Show file tree
Hide file tree
Showing 40 changed files with 1,717 additions and 1,048 deletions.
6 changes: 3 additions & 3 deletions vhdl_lang/src/analysis/declarative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Declaration {
| View(_)
),
// LRM: package_body_declarative_item
AnyEntKind::Design(Design::PackageBody | Design::UninstPackage(..))
AnyEntKind::Design(Design::PackageBody(..) | Design::UninstPackage(..))
| AnyEntKind::Overloaded(
Overloaded::SubprogramDecl(_)
| Overloaded::Subprogram(_)
Expand Down Expand Up @@ -1173,11 +1173,11 @@ fn get_entity_class(ent: EntRef) -> Option<EntityClass> {
AnyEntKind::Library => None,
AnyEntKind::Design(des) => match des {
Design::Entity(_, _) => Some(EntityClass::Entity),
Design::Architecture(_) => Some(EntityClass::Architecture),
Design::Architecture(..) => Some(EntityClass::Architecture),
Design::Configuration => Some(EntityClass::Configuration),
Design::Package(_, _) => Some(EntityClass::Package),
// Should never be target of attribute
Design::PackageBody => None,
Design::PackageBody(..) => None,
Design::UninstPackage(_, _) => None,
Design::PackageInstance(_) => None,
Design::InterfacePackageInstance(_) => None,
Expand Down
29 changes: 27 additions & 2 deletions vhdl_lang/src/analysis/design_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,11 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
self.ctx,
&mut unit.ident,
primary.into(),
AnyEntKind::Design(Design::Architecture(primary)),
AnyEntKind::Design(Design::Architecture(
Visibility::default(),
Region::default(),
primary,
)),
src_span,
Some(self.source()),
);
Expand All @@ -294,6 +298,15 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
self.analyze_declarative_part(&scope, arch, &mut unit.decl, diagnostics)?;
self.analyze_concurrent_part(&scope, arch, &mut unit.statements, diagnostics)?;
scope.close(diagnostics);

let region = scope.into_region();
let visibility = root_scope.into_visibility();

unsafe {
arch.set_kind(AnyEntKind::Design(Design::Architecture(
visibility, region, primary,
)))
}
Ok(())
}

Expand Down Expand Up @@ -334,7 +347,10 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
unit.ident.name().clone().into(),
Some(self.work_library()),
Related::DeclaredBy(primary.into()),
AnyEntKind::Design(Design::PackageBody),
AnyEntKind::Design(Design::PackageBody(
Visibility::default(),
Region::default(),
)),
Some(unit.ident_pos(self.ctx).clone()),
unit.span(),
Some(self.source()),
Expand All @@ -355,6 +371,10 @@ impl<'a, 't> AnalyzeContext<'a, 't> {

self.analyze_declarative_part(&scope, body, &mut unit.decl, diagnostics)?;
scope.close(diagnostics);
let region = scope.into_region();
let visibility = root_scope.into_visibility();

unsafe { body.set_kind(AnyEntKind::Design(Design::PackageBody(visibility, region))) }
Ok(())
}

Expand Down Expand Up @@ -647,6 +667,11 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
"Use clause must be a selected name",
ErrorCode::MismatchedKinds,
);
// We still want to resolve the name,
// so that it is available for completion purposes.
// We ignore the errors here, since there is already a diagnostic at that position.
let mut empty_diag = Vec::new();
let _ = self.name_resolve(scope, name.span(), &mut name.item, &mut empty_diag);
continue;
}
}
Expand Down
2 changes: 1 addition & 1 deletion vhdl_lang/src/analysis/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ impl DesignRoot {
)
}
// Find all architectures which implement the entity
AnyEntKind::Design(Design::Architecture(ent_of_arch)) => {
AnyEntKind::Design(Design::Architecture(.., ent_of_arch)) => {
ent_of_arch.id == ent_id
}
_ => false,
Expand Down
5 changes: 4 additions & 1 deletion vhdl_lang/src/analysis/tests/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ end architecture;"

for (library_name, codes) in self.libraries.iter() {
for code in codes {
root.add_design_file(library_name.clone(), code.design_file());
root.add_design_file(
library_name.clone(),
code.design_file_diagnostics(&mut diagnostics),
);
}
}
root.analyze(&mut diagnostics);
Expand Down
Loading

0 comments on commit 16d9e5e

Please sign in to comment.