Skip to content

Commit

Permalink
LSP: Collect type_ascription from TyConstantDeclaration (FuelLabs#3748
Browse files Browse the repository at this point in the history
)

Pretty simple fix, just need to pass through the type_ascription from
the `parsed::ConstantDeclaration` to the `ty::TyConstantDeclaration`.

closes FuelLabs#3615
  • Loading branch information
JoshuaBatty authored Jan 11, 2023
1 parent f14d6ef commit 5b04a8d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions sway-core/src/language/ty/declaration/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct TyConstantDeclaration {
pub visibility: Visibility,
pub return_type: TypeId,
pub attributes: transform::AttributesMap,
pub type_ascription_span: Option<Span>,
pub span: Span,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ impl ty::TyDeclaration {
parsed::Declaration::ConstantDeclaration(parsed::ConstantDeclaration {
name,
type_ascription,
type_ascription_span,
value,
visibility,
attributes,
span,
..
}) => {
let type_ascription = check!(
ctx.resolve_type_with_self(
Expand Down Expand Up @@ -132,6 +132,7 @@ impl ty::TyDeclaration {
visibility,
return_type,
attributes,
type_ascription_span,
span,
};
let typed_const_decl = ty::TyDeclaration::ConstantDeclaration(
Expand Down
12 changes: 12 additions & 0 deletions sway-lsp/src/traverse/typed_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ impl<'a> TypedTree<'a> {
token.typed = Some(TypedAstToken::TypedDeclaration(declaration.clone()));
token.type_def = Some(TypeDefinition::Ident(const_decl.name.clone()));
}

if let Some(type_ascription_span) = &const_decl.type_ascription_span {
if let Some(mut token) = self
.tokens
.try_get_mut(&to_ident_key(&Ident::new(type_ascription_span.clone())))
.try_unwrap()
{
token.typed =
Some(TypedAstToken::TypedDeclaration(declaration.clone()));
token.type_def = Some(TypeDefinition::TypeId(const_decl.return_type));
}
};
self.handle_expression(&const_decl.value);
}
}
Expand Down

0 comments on commit 5b04a8d

Please sign in to comment.