haskell / haskell-language-server

Official haskell ide support via language server (LSP). Successor of ghcide & haskell-ide-engine.
Apache License 2.0
2.66k stars 360 forks source link

Weird errors when a local intermediate component is not loaded #1370

Closed georgefst closed 1 year ago

georgefst commented 3 years ago

EDIT/tl;dr: This is a known issue, and the solution seems to involve https://github.com/haskell/haskell-language-server/issues/3422 and/or https://github.com/haskell/hie-bios/issues/269.

One of my projects hits a strange error which doesn't show up outside of HLS. Could be to do with the way I'm using cabal.project, or c2hs. No idea really.

When loading evdev-examples/evtest/Main.hs:

• Couldn't match type ‘Device’
                 with ‘evdev-2.1.0:Evdev.Device’
  NB: ‘evdev-2.1.0:Evdev.Device’
        is defined in ‘Evdev’ in package ‘evdev-2.1.0’
      ‘Device’ is defined at
        /home/gthomas/Code/evdev/evdev/src/Evdev.hs:78:1-71
  Expected type: Streamly.Internal.Data.Stream.Async.AsyncT
                   IO evdev-2.1.0:Evdev.Device
    Actual type: Streamly.Internal.Data.Stream.Async.AsyncT IO Device
• In the second argument of ‘($)’, namely
    ‘S.mapM printNewDevice $ newDevices' $ read t’
  In the second argument of ‘($)’, namely
    ‘readEventsMany $ S.mapM printNewDevice $ newDevices' $ read t’
  In a stmt of a 'do' block:
    S.mapM_ pPrint
      $ readEventsMany $ S.mapM printNewDevice $ newDevices' $ read t

PS. will only build on Linux (or BSD)

