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

Quick fix "Import" does not work for modifier private with access qualifier #6732

Closed
tgodzik opened this issue Aug 28, 2024 Discussed in #6730 · 5 comments · Fixed by #6765
Closed

Quick fix "Import" does not work for modifier private with access qualifier #6732

tgodzik opened this issue Aug 28, 2024 Discussed in #6730 · 5 comments · Fixed by #6765
Labels
bug Something that is making a piece of functionality unusable Scala 2
Milestone

Comments

@tgodzik
Copy link
Contributor

tgodzik commented Aug 28, 2024

Discussed in #6730

Originally posted by LeUser111 August 28, 2024
Hi there,

I'm making massive use of access modifiers in combination with access qualifiers (see Scala 2 language specification) throughout my code bases.

Unfortunately, metals does not suggest imports for members with modifier private and matching qualifier.

A simple example would be:

package com.airhack.a

private[airhack] object A {
  
    val hello = "hello"

}
package com.airhack.b

object B {
  
    // A is missing the import, metals doesn't suggest importing A, even though the import would be valid
    val hello = A.hello

}

The import quick fix works perfectly fine when A is public. Right now this means that I have to write a lot of imports by hand. It would be really nice if metals could suggest the imports automatically!

I'm not sure if this would be a bug or feature request and whether metals is even the right project - it might be an upstream issue.

I'd be grateful if someone could point me in the right direction!

@tgodzik tgodzik added bug Something that is making a piece of functionality unusable Scala 2 labels Aug 28, 2024
@masonedmison
Copy link
Contributor

Has anyone started looking at this one yet? If not, I'd be happy to take a look at this.

@tgodzik
Copy link
Contributor Author

tgodzik commented Sep 5, 2024

I don't think anyone had the time, so you're welcome to take a look.

Some places to take a look at:

This one is used for the auto imports code action.

We used this one to get members to import found from indexing via metals.

Here we provide the potential matches

@masonedmison
Copy link
Contributor

Thanks @tgodzik! I believe I've found in the code where symbols are being filtered by visibility. It looks like something similar is done in the scala 3 implementation.

I'll have to have a deeper look into the scala reflection documentation (I can start with scala 2 if that's OK with you) to get a better sense on how to get the "access" modifier from a Symbol.

@tgodzik
Copy link
Contributor Author

tgodzik commented Sep 6, 2024

Actually, this might be as simple as doing sym.isPublic || sym.hasAccessBoundary, from what I see we do check accessibility anyway later on.

You could just try that with some tests for good measure.

@masonedmison
Copy link
Contributor

@tgodzik I made a bit of progress on this and opened up a draft PR. If we like this approach, it should be fairly easy to take a similar approach for the Scala 3 AutoImportsProvider implementation.

@tgodzik tgodzik added this to the Metals v1.4.0 milestone Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that is making a piece of functionality unusable Scala 2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants