Skip to content

Commit

Permalink
Adds handling of StorageEntry to the LSP.
Browse files Browse the repository at this point in the history
  • Loading branch information
esdrubal committed Jun 6, 2024
1 parent 12965a5 commit a449e6e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 10 deletions.
5 changes: 3 additions & 2 deletions sway-lsp/src/core/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use sway_core::{
AbiCastExpression, AmbiguousPathExpression, Declaration, DelineatedPathExpression,
EnumVariant, Expression, FunctionApplicationExpression, FunctionParameter,
IncludeStatement, MethodApplicationExpression, Scrutinee, StorageField,
StructExpression, StructExpressionField, StructField, StructScrutineeField, Supertrait,
TraitFn, UseStatement,
StorageNamespace, StructExpression, StructExpressionField, StructField,
StructScrutineeField, Supertrait, TraitFn, UseStatement,
},
ty,
},
Expand Down Expand Up @@ -44,6 +44,7 @@ pub enum AstToken {
MethodApplicationExpression(MethodApplicationExpression),
Scrutinee(Scrutinee),
StorageField(StorageField),
StorageNamespace(StorageNamespace),
StructExpression(StructExpression),
StructExpressionField(StructExpressionField),
StructField(StructField),
Expand Down
22 changes: 19 additions & 3 deletions sway-lsp/src/traverse/lexed_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use sway_ast::{
ExprTupleDescriptor, FnArg, FnArgs, FnSignature, IfCondition, IfExpr, ItemAbi,
ItemConfigurable, ItemConst, ItemEnum, ItemFn, ItemImpl, ItemImplItem, ItemKind, ItemStorage,
ItemStruct, ItemTrait, ItemTypeAlias, ItemUse, MatchBranchKind, ModuleKind, Pattern,
PatternStructField, Statement, StatementLet, StorageField, TraitType, Ty, TypeField, UseTree,
PatternStructField, Statement, StatementLet, StorageEntry, StorageField, TraitType, Ty,
TypeField, UseTree,
};
use sway_core::language::{lexed::LexedProgram, HasSubmodules};
use sway_types::{Ident, Span, Spanned};
Expand Down Expand Up @@ -404,11 +405,26 @@ impl Parse for ItemStorage {
fn parse(&self, ctx: &ParseContext) {
insert_keyword(ctx, self.storage_token.span());

self.fields
self.entries
.get()
.into_iter()
.par_bridge()
.for_each(|field| field.value.parse(ctx));
.for_each(|entry| entry.value.parse(ctx));
}
}

impl Parse for StorageEntry {
fn parse(&self, ctx: &ParseContext) {
if let Some(namespace) = &self.namespace {
namespace
.clone()
.into_inner()
.into_iter()
.par_bridge()
.for_each(|entry| entry.value.parse(ctx));
} else if let Some(field) = &self.field {
field.parse(ctx);
}
}
}

Expand Down
39 changes: 34 additions & 5 deletions sway-lsp/src/traverse/parsed_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ use sway_core::{
IncludeStatement, IntrinsicFunctionExpression, LazyOperatorExpression, MatchExpression,
MethodApplicationExpression, MethodName, ParseModule, ParseProgram, ParseSubmodule,
QualifiedPathType, ReassignmentExpression, ReassignmentTarget, RefExpression,
Scrutinee, StorageAccessExpression, StorageDeclaration, StorageField,
StructDeclaration, StructExpression, StructExpressionField, StructField,
StructScrutineeField, SubfieldExpression, Supertrait, TraitDeclaration, TraitFn,
TraitItem, TraitTypeDeclaration, TupleIndexExpression, TypeAliasDeclaration,
Scrutinee, StorageAccessExpression, StorageDeclaration, StorageEntry, StorageField,
StorageNamespace, StructDeclaration, StructExpression, StructExpressionField,
StructField, StructScrutineeField, SubfieldExpression, Supertrait, TraitDeclaration,
TraitFn, TraitItem, TraitTypeDeclaration, TupleIndexExpression, TypeAliasDeclaration,
UseStatement, VariableDeclaration, WhileLoopExpression,
},
CallPathTree, HasSubmodules, Literal,
Expand Down Expand Up @@ -312,13 +312,23 @@ impl Parse for Expression {
}
ExpressionKind::StorageAccess(StorageAccessExpression {
field_names,
namespace_names,
storage_keyword_span,
}) => {
let storage_ident = Ident::new(storage_keyword_span.clone());
ctx.tokens.insert(
ctx.ident(&storage_ident),
Token::from_parsed(AstToken::Ident(storage_ident), SymbolKind::Unknown),
);
adaptive_iter(namespace_names, |namespace_name| {
ctx.tokens.insert(
ctx.ident(namespace_name),
Token::from_parsed(
AstToken::Ident(namespace_name.clone()),
SymbolKind::Field,
),
);
});
adaptive_iter(field_names, |field_name| {
ctx.tokens.insert(
ctx.ident(field_name),
Expand Down Expand Up @@ -885,11 +895,30 @@ impl Parse for ParsedDeclId<TraitTypeDeclaration> {
impl Parse for ParsedDeclId<StorageDeclaration> {
fn parse(&self, ctx: &ParseContext) {
let storage_decl = ctx.engines.pe().get_storage(self);
adaptive_iter(&storage_decl.fields, |field| field.parse(ctx));
adaptive_iter(&storage_decl.entries, |entry| entry.parse(ctx));
storage_decl.attributes.parse(ctx);
}
}

impl Parse for StorageEntry {
fn parse(&self, ctx: &ParseContext) {
match self {
StorageEntry::Namespace(namespace) => namespace.parse(ctx),
StorageEntry::Field(field) => field.parse(ctx),
}
}
}

impl Parse for StorageNamespace {
fn parse(&self, ctx: &ParseContext) {
ctx.tokens.insert(
ctx.ident(&self.name),
Token::from_parsed(AstToken::StorageNamespace(self.clone()), SymbolKind::Field),
);
self.entries.iter().for_each(|entry| entry.parse(ctx));
}
}

impl Parse for StorageField {
fn parse(&self, ctx: &ParseContext) {
ctx.tokens.insert(
Expand Down

0 comments on commit a449e6e

Please sign in to comment.