Skip to content

Commit

Permalink
[move-ide] Fixed auto-completion on the dot character
Browse files Browse the repository at this point in the history
  • Loading branch information
awelc committed Nov 5, 2024
1 parent 7523fe8 commit ed800be
Show file tree
Hide file tree
Showing 21 changed files with 318 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,8 @@ impl<'a> ParsingAnalysisContext<'a> {
self.exp_symbols(e2);
}
E::Borrow(_, e) => self.exp_symbols(e),
E::Dot(e, _) => self.exp_symbols(e),
E::DotCall(e, name, _, vo, v) => {
E::Dot(e, _, _) => self.exp_symbols(e),
E::DotCall(e, name, _, vo, v, _) => {
self.exp_symbols(e);
if let Some(v) = vo {
v.iter().for_each(|t| self.type_symbols(t));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ pub type LambdaLValues = Spanned<LambdaLValues_>;
#[allow(clippy::large_enum_variant)]
pub enum ExpDotted_ {
Exp(Box<Exp>),
Dot(Box<ExpDotted>, Name),
Dot(Box<ExpDotted>, Name, Loc),
Index(Box<ExpDotted>, Spanned<Vec<Exp>>),
DotUnresolved(Loc, Box<ExpDotted>), // dot where Name could not be parsed
}
Expand Down Expand Up @@ -393,6 +393,7 @@ pub enum Exp_ {
/* is_macro */ Option<Loc>,
Option<Vec<Type>>,
Spanned<Vec<Exp>>,
Loc, // location of the dot
),
Pack(ModuleAccess, Option<Vec<Type>>, Fields<Exp>),
Vector(Loc, Option<Vec<Type>>, Spanned<Vec<Exp>>),
Expand Down Expand Up @@ -1530,7 +1531,7 @@ impl AstDebug for Exp_ {
w.comma(rhs, |w, e| e.ast_debug(w));
w.write(")");
}
E::MethodCall(e, f, is_macro, tys_opt, sp!(_, rhs)) => {
E::MethodCall(e, f, is_macro, tys_opt, sp!(_, rhs), _) => {
e.ast_debug(w);
w.write(format!(".{}", f));
if is_macro.is_some() {
Expand Down Expand Up @@ -1730,7 +1731,7 @@ impl AstDebug for ExpDotted_ {
use ExpDotted_ as D;
match self {
D::Exp(e) => e.ast_debug(w),
D::Dot(e, n) => {
D::Dot(e, n, _) => {
e.ast_debug(w);
w.write(format!(".{}", n))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2684,7 +2684,7 @@ fn exp(context: &mut Context, pe: Box<P::Exp>) -> Box<E::Exp> {
EE::UnresolvedError
}
},
pdotted_ @ (PE::Dot(_, _) | PE::DotUnresolved(_, _)) => {
pdotted_ @ (PE::Dot(_, _, _) | PE::DotUnresolved(_, _)) => {
match exp_dotted(context, Box::new(sp(loc, pdotted_))) {
Some(edotted) => EE::ExpDotted(E::DottedUsage::Use, edotted),
None => {
Expand Down Expand Up @@ -2728,14 +2728,14 @@ fn exp(context: &mut Context, pe: Box<P::Exp>) -> Box<E::Exp> {
}
}

PE::DotCall(pdotted, n, is_macro, ptys_opt, sp!(rloc, prs)) => {
PE::DotCall(pdotted, n, is_macro, ptys_opt, sp!(rloc, prs), dot_loc) => {
match exp_dotted(context, pdotted) {
Some(edotted) => {
let pkg = context.current_package();
context.check_feature(pkg, FeatureGate::DotCall, loc);
let tys_opt = optional_types(context, ptys_opt);
let ers = sp(rloc, exps(context, prs));
EE::MethodCall(edotted, n, is_macro, tys_opt, ers)
EE::MethodCall(edotted, n, is_macro, tys_opt, ers, dot_loc)
}
None => {
assert!(context.env().has_errors());
Expand Down Expand Up @@ -2790,8 +2790,8 @@ fn exp_cast(context: &mut Context, in_parens: bool, plhs: Box<P::Exp>, pty: P::T
| PE::Match(_, _)
| PE::Spec(_) => true,

PE::DotCall(lhs, _, _, _, _)
| PE::Dot(lhs, _)
PE::DotCall(lhs, _, _, _, _, _)
| PE::Dot(lhs, _, _)
| PE::DotUnresolved(_, lhs)
| PE::Index(lhs, _)
| PE::Borrow(_, lhs)
Expand Down Expand Up @@ -2903,7 +2903,7 @@ fn move_or_copy_path_(context: &mut Context, case: PathCase, pe: Box<P::Exp>) ->
return None;
}
}
E::ExpDotted_::Dot(_, _)
E::ExpDotted_::Dot(_, _, _)
| E::ExpDotted_::DotUnresolved(_, _)
| E::ExpDotted_::Index(_, _) => {
let current_package = context.current_package();
Expand All @@ -2922,9 +2922,9 @@ fn exp_dotted(context: &mut Context, pdotted: Box<P::Exp>) -> Option<Box<E::ExpD
use P::Exp_ as PE;
let sp!(loc, pdotted_) = *pdotted;
let edotted_ = match pdotted_ {
PE::Dot(plhs, field) => {
PE::Dot(plhs, field, dot_loc) => {
let lhs = exp_dotted(context, plhs)?;
EE::Dot(lhs, field)
EE::Dot(lhs, field, dot_loc)
}
PE::Index(plhs, sp!(argloc, args)) => {
let cur_pkg = context.current_package();
Expand Down Expand Up @@ -3418,7 +3418,7 @@ fn lvalues(context: &mut Context, e: Box<P::Exp>) -> Option<LValue> {
let er = exp(context, pr);
L::Mutate(er)
}
pdotted_ @ PE::Dot(_, _) => {
pdotted_ @ PE::Dot(_, _, _) => {
let dotted = exp_dotted(context, Box::new(sp(loc, pdotted_)))?;
L::FieldMutate(dotted)
}
Expand Down
7 changes: 4 additions & 3 deletions external-crates/move/crates/move-compiler/src/naming/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ pub type LambdaLValues = Spanned<LambdaLValues_>;
#[derive(Debug, PartialEq, Clone)]
pub enum ExpDotted_ {
Exp(Box<Exp>),
Dot(Box<ExpDotted>, Field),
Dot(Box<ExpDotted>, Field, Loc),
Index(Box<ExpDotted>, Spanned<Vec<Exp>>),
DotAutocomplete(Loc, Box<ExpDotted>), // Dot (and its location) where Field could not be parsed
}
Expand Down Expand Up @@ -421,6 +421,7 @@ pub enum Exp_ {
/* is_macro */ Option<Loc>,
Option<Vec<Type>>,
Spanned<Vec<Exp>>,
Loc, // location of the dot
),
VarCall(Var, Spanned<Vec<Exp>>),
Builtin(BuiltinFunction, Spanned<Vec<Exp>>),
Expand Down Expand Up @@ -1636,7 +1637,7 @@ impl AstDebug for Exp_ {
w.comma(rhs, |w, e| e.ast_debug(w));
w.write(")");
}
E::MethodCall(e, f, is_macro, tys_opt, sp!(_, rhs)) => {
E::MethodCall(e, f, is_macro, tys_opt, sp!(_, rhs), _) => {
e.ast_debug(w);
w.write(format!(".{}", f));
if is_macro.is_some() {
Expand Down Expand Up @@ -1889,7 +1890,7 @@ impl AstDebug for ExpDotted_ {
use ExpDotted_ as D;
match self {
D::Exp(e) => e.ast_debug(w),
D::Dot(e, n) => {
D::Dot(e, n, _) => {
e.ast_debug(w);
w.write(format!(".{}", n))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ fn exp(context: &mut Context, sp!(_, e_): &mut N::Exp) {
exp(context, e)
}
}
N::Exp_::MethodCall(ed, _, _, _, sp!(_, es)) => {
N::Exp_::MethodCall(ed, _, _, _, sp!(_, es), _) => {
exp_dotted(context, ed);
for e in es {
exp(context, e)
Expand All @@ -416,7 +416,7 @@ fn exp(context: &mut Context, sp!(_, e_): &mut N::Exp) {
fn exp_dotted(context: &mut Context, sp!(_, ed_): &mut N::ExpDotted) {
match ed_ {
N::ExpDotted_::Exp(e) => exp(context, e),
N::ExpDotted_::Dot(ed, _) | N::ExpDotted_::DotAutocomplete(_, ed) => {
N::ExpDotted_::Dot(ed, _, _) | N::ExpDotted_::DotAutocomplete(_, ed) => {
exp_dotted(context, ed)
}
N::ExpDotted_::Index(ed, sp!(_, es)) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2901,7 +2901,7 @@ fn exp(context: &mut Context, e: Box<E::Exp>) -> Box<N::Exp> {
EE::Call(ma, is_macro, tys_opt, rhs) => {
resolve_call(context, eloc, ma, is_macro, tys_opt, rhs)
}
EE::MethodCall(edot, n, is_macro, tys_opt, rhs) => match dotted(context, *edot) {
EE::MethodCall(edot, n, is_macro, tys_opt, rhs, dot_loc) => match dotted(context, *edot) {
None => {
assert!(context.env.has_errors());
NE::UnresolvedError
Expand All @@ -2912,7 +2912,7 @@ fn exp(context: &mut Context, e: Box<E::Exp>) -> Box<N::Exp> {
if is_macro.is_some() {
context.check_feature(context.current_package, FeatureGate::MacroFuns, eloc);
}
NE::MethodCall(d, n, is_macro, ty_args, nes)
NE::MethodCall(d, n, is_macro, ty_args, nes, dot_loc)
}
},
EE::Vector(vec_loc, tys_opt, rhs) => {
Expand Down Expand Up @@ -2978,7 +2978,9 @@ fn dotted(context: &mut Context, edot: E::ExpDotted) -> Option<N::ExpDotted> {
_ => N::ExpDotted_::Exp(ne),
}
}
E::ExpDotted_::Dot(d, f) => N::ExpDotted_::Dot(Box::new(dotted(context, *d)?), Field(f)),
E::ExpDotted_::Dot(d, f, loc) => {
N::ExpDotted_::Dot(Box::new(dotted(context, *d)?), Field(f), loc)
}
E::ExpDotted_::DotUnresolved(loc, d) => {
N::ExpDotted_::DotAutocomplete(loc, Box::new(dotted(context, *d)?))
}
Expand Down Expand Up @@ -4328,7 +4330,7 @@ fn remove_unused_bindings_exp(
remove_unused_bindings_exp(context, used, e)
}
}
N::Exp_::MethodCall(ed, _, _, _, sp!(_, es)) => {
N::Exp_::MethodCall(ed, _, _, _, sp!(_, es), _) => {
remove_unused_bindings_exp_dotted(context, used, ed);
for e in es {
remove_unused_bindings_exp(context, used, e)
Expand All @@ -4346,7 +4348,7 @@ fn remove_unused_bindings_exp_dotted(
) {
match ed_ {
N::ExpDotted_::Exp(e) => remove_unused_bindings_exp(context, used, e),
N::ExpDotted_::Dot(ed, _) | N::ExpDotted_::DotAutocomplete(_, ed) => {
N::ExpDotted_::Dot(ed, _, _) | N::ExpDotted_::DotAutocomplete(_, ed) => {
remove_unused_bindings_exp_dotted(context, used, ed)
}
N::ExpDotted_::Index(ed, sp!(_, es)) => {
Expand Down
9 changes: 5 additions & 4 deletions external-crates/move/crates/move-compiler/src/parser/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,15 +628,16 @@ pub enum Exp_ {
// &mut e
Borrow(bool, Box<Exp>),

// e.f
Dot(Box<Exp>, Name),
// e.f (along with the location of the dot)
Dot(Box<Exp>, Name, Loc),
// e.f(earg,*)
DotCall(
Box<Exp>,
Name,
/* is_macro */ Option<Loc>,
Option<Vec<Type>>,
Spanned<Vec<Exp>>,
Loc, // location of the dot
),
// e[e']
Index(Box<Exp>, Spanned<Vec<Exp>>), // spec only
Expand Down Expand Up @@ -2128,11 +2129,11 @@ impl AstDebug for Exp_ {
}
e.ast_debug(w);
}
E::Dot(e, n) => {
E::Dot(e, n, _) => {
e.ast_debug(w);
w.write(format!(".{}", n));
}
E::DotCall(e, n, is_macro, tyargs, sp!(_, rhs)) => {
E::DotCall(e, n, is_macro, tyargs, sp!(_, rhs), _) => {
e.ast_debug(w);
w.write(format!(".{}", n));
if is_macro.is_some() {
Expand Down
17 changes: 12 additions & 5 deletions external-crates/move/crates/move-compiler/src/parser/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2618,7 +2618,7 @@ fn parse_dot_or_index_chain(context: &mut Context) -> Result<Exp, Box<Diagnostic
match parse_u8(contents) {
Ok((parsed, NumberFormat::Decimal)) => {
let field_access = Name::new(loc, format!("{parsed}").into());
Exp_::Dot(Box::new(lhs), field_access)
Exp_::Dot(Box::new(lhs), field_access, first_token_loc)
}
Ok((_, NumberFormat::Hex)) => {
let msg = "Invalid field access. Expected a decimal number but was given a hexadecimal";
Expand All @@ -2627,7 +2627,7 @@ fn parse_dot_or_index_chain(context: &mut Context) -> Result<Exp, Box<Diagnostic
context.add_diag(diag);
// Continue on with the parsing
let field_access = Name::new(loc, contents.into());
Exp_::Dot(Box::new(lhs), field_access)
Exp_::Dot(Box::new(lhs), field_access, first_token_loc)
}
Err(_) => {
let msg = format!(
Expand All @@ -2639,7 +2639,7 @@ fn parse_dot_or_index_chain(context: &mut Context) -> Result<Exp, Box<Diagnostic
context.add_diag(diag);
// Continue on with the parsing
let field_access = Name::new(loc, contents.into());
Exp_::Dot(Box::new(lhs), field_access)
Exp_::Dot(Box::new(lhs), field_access, first_token_loc)
}
}
}
Expand All @@ -2665,9 +2665,16 @@ fn parse_dot_or_index_chain(context: &mut Context) -> Result<Exp, Box<Diagnostic
parse_macro_opt_and_tyargs_opt(context, false, n.loc);
let tys = tys.map(|t| t.value);
let args = parse_call_args(context);
Exp_::DotCall(Box::new(lhs), n, is_macro, tys, args)
Exp_::DotCall(
Box::new(lhs),
n,
is_macro,
tys,
args,
first_token_loc,
)
} else {
Exp_::Dot(Box::new(lhs), n)
Exp_::Dot(Box::new(lhs), n, first_token_loc)
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ fn recolor_exp(ctx: &mut Recolor, sp!(_, e_): &mut N::Exp) {
recolor_exp(ctx, e)
}
}
N::Exp_::MethodCall(ed, _, _, _, sp!(_, es)) => {
N::Exp_::MethodCall(ed, _, _, _, sp!(_, es), _) => {
recolor_exp_dotted(ctx, ed);
for e in es {
recolor_exp(ctx, e)
Expand Down Expand Up @@ -680,7 +680,7 @@ fn recolor_exp(ctx: &mut Recolor, sp!(_, e_): &mut N::Exp) {
fn recolor_exp_dotted(ctx: &mut Recolor, sp!(_, ed_): &mut N::ExpDotted) {
match ed_ {
N::ExpDotted_::Exp(e) => recolor_exp(ctx, e),
N::ExpDotted_::Dot(ed, _) | N::ExpDotted_::DotAutocomplete(_, ed) => {
N::ExpDotted_::Dot(ed, _, _) | N::ExpDotted_::DotAutocomplete(_, ed) => {
recolor_exp_dotted(ctx, ed)
}
N::ExpDotted_::Index(ed, sp!(_, es)) => {
Expand Down Expand Up @@ -941,7 +941,7 @@ fn exp(context: &mut Context, sp!(eloc, e_): &mut N::Exp) {
}
exps(context, es)
}
N::Exp_::MethodCall(ed, _, _, tys_opt, sp!(_, es)) => {
N::Exp_::MethodCall(ed, _, _, tys_opt, sp!(_, es), _) => {
if let Some(tys) = tys_opt {
types(context, tys)
}
Expand Down Expand Up @@ -1158,7 +1158,7 @@ fn builtin_function(context: &mut Context, sp!(_, bf_): &mut N::BuiltinFunction)
fn exp_dotted(context: &mut Context, sp!(_, ed_): &mut N::ExpDotted) {
match ed_ {
N::ExpDotted_::Exp(e) => exp(context, e),
N::ExpDotted_::Dot(ed, _) | N::ExpDotted_::DotAutocomplete(_, ed) => {
N::ExpDotted_::Dot(ed, _, _) | N::ExpDotted_::DotAutocomplete(_, ed) => {
exp_dotted(context, ed)
}
N::ExpDotted_::Index(ed, sp!(_, es)) => {
Expand Down
Loading

0 comments on commit ed800be

Please sign in to comment.