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

Completion check_stability doesn't look at the attributes on the parent modules #15802

Open
Kivooeo opened this issue Oct 25, 2023 · 7 comments
Labels
A-completion autocompletion C-bug Category: bug

Comments

@Kivooeo
Copy link

Kivooeo commented Oct 25, 2023

Why this suggest me nightly(?) feature on a stable version
image

It should suggest me println! not a place!

rust-analyzer --verstion output

rust-analyzer --version
rust-analyzer 1.73.0 (cc66ad46 2023-10-03)

Previously, about two weeks ago, it suggests a println! on first place, i dont think this is correct work.

@Kivooeo Kivooeo added the C-support Category: support questions label Oct 25, 2023
@lnicola
Copy link
Member

lnicola commented Oct 25, 2023

Until two weeks ago we didn't suggest place! at all. But I agree, it shouldn't be the first suggestion.

@lnicola lnicola added A-completion autocompletion C-bug Category: bug and removed C-support Category: support questions labels Oct 25, 2023
@Kivooeo

This comment was marked as spam.

@lnicola lnicola changed the title pl autocompletition on stable? Completion check_stability doesn't look at the attributes on the parent modules Nov 11, 2023
@Veykril
Copy link
Member

Veykril commented Nov 11, 2023

&& ctx.check_stability(original_item.attrs(ctx.db).as_deref())
and
&& ctx.check_stability(original_item.attrs(ctx.db).as_deref())

are the two places where we need to look at the stability of all segments of the import.import_path.

@lnicola
Copy link
Member

lnicola commented Nov 11, 2023

Tentative, non-working patch at lnicola@873d34b.

@Veykril
Copy link
Member

Veykril commented Nov 11, 2023

Actually, after having worked on #15871 just now, I think we can forego looking at the attributes entirely for this in completions again (the linked PRs changes unrelated to the idea). We know the stability of an import path when calculating it in find_path

) -> Option<(ModPath, Stability)> {
, we just aren't exposing that from find_path_inner where we map the stability away. LocatedImport's import paths being looked for here
if let Some(prefix_kind) = prefixed {
module_with_candidate.find_use_path_prefixed(
db,
item_to_search,
prefix_kind,
prefer_no_std,
prefer_prelude,
)
} else {
module_with_candidate.find_use_path(db, item_to_search, prefer_no_std, prefer_prelude)
}

@lnicola
Copy link
Member

lnicola commented Nov 11, 2023

But my proposed change (which doesn't actually work for place! for some reason) also applies outside of flyimport. For example (this won't compile, of course):

struct S;

mod m {
    #![unstable]

    impl super::S {
        pub fn foo(&self) {}
    }
}
fn main() {
    S.<|>;

We currently suggest foo here, but not under lnicola@873d34b.

@Veykril
Copy link
Member

Veykril commented Nov 11, 2023

Right, my idea won't cover method calls. Aside from that I don't think there really is a point in checking the parent module of anything though, since any other completion would require the thing in question to already be in scope, and hence the user should have the feature enabled anyways?

Walking up the ancestors also has the problem of re-exports through unstable modules not being recognized as unstable actually. (I think rustc itself currently fails this as well, or used to iirc)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-completion autocompletion C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

3 participants