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

suggestImportDisambiguation does not interact well with DuplicateRecordFields #1457

Closed
berberman opened this issue Feb 28, 2021 · 8 comments
Closed
Labels
component: ghcide type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@berberman
Copy link
Collaborator

berberman commented Feb 28, 2021

Your environment

Output of haskell-language-server --probe-tools or haskell-language-server-wrapper --probe-tools:

haskell-language-server version: 1.0.0.0 (GHC: 8.10.3) (PATH: /home/berberman/.cabal/store/ghc-8.10.3/haskell-language-server-1.0.0.0-c7859e8f45ef6bd2fac7adc65982f4e497ee3c40299bcc89c5915aaa0534ebc3/bin/haskell-language-server)
Tool versions found on the $PATH
cabal:          3.2.0.0
stack:          Not found
ghc:            8.10.3

Which lsp-client do you use:
vscode

Expected behaviour

There should be no suggestion, because the ambiguity comes from DuplicateRecordFields, rather than imports.

Actual behaviour

2021

These code actions are meaningless in this case.

@berberman berberman added type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. good first issue component: ghcide labels Feb 28, 2021
@adamgundry
Copy link
Member

If you want to be really clever, in this situation you could suggest adding import qualified A as RecA (RecA(..) and replace with RecA.foo. But perhaps that's a bit complex to figure out.

@July541
Copy link
Collaborator

July541 commented Mar 31, 2021

For the original issue, I just wondering if we have another file B.hs simultaneously:

module B where

newtype RecC = RecC { foo :: Int }

What suggestions should ghcide gives? Maybe Replace with qualified: B.foo (cause hiding can not work for duplicated records) is not a bad choice.

@adamgundry 's idea seems an appropriate solution, which can eliminate the worry above, but it may make the original function suggestImportDisambiguation too huge to maintain, can anyone give some advice?


Meanwhile, we must notice that if we choose to keep the foo from B and hide others in the current version, it will print double foo in A.

image

If we choose foo from A and hide others, it will add hiding (foo) to the two imports simultaneously, it will use foo in RecB due to RecB is at the bottom of the RecA.

image

Our fix should consider these two situations. Please point out if I missed any other conditions.

@July541
Copy link
Collaborator

July541 commented Apr 2, 2021

@berberman I am trying to fix this issue by just remove all ambiguities that are from the same module, does it make sense?

@berberman
Copy link
Collaborator Author

@July541 Nice, what will it look like? Could you give an example?

@July541
Copy link
Collaborator

July541 commented Apr 2, 2021

@berberman Here are two samples:

  1. With the same records name in exactly one module, we will ignore all the ambiguities due to they are not caused by ambiguity imports.
    image

  2. For the mixture of real ambiguity records and DuplicateRecordFields caused ambiguity, we only keep the ambiguity one from files without DuplicateRecordFields extension as suggestions and drop others.
    image

@berberman
Copy link
Collaborator Author

Looks great, thanks!

@July541
Copy link
Collaborator

July541 commented Apr 2, 2021

@berberman Can you point me out where I can include some tests? I am not sure about how to integrate with a test.

@berberman
Copy link
Collaborator Author

@July541 You could find related tests here:

suggestImportDisambiguationTests :: TestTree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: ghcide type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..
Projects
None yet
Development

No branches or pull requests

3 participants