Skip to content

Commit

Permalink
Update rustc-ap-syntax to 100.0
Browse files Browse the repository at this point in the history
This update includes removal of
ExprKind::TupField(rust-lang/rust#49718).
With this change, I changed the logic of method completion for tuple
struct and added a related test.
  • Loading branch information
kngwyu committed Apr 15, 2018
1 parent 7868111 commit 40466f6
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 59 deletions.
52 changes: 26 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ env_logger = "0.5"
cargo = "0.26"
clap = "2.31"
lazy_static = "1.0"
rustc-ap-rustc_errors = "89.0.0"
rustc-ap-syntax = "89.0.0"
rustc-ap-syntax_pos = "89.0.0"
rustc-ap-rustc_errors = "100.0.0"
rustc-ap-syntax = "100.0.0"
rustc-ap-syntax_pos = "100.0.0"

[dependencies.clippy]
version = "0.0.192"
Expand Down
35 changes: 7 additions & 28 deletions src/racer/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ fn to_racer_path(path: &ast::Path) -> core::Path {
let mut v = Vec::new();
let mut global = false;
for seg in &path.segments {
let name = seg.identifier.name.to_string();
let name = seg.ident.name.to_string();
let mut types = Vec::new();
// TODO: this is for backword compatibility & maybe we have to rewrite core::Path
if name == "{{root}}" {
Expand Down Expand Up @@ -664,7 +664,7 @@ impl<'c, 's, 'ast> visit::Visitor<'ast> for ExprTypeVisitor<'c, 's> {

ExprKind::MethodCall(ref method_def, ref arguments) => {
// spannedident.node is an ident I think
let methodname = method_def.identifier.name.as_str();
let methodname = method_def.ident.name.as_str();
debug!("[method call] name: {}", methodname);

// arguments[0] is receiver(e.g. self)
Expand Down Expand Up @@ -702,11 +702,11 @@ impl<'c, 's, 'ast> visit::Visitor<'ast> for ExprTypeVisitor<'c, 's> {
}

ExprKind::Field(ref subexpression, spannedident) => {
let fieldname = spannedident.node.name.to_string();
let fieldname = spannedident.name.to_string();
debug!("exprfield {}", fieldname);
self.visit_expr(subexpression);
self.result = self.result.as_ref().and_then(|structm| match *structm {
Ty::Match(ref structm) => {
self.result = self.result.as_ref().and_then(|structm| match structm {
Ty::Match(structm) => {
typeinf::get_struct_field_type(&fieldname, structm, self.session).and_then(
|fieldtypepath| {
find_type_match_including_generics(
Expand Down Expand Up @@ -758,27 +758,6 @@ impl<'c, 's, 'ast> visit::Visitor<'ast> for ExprTypeVisitor<'c, 's> {
};
}

ExprKind::TupField(ref subexpression, ref spanned_index) => {
let fieldnum = spanned_index.node;
debug!("tupfield {:?}", fieldnum);
self.visit_expr(subexpression);
self.result = self.result.as_ref().and_then(|ty| match *ty {
Ty::Match(ref structm) => {
typeinf::get_tuplestruct_field_type(fieldnum, structm, &self.session)
.and_then(|fieldtypepath| {
find_type_match_including_generics(
&fieldtypepath,
&structm.filepath,
structm.point,
structm,
self.session,
)
})
}
_ => None,
});
}

ExprKind::Try(ref expr) => {
debug!("try expr");
self.visit_expr(&expr);
Expand Down Expand Up @@ -1212,7 +1191,7 @@ impl GenericsList {
GenericParam::Lifetime(_) => None,
GenericParam::Type(ty_param) => {
let param_name = ty_param.ident.name.as_str().to_string();
let codemap::BytePos(point) = ty_param.span.lo();
let codemap::BytePos(point) = ty_param.ident.span.lo();
let bounds =
TraitBounds::from_ty_param_bounds(&ty_param.bounds, &file_path, offset);
Some(GenericsArg {
Expand Down Expand Up @@ -1265,7 +1244,7 @@ impl<'ast> visit::Visitor<'ast> for EnumVisitor {
for variant in &enum_definition.variants {
let codemap::BytePos(point) = variant.span.lo();
self.values
.push((variant.node.name.to_string(), point as usize));
.push((variant.node.ident.name.to_string(), point as usize));
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/racer/typeinf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,16 @@ pub fn get_struct_field_type(
session: &Session,
) -> Option<core::Ty> {
assert!(structmatch.mtype == core::MatchType::Struct);

debug!("[get_struct_filed_type]{}, {:?}", fieldname, structmatch);
let src = session.load_file(&structmatch.filepath);

let opoint = scopes::expect_stmt_start(src.as_src(), structmatch.point);
let structsrc = scopes::end_of_next_scope(&src[opoint..]);

let structsrc = if structsrc == "" {
(*get_first_stmt(src.as_src().from(opoint))).to_owned()
} else {
structsrc.to_owned()
};
let fields = ast::parse_struct_fields(structsrc.to_owned(), Scope::from_match(structmatch));
for (field, _, ty) in fields.into_iter() {
if fieldname == field {
Expand Down
16 changes: 16 additions & 0 deletions tests/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4057,6 +4057,22 @@ fn completes_methods_for_closure_arg() {
);
}

#[test]
fn completes_methods_for_tuple_struct() {
let src = r"
fn main() {
struct A(i32, Vec<i32>);
let mut a = A(0, vec![3, 4]);
a.1.appen~
}
";
assert!(
get_all_completions(src, None)
.into_iter()
.any(|ma| ma.matchstr == "append")
);
}

// issue 706
mod trait_bounds {
use super::*;
Expand Down

0 comments on commit 40466f6

Please sign in to comment.