-
-
Notifications
You must be signed in to change notification settings - Fork 367
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
Improve the error message for unknown modules #3695
Comments
@seanhess This tries to explain the context and the roadmap. Happy to flesh out any details if you have questions. But as you can imagine, this is a big problem, with lots of moving parts, so I might be forgetting some things. |
This is great, thanks for the help getting oriented and clear roadmap. I'm on it! |
@fendor Tests are failing after checkout. I followed the contributing guidelines. ghc 9.6.2, cabal 3.10.1.0. Is there a specific ghc version I should be using?
|
We have a lot of problems with flaky tests :( I might just ignore it if I was you @fendor rather than parsing the error, could we pass up more structured errors from |
I'm struggling to figure out how to hack HLS. Following the instructions in the contributing guide, I've built HLS with Even if I manually run that binary in my test directory, it doesn't pick up any changes. I've tried hacking Steps:
Results: I get the exact same error message as I did before I changed the code, and the term "HELLO" doesn't appear in my terminal.
|
Well, yesn't, that'd be moving the parsing to hie-bios. Which is fine in my opinion. @seanhess Check in the stderr logs if the correct hls binary is invoked. For this issue in particular, it should be enough to run the binary directly, e.g.
Also, it might be helpful to ask on IRC libera #haskell-language-server for quicker help with setup issues. |
Should I work in hie-bios then? |
@fendor See PR ^ I couldn't figure out how to test hie-bios correctly, so instead I'm parsing the error here. |
The one major advantage of this approach, presumably, is that there's much less waiting around when adding a new module. Since adding a new entry to Perhaps we could do both? Unless there's work going on in Cabal to make these reloads quicker, at least for such simple cases? |
Yeah, that's true, that's an advantage, but it may also break unexpectedly. For example, you run If we do both... what would happen in that situation? You still see an error/warning at the very top, you may just ignore it for some time. Ignorable errors/warnings are not great UX in my opinion.
If we can reliably figure out that we just added a module to a cradle, I think we might do something cool in HLS itself. |
Context
When users add a new module to a cabal project, they are usually greeted with an uninformative
Multi Cradle: No prefixes matched
or something similar.We can identify three different cases and different behaviour:
1. Adding an other-module
Test.hs
to an executable componentIn an example project with only a
Main.hs
module, adding an other-moduleTest.hs
results in the following error message:The cause is that
implicit-hie
generates roughly this hie.yaml fileWhich essentially means, only map
./app/Main.hs
to the componentexample:exe:example
. Clearly./app/Test.hs
is not listed here, resulting in the sub-par error message fromhie-bios
.Note,
implicit-hie
doesn't handle overlapping source directories correctly in most cases, see #3606 for example.2. Adding an exposed-module to a library component
This generally works ok because
implicit-hie
generateshie.yaml
s of the form:Essentially, maps for each source directory to the library component. So why does this work even if a hypothetical
Lib.hs
is not part of the library component?hie-bios
doesn't care about that and just gives us the compilation options for the componentexample.:lib
. Then haskell-language-server just takes the options, creates a unit, and addsLib.hs
to it:haskell-language-server/ghcide/session-loader/Development/IDE/Session.hs
Line 841 in feb5965
Read the comment right above it for the justification.
That's why adding modules to a library works "okayish" most of the time.
3. Adding a new module to a component with a simple 'hie.yaml'
However, this all falls apart when we handwrite the recommended hie.yaml file:
This basically runs
cabal repl src/Lib.hs
to find the compilation options. However, thencabal
complains even in the case where it previously was working fine!Naturally, if
Lib.hs
is not an exposed- or other-module of the library component,cabal
cannot find it. In this case, the error message is terrible in particular, as it tries to interpret the target as a cabal script, which is not even close to the desired result.Solution
We can identify at least two possible ways forward.
One way, is improving
implicit-hie
to generate more laxhie.yaml
files. I am in general against that approach. It will conceal the problem, and will just produce inconsistent views between the build-tool (cabal) and HLS. E.g. HLS reports no error or warning whilecabal build
straight up fails (also the package is rejected on hackage, etc..).The better approach is to interject these terrible error messages and provide useful, actionable diagnostics to the user.
For example, for the first example, we should display a message like this:
It might not always be possible to provide precise information, but general information, perhaps with links to https://errors.haskell.org/, would be great already.
To improve the error message further, there are a couple of hacky solutions we can think of. We can try to guess the component the module likely will be part of by looking at already loaded components, and comparing the importPaths. If the loaded component options have a unit-id (supplied by
-this-unit-id
), we can then lookup that unit-id indist-newstyle/cache/plan.json
, find the component and produce a more accurate error message.Fixing the issue programmatically is not something we want to do in this issue, we want to focus on purely better error messages.
Implementation Roadmap
haskell-language-server/ghcide/session-loader/Development/IDE/Session.hs
Line 738 in feb5965
haskell-language-server/ghcide/session-loader/Development/IDE/Session.hs
Line 939 in feb5965
dist-newstyle/cache/plan.json
helps you map aunit-id
to a component name.This issue tracks the effort for improving the error message.
The text was updated successfully, but these errors were encountered: