Skip to content

Commit

Permalink
Moved get_impl_spans_for_decl into TraitMap.
Browse files Browse the repository at this point in the history
  • Loading branch information
esdrubal committed Jan 9, 2025
1 parent e598c1c commit 4db723d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
10 changes: 1 addition & 9 deletions sway-core/src/semantic_analysis/namespace/module.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
engine_threading::Engines,
language::{
ty::{self, TyDecl},
ty::{self},
Visibility,
},
Ident, TypeId,
Expand Down Expand Up @@ -416,14 +416,6 @@ impl Module {
})
.collect::<Vec<_>>()
}

pub fn get_impl_spans_for_decl(&self, engines: &Engines, ty_decl: &TyDecl) -> Vec<Span> {
let handler = Handler::default();
ty_decl
.return_type(&handler, engines)
.map(|type_id| TraitMap::get_impl_spans_for_type(self, engines, &type_id))
.unwrap_or_default()
}
}

impl From<Root> for Module {
Expand Down
15 changes: 14 additions & 1 deletion sway-core/src/semantic_analysis/namespace/trait_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
engine_threading::*,
language::{
parsed::{EnumDeclaration, ImplItem, StructDeclaration},
ty::{self, TyImplItem, TyTraitItem},
ty::{self, TyDecl, TyImplItem, TyTraitItem},
CallPath,
},
type_system::{SubstTypes, TypeId},
Expand Down Expand Up @@ -1113,6 +1113,19 @@ impl TraitMap {
spans
}

/// Find the spans of all impls for the given decl.
pub fn get_impl_spans_for_decl(
module: &Module,
engines: &Engines,
ty_decl: &TyDecl,
) -> Vec<Span> {
let handler = Handler::default();
ty_decl
.return_type(&handler, engines)
.map(|type_id| TraitMap::get_impl_spans_for_type(module, engines, &type_id))
.unwrap_or_default()
}

/// Find the entries in `self` with trait name `trait_name` and return the
/// spans of the impls.
pub fn get_impl_spans_for_trait_name(module: &Module, trait_name: &CallPath) -> Vec<Span> {
Expand Down
8 changes: 5 additions & 3 deletions sway-lsp/src/capabilities/hover/hover_link_contents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,11 @@ impl<'a> HoverLinkContents<'a> {
/// Adds implementations of the given type to the list of implementations using the [`TyDecl`].
pub fn add_implementations_for_decl(&mut self, ty_decl: &TyDecl) {
if let Some(namespace) = self.session.namespace() {
let impl_spans = namespace
.module(self.engines)
.get_impl_spans_for_decl(self.engines, ty_decl);
let impl_spans = TraitMap::get_impl_spans_for_decl(
namespace.module(self.engines),
self.engines,
ty_decl,
);
self.add_implementations(&ty_decl.span(self.engines), impl_spans);
}
}
Expand Down

0 comments on commit 4db723d

Please sign in to comment.