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

Handle visibility (privacy) in field/method completion #824

Closed
flodiebold opened this issue Feb 13, 2019 · 8 comments · Fixed by #9685
Closed

Handle visibility (privacy) in field/method completion #824

flodiebold opened this issue Feb 13, 2019 · 8 comments · Fixed by #9685
Labels
A-completion autocompletion S-actionable Someone could pick this issue up and work on it right now

Comments

@flodiebold
Copy link
Member

We currently don't handle visibility at all. This means that we provide lots of private fields and methods for completions outside of modules where you can actually access them. We should fix this. I think the basic steps for this will be:

  • add visibility to the HIR for StructField and Function (probably also Const, Type etc.)
  • implement the code to check whether a field/method is visible from a certain module (basically, if the item is private, are we in the module where it's defined or a submodule? notably, for impl items, the privacy is determined by the module containing the impl, not the one containing the type, I think)
  • filter out completions that are not visible in complete_dot.rs

A different, but related issue is handling visibility of items, for example when doing glob imports.

@sirgl
Copy link

sirgl commented Feb 14, 2019

I think, that it would be better not to filter out items, but make it less relevant and sort completion results by relevancy. Very often I forget to add pub and try to complete it somewhere else, so it is not very convenient to go there and add visibility manually. I think, that assist to add pub for not visible entry should be created. It would be much better user experience

@DJMcNab
Copy link
Contributor

DJMcNab commented Feb 14, 2019

But do filter it out for external crates?

@flodiebold
Copy link
Member Author

It probably makes sense to treat the local source roots differently than the other ones (i.e. provide private items only from crates you can edit).

@sanbox-irl
Copy link

Hiya -- i'd like to see this added. I think the optimal configuration is:

  1. By default, we only show publicly accessible things in the current scope
  2. we provide a setting to turn this off (perhaps even allowing us to sort, though I think that's a bit silly personally)

The reason for this is a few -- first, I like the Rust analyzer being able to tell me at a glance what's in scope and not in scope. Secondly, I really dislike the idea of the Rust Analyzer being willing to autocomplete something which will not compile. As a given rule, I think the Rust analyzer shouldn't suggest things which are wrong. Scope errors are one of those things. Finally, I think this could be rolled into a larger process of having the Rust Analyzer handle scope for the user much more effectively (think a help action to automatically add a using directive, like Omnisharp has for C#).

Thank you!

@lnicola
Copy link
Member

lnicola commented Sep 12, 2019

I think VS puts public items in front and private ones at the end, which doesn't sound so bad if you have a way to distinguish them.

@flodiebold flodiebold changed the title Handle visibility in field/method completion Handle visibility (privacy) in field/method completion Dec 23, 2019
@flodiebold flodiebold added the A-completion autocompletion label Dec 26, 2019
@pksunkara
Copy link
Contributor

#2830 seems a duplicate of this.

@jonas-schievink
Copy link
Contributor

Hmm, this seems to be mostly implemented now. Is anything missing here?

@Veykril
Copy link
Member

Veykril commented Jul 22, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-completion autocompletion S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants