Skip to content

Commit

Permalink
Return the local struct Span as a new field on `TypedExpressionVarian…
Browse files Browse the repository at this point in the history
…t::StructExpression` (#2380)

This PR uses the local span of the call_path_binding to create a Span for the TypedExpressionVariant::StructExpression. Previously it was only passing along the Ident of the declaration which would prohibit the token from being collected in the language server.
  • Loading branch information
JoshuaBatty committed Jul 26, 2022
1 parent 7aa44cd commit 1f48797
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions sway-core/src/control_flow_analysis/dead_code_analysis.rs
Expand Up @@ -821,6 +821,7 @@ fn connect_expression(
StructExpression {
struct_name,
fields,
..
} => {
let decl = match graph.namespace.find_struct_decl(struct_name.as_str()) {
Some(ix) => *ix,
Expand Down
Expand Up @@ -1021,6 +1021,7 @@ impl TypedExpression {
expression: TypedExpressionVariant::StructExpression {
struct_name: struct_name.clone(),
fields: typed_fields_buf,
span: call_path_binding.inner.suffix.1.clone(),
},
return_type: type_id,
is_constant: IsConstant::No,
Expand Down
Expand Up @@ -49,6 +49,7 @@ pub enum TypedExpressionVariant {
StructExpression {
struct_name: Ident,
fields: Vec<TypedStructExpressionField>,
span: Span,
},
CodeBlock(TypedCodeBlock),
// a flag that this value will later be provided as a parameter, but is currently unknown
Expand Down Expand Up @@ -177,12 +178,18 @@ impl PartialEq for TypedExpressionVariant {
Self::StructExpression {
struct_name: l_struct_name,
fields: l_fields,
span: l_span,
},
Self::StructExpression {
struct_name: r_struct_name,
fields: r_fields,
span: r_span,
},
) => l_struct_name == r_struct_name && l_fields.clone() == r_fields.clone(),
) => {
l_struct_name == r_struct_name
&& l_fields.clone() == r_fields.clone()
&& l_span == r_span
}
(Self::CodeBlock(l0), Self::CodeBlock(r0)) => l0 == r0,
(
Self::IfExp {
Expand Down
7 changes: 2 additions & 5 deletions sway-lsp/src/core/traverse_typed_tree.rs
Expand Up @@ -230,11 +230,8 @@ fn handle_expression(expression: &TypedExpression, tokens: &TokenMap) {
handle_expression(prefix, tokens);
handle_expression(index, tokens);
}
TypedExpressionVariant::StructExpression {
ref struct_name,
ref fields,
} => {
if let Some(mut token) = tokens.get_mut(&to_ident_key(struct_name)) {
TypedExpressionVariant::StructExpression { fields, span, .. } => {
if let Some(mut token) = tokens.get_mut(&to_ident_key(&Ident::new(span.clone()))) {
token.typed = Some(TypedAstToken::TypedExpression(expression.clone()));
}

Expand Down

0 comments on commit 1f48797

Please sign in to comment.