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

Provide completions for associated types #784

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

TedDriggs
Copy link
Contributor

Fixes #775. This fix is very similar to the one for trait functions:

  1. Look to see if cursor is after a declaration keyword
  2. If so, try to find the enclosing trait
  3. If trait found, look for trait items of the right type

This fix is very similar to the one for trait functions:

1. Look to see if cursor is after a declaration keyword
2. If so, try to find the enclosing trait
3. If trait found, look for trait items of the right type
Copy link
Contributor

@bkchr bkchr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Maybe adding another test like the following:

trait TestTrait {
  type ErrorOne;
  type ErrorTwo;
}

struct Test;
impl Trait for Test {
  type Error~
}

And then use get_all_completions to check that both are returned?

Copy link
Collaborator

@jwilm jwilm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to the two tests you have here, should there be a test which checks autocomplete works in incomplete code snippets? For instance,

impl IntoIterator for Foo {
    type I~
}

Would provide two completions Item and IntoIter.

if txt_matches(search_type, &format!("type {}", searchstr), signature) {
debug!("found associated type starting |{}| |{}|", searchstr, blob);
// TODO: parse this properly
let start = blob.find(&format!("type {}", searchstr)).unwrap() + 5;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since format! allocates, is kind of expensive, and this same string is generated in two places, it should probably be made a variable binding above.

@kngwyu kngwyu mentioned this pull request Oct 23, 2018
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide completions for associated types in trait impls
3 participants