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

Unexpected import (implicit) Prelude code lens #2798

Closed
konsumlamm opened this issue Mar 23, 2022 · 6 comments · Fixed by #3277
Closed

Unexpected import (implicit) Prelude code lens #2798

konsumlamm opened this issue Mar 23, 2022 · 6 comments · Fixed by #3277
Labels
component: imports plugin GHC issues with particular GHC versions level: easy The issue is suited for beginners type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@konsumlamm
Copy link

konsumlamm commented Mar 23, 2022

Example

import_implicit_prelude1

I'm not sure if the import (implicit) Prelude code lens itself supposed to be a feature or not, but the import code lens for the module isn't shown. When a newline is added before, this doesn't occur:

import_implicit_prelude2

GHC version: 9.2.2
HLS version: 1.7.0.0

@fendor
Copy link
Collaborator

fendor commented Mar 24, 2022

Thank you for the bug report! Moving to HLS repo where this feature is implemented

@fendor fendor transferred this issue from haskell/vscode-haskell Mar 24, 2022
@drsooch
Copy link
Collaborator

drsooch commented May 1, 2022

Any extra information on this? HLS version? GHC version? Project details (are you using some non-standard setup)?

I tried to repro with a simple file but didn't see anything.

@Ailrun Ailrun added type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. status: needs repro component: imports plugin and removed status: needs triage labels May 1, 2022
@konsumlamm
Copy link
Author

konsumlamm commented May 1, 2022

Sorry, I edited the issue to include the GHC and HLS versions. There is no non-standard setup, just a simple default setup (generated by cabal init).

@drsooch
Copy link
Collaborator

drsooch commented May 1, 2022

Looks like this just affects GHC 9.2.*

@drsooch drsooch added GHC issues with particular GHC versions and removed status: needs repro labels May 1, 2022
@michaelpj michaelpj added the level: easy The issue is suited for beginners label May 30, 2022
@sloorush
Copy link
Contributor

sloorush commented Jun 7, 2022

I tried to reproduce the error, and it is reproducible.

The import (implicit) Prelude () text comes up when the import statement is in the first list of the file. Here is a screenshot comparing the two situations:

image

Testing on ghc-9.2.2, this was not reproducible on ghc-9.0.2

@ChristophHochrainer
Copy link
Contributor

ChristophHochrainer commented Oct 9, 2022

Hey, I could also reproduce it and I believe to have found the culprit.

I believe it is the function minimalImportsRule inside plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs, or more specifically the importsMap.

let importsMap =
        Map.fromList
          [ (realSrcSpanStart l, printOutputable i)
            | L (locA -> RealSrcSpan l _) i <- fromMaybe [] mbMinImports
          ]
      res =
        [ (i, Map.lookup (realSrcSpanStart l) importsMap)
          | i <- imports
          , RealSrcSpan l _ <- [getLoc i]
        ]

This map uses the source location as key and only allows a single value and not a value list. The GHC API always gives the import (implicit) Prelude suggestion in the first line. So every other import in the first line collides with this and gets overridden. A solution to this could be exclude the Prelude code action.

ChristophHochrainer added a commit to ChristophHochrainer/haskell-language-server that referenced this issue Oct 9, 2022
ChristophHochrainer added a commit to ChristophHochrainer/haskell-language-server that referenced this issue Oct 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: imports plugin GHC issues with particular GHC versions level: easy The issue is suited for beginners type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants