Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[move-ide] Fixed auto-completion on the dot character #20175

Merged
merged 6 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>, /* dot location */ Loc, Name),
Index(Box<ExpDotted>, Spanned<Vec<Exp>>),
DotUnresolved(Loc, Box<ExpDotted>), // dot where Name could not be parsed
}
Expand Down Expand Up @@ -389,6 +389,7 @@ pub enum Exp_ {
),
MethodCall(
Box<ExpDotted>,
Loc, // location of the dot
Name,
/* is_macro */ Option<Loc>,
Option<Vec<Type>>,
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, dot_loc, n, is_macro, ptys_opt, sp!(rloc, prs)) => {
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, dot_loc, n, is_macro, tys_opt, ers)
}
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, dot_loc, field) => {
let lhs = exp_dotted(context, plhs)?;
EE::Dot(lhs, field)
EE::Dot(lhs, dot_loc, field)
}
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),
cgswords marked this conversation as resolved.
Show resolved Hide resolved
Dot(Box<ExpDotted>, /* dot loation */ Loc, Field),
Index(Box<ExpDotted>, Spanned<Vec<Exp>>),
DotAutocomplete(Loc, Box<ExpDotted>), // Dot (and its location) where Field could not be parsed
}
Expand Down Expand Up @@ -417,6 +417,7 @@ pub enum Exp_ {
),
MethodCall(
ExpDotted,
Loc, // location of the dot
Name,
/* is_macro */ Option<Loc>,
Option<Vec<Type>>,
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, dot_loc, n, is_macro, tys_opt, rhs) => 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, dot_loc, n, is_macro, ty_args, nes)
}
},
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, loc, f) => {
N::ExpDotted_::Dot(Box::new(dotted(context, *d)?), loc, Field(f))
}
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,11 +628,12 @@ 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>, /* dot location */ Loc, Name),
// e.f(earg,*)
DotCall(
Box<Exp>,
Loc, // location of the dot
Name,
/* is_macro */ Option<Loc>,
Option<Vec<Type>>,
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), first_token_loc, field_access)
}
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), first_token_loc, field_access)
}
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), first_token_loc, field_access)
}
}
}
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),
first_token_loc,
n,
is_macro,
tys,
args,
)
} else {
Exp_::Dot(Box::new(lhs), n)
Exp_::Dot(Box::new(lhs), first_token_loc, n)
}
}
},
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
Loading