Skip to content

Commit

Permalink
Enable completion for indexed value of array
Browse files Browse the repository at this point in the history
  • Loading branch information
kngwyu committed Nov 27, 2018
1 parent 22018f7 commit 4c2d363
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/racer/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@ fn complete_from_file_(filepath: &path::Path, cursor: Location, session: &Sessio
}
CompletionType::Field => {
let context = ast::get_type_of(contextstr.to_owned(), filepath, pos, session);
debug!("complete_from_file context is {:?}", context);
println!("complete_from_file context is {:?}", context);

This comment has been minimized.

Copy link
@bluss

bluss Dec 8, 2018

Contributor

unintentional addition @kngwyu ?

This comment has been minimized.

Copy link
@kngwyu

kngwyu Dec 8, 2018

Author Collaborator

Hoops, thanks for reporting!
I yanked this version 😓

This comment has been minimized.

Copy link
@bluss

bluss Dec 8, 2018

Contributor

No sweat. Thanks for working on racer! 💟

if let Some(ty) = context {
out.extend(nameres::get_field_matches_from_ty(
ty,
Expand Down
2 changes: 1 addition & 1 deletion src/racer/typeinf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,12 +549,12 @@ pub fn get_return_type_of_function(
}

pub(crate) fn get_type_of_indexed_value(body: Ty, session: &Session) -> Option<Ty> {
// TODO(kngwyu): slice support
match body.dereference() {
Ty::Match(m) => nameres::get_index_output(&m, session),
Ty::PathSearch(p) => p
.resolve_as_match(session)
.and_then(|m| nameres::get_index_output(&m, session)),
Ty::Array(ty, _) | Ty::Slice(ty) => Some(*ty),
_ => None,
}
}
Expand Down
11 changes: 11 additions & 0 deletions tests/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ fn completes_methods_for_consts() {
assert_eq!(get_only_completion(src, None).matchstr, "chars");
}

#[test]
fn completes_methods_for_const_array() {
let src = r#"
const VECTOR: [f64; 2] = [0.0, 0.0];
fn main() {
VECTOR[0].atan2~
}
"#;
assert_eq!(get_only_completion(src, None).matchstr, "atan2");
}

#[test]
fn completes_methods_for_static() {
let src = r#"
Expand Down

0 comments on commit 4c2d363

Please sign in to comment.