haskell-language-server version: 0.9.0.0 (GHC: 8.10.2) (PATH: /home/gthomas/.config/Code - OSS/User/globalStorage/haskell.haskell/haskell-language-server-0.9.0-linux-8.10.2) (GIT hash: 46d2a3dc7ef49ba57b2706022af1801149ab3f2b)
Tool versions found on the $PATH
cabal:      3.2.0.0
stack:      Not found
ghc:        8.10.2
LSP logs:
``` [client] run command: "/home/gthomas/.config/Code - OSS/User/globalStorage/haskell.haskell/haskell-language-server-0.9.0-linux-8.10.2 --lsp" [client] debug command: "/home/gthomas/.config/Code - OSS/User/globalStorage/haskell.haskell/haskell-language-server-0.9.0-linux-8.10.2 --lsp" [client] server cwd: undefined haskell-language-server version: 0.9.0.0 (GHC: 8.10.2) (PATH: /home/gthomas/.config/Code - OSS/User/globalStorage/haskell.haskell/haskell-language-server-0.9.0-linux-8.10.2) (GIT hash: 46d2a3dc7ef49ba57b2706022af1801149ab3f2b) Starting (haskell-language-server)LSP server... with arguments: LspArguments {argLSP = True, argsCwd = Nothing, argFiles = [], argsShakeProfiling = Nothing, argsTesting = False, argsExamplePlugin = False, argsDebugOn = False, argsLogFile = Nothing, argsThreads = 0, argsProjectGhcVersion = False} with plugins: [PluginId "brittany",PluginId "class",PluginId "eval",PluginId "floskell",PluginId "fourmolu",PluginId "ghcide-code-actions",PluginId "ghcide-completions",PluginId "ghcide-hover-and-symbols",PluginId "ghcide-type-lenses",PluginId "haddockComments",PluginId "hlint",PluginId "importLens",PluginId "moduleName",PluginId "ormolu",PluginId "pragmas",PluginId "retrie",PluginId "splice",PluginId "stylish-haskell",PluginId "tactic"] in directory: /home/gthomas/Code/evdev If you are seeing this in a terminal, you probably should have run ghcide WITHOUT the --lsp option! Started LSP server in 0.10s 2021-02-12 14:19:18.360115946 [ThreadId 21] - Registering ide configuration: IdeConfiguration {workspaceFolders = fromList [NormalizedUri 8300828575177198912 "file:///home/gthomas/Code/monpad",NormalizedUri 8343285067462406768 "file:///home/gthomas/Code/music",NormalizedUri 109631572554722720 "file:///home/gthomas/Code/evdev-streamly-blocking-bug",NormalizedUri 3112717853944786625 "file:///home/gthomas/Code/hs-scripts",NormalizedUri 5742617178898687330 "file:///home/gthomas/Code/hlint",NormalizedUri 6881108509642929891 "file:///home/gthomas/Desktop",NormalizedUri 4061987544770403812 "file:///home/gthomas/Code/fourmolu",NormalizedUri (-470015693029166090) "file:///home/gthomas/Stuff/george-conf",NormalizedUri 1636838228875072503 "file:///home/gthomas/Code/ghcide",NormalizedUri (-4359575752087986441) "file:///home/gthomas/Code/evdev",NormalizedUri 6637041034560558524 "file:///home/gthomas/Code/pretty-simple",NormalizedUri (-2061641255772700819) "file:///home/gthomas/Code/net-evdev"], clientSettings = hashed Nothing} 2021-02-12 14:19:18.383113745 [ThreadId 21] - Configuration changed: Object (fromList [("haskell",Object (fromList [("logFile",String ""),("updateBehavior",String "keep-up-to-date"),("hlintOn",Bool True),("formatOnImportOn",Bool True),("indentationRules",Object (fromList [("enabled",Bool True)])),("liquidOn",Bool False),("languageServerVariant",String "haskell-language-server"),("serverExecutablePath",String ""),("diagnosticsOnChange",Bool True),("completionSnippetsOn",Bool True),("maxNumberOfProblems",Number 100.0),("formattingProvider",String "fourmolu"),("trace",Object (fromList [("server",String "off")]))]))]) 2021-02-12 14:19:18.384282759 [ThreadId 21] - Opened text document: file:///home/gthomas/Code/evdev/evdev-examples/evtest/Main.hs 2021-02-12 14:19:18.385052166 [ThreadId 74] - hlint:getIdeas:file:NormalizedFilePath "/home/gthomas/Code/evdev/evdev-examples/evtest/Main.hs" 2021-02-12 14:19:18.387873017 [ThreadId 81] - Consulting the cradle for "evdev-examples/evtest/Main.hs" Output from setting up the cradle Cradle {cradleRootDir = "/home/gthomas/Code/evdev", cradleOptsProg = CradleAction: Cabal} > Resolving dependencies... > Build profile: -w ghc-8.10.2 -O1 > In order, the following will be built (use -v for more details): > - evdev-2.0.0.1 (lib) (configuration changed) > - evdev-streamly-0.0.1.0 (lib) (configuration changed) > - evdev-examples-0.1.0.0 (exe:evtest) (configuration changed) > Configuring library for evdev-2.0.0.1.. > Preprocessing library for evdev-2.0.0.1.. > Building library for evdev-2.0.0.1.. > [5 of 5] Compiling Evdev.Uinput ( src/Evdev/Uinput.hs, /home/gthomas/Code/evdev/dist-newstyle/build/x86_64-linux/ghc-8.10.2/evdev-2.0.0.1/build/Evdev/Uinput.o, /home/gthomas/Code/evdev/dist-newstyle/build/x86_64-linux/ghc-8.10.2/evdev-2.0.0.1/build/Evdev/Uinput.dyn_o ) > Configuring library for evdev-streamly-0.0.1.0.. > Preprocessing library for evdev-streamly-0.0.1.0.. > Building library for evdev-streamly-0.0.1.0.. > Configuring executable 'evtest' for evdev-examples-0.1.0.0.. > Preprocessing executable 'evtest' for evdev-examples-0.1.0.0.. 2021-02-12 14:19:37.617026665 [ThreadId 81] - Using interface files cache dir: ghcide 2021-02-12 14:19:37.617107221 [ThreadId 81] - Making new HscEnv[main] 2021-02-12 14:19:37.650001752 [ThreadId 188] - hlint:getIdeas:file:NormalizedFilePath "/home/gthomas/Code/evdev/evdev-examples/evtest/Main.hs" 2021-02-12 14:19:37.65048975 [ThreadId 208] - finish: getSession (took 0.00s) 2021-02-12 14:19:37.650485194 [ThreadId 210] - finish: ModuleName.ghcSession (took 0.00s) 2021-02-12 14:19:37.653188037 [ThreadId 216] - finish: importLens (took 0.00s) 2021-02-12 14:19:37.653380045 [ThreadId 213] - finish: CodeAction (took 0.00s) 2021-02-12 14:19:37.653549347 [ThreadId 216] - finish: splice.codeAction.GitHieAst (took 0.00s) 2021-02-12 14:19:37.653590978 [ThreadId 213] - finish: addPragma (took 0.00s) 2021-02-12 14:19:37.653628629 [ThreadId 216] - finish: Outline (took 0.00s) 2021-02-12 14:19:37.653670346 [ThreadId 213] - finish: HaddockComments.GetAnnotatedParsedSource (took 0.00s) 2021-02-12 14:19:37.65444715 [ThreadId 216] - finish: ModuleName.GetParsedModule (took 0.00s) 2021-02-12 14:19:37.943742516 [ThreadId 216] - finish: codeLens (took 0.29s) 2021-02-12 14:19:37.943712656 [ThreadId 286] - finish: retrie (took 0.29s) 2021-02-12 14:19:37.94405097 [ThreadId 216] - finish: (took 0.29s) 2021-02-12 14:19:37.94523775 [ThreadId 286] - finish: tactic (took 0.30s) 2021-02-12 14:19:37.945737659 [ThreadId 214] - finish: tactic (took 0.00s) 2021-02-12 14:19:37.945883579 [ThreadId 214] - finish: tactic (took 0.00s) 2021-02-12 14:19:38.188846578 [ThreadId 298] - finish: CodeAction:PackageExports (took 0.53s) ```
wz1000 commented 3 years ago

https://github.com/haskell/haskell-language-server/tree/master/ghcide#limitations-to-multi-component-support

jneira commented 3 years ago

For completeness, this would be a manifestation of

There is a known issue where if you have three components, such that A depends on B which depends on C then if you load A and C into the session but not B then under certain situations you can get strange errors about a type coming from two different places. See this repo for a simple reproduction of the bug.

kokobd commented 2 years ago

Any update on this? Or do we have a known workaround, for example a quick way to load all packages in the local project?

jneira commented 2 years ago

Afaik no other than load the appropiate files to load all the needed components. The long awaited proper fix (for this and so many other hls issues around setup) would be the use of show-build-info in cabal/stack, see https://github.com/haskell/hie-bios/issues/269

georgefst commented 2 years ago

Does https://github.com/haskell/haskell-language-server/pull/2994 fix this? I don't have a GHC-9.4-compatible reproducer to hand.

georgefst commented 2 years ago

Oh, I missed @jneira's comment above. I thought this was down to MHU, not show-build-info. Must have misremembered.

georgefst commented 1 year ago

As alluded to in https://github.com/haskell/haskell-language-server/issues/3422, this tends to manifest differently with GHC 9.4, usually with spurious "overlapping instance" errors.

georgefst commented 1 year ago

Closing in favour of #3738.