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

More flexible prefix matching #3585

Closed
noughtmare opened this issue May 9, 2023 · 11 comments
Closed

More flexible prefix matching #3585

noughtmare opened this issue May 9, 2023 · 11 comments
Labels
type: enhancement New feature or request

Comments

@noughtmare
Copy link
Contributor

noughtmare commented May 9, 2023

Is your enhancement request related to a problem? Please describe.

The problem occurs when you add a new module, but forget to update your cabal file. Then HLS will show an error that is hard to understand:

Multi Cradle: No prefixes matched
pwd: c:\Users\nubch\Documents\haskell\tictactoe\tictactoe2 filepath: C:\Users\nubch\Documents\haskell\tictactoe\tictactoe2\app\Libr.hs prefixes: ("app/Main.hs",Cabal {component = Just "tictactoe2:exe:tictactoe2"})

Full context: https://old.reddit.com/r/haskell/comments/13c1ga5/on_the_verge_of_giving_up_learning_haskell/

Edit, another victim: https://discourse.haskell.org/t/cabal-quickstart-with-hls-pains/6867

Describe the solution you'd like

HLS should handle modules that are not explicitly listed in the other-modules or exposed-modules fields as long as the modules are still located in a directory specified by hs-source-dirs. It should still display a warning that the module is not listed in the cabal file, but it should not prevent HLS from working on those unlisted modules.

Describe alternatives you've considered

We could keep the status quo and require users to edit the cabal file or create a hie.yaml file, but those are both manual actions that take a small bit of effort and more importantly it is one more thing for newcomers to get stuck on as the reddit thread linked above shows.

Another alternative is that HLS could show a better error message which spells out that you might need to update your cabal file. I think this would be much better than the status quo, but not as good as just being more flexible.

@noughtmare noughtmare added the type: enhancement New feature or request label May 9, 2023
@michaelpj michaelpj transferred this issue from haskell/haskell-language-server May 10, 2023
@michaelpj
Copy link
Collaborator

This is a hie-bios issue.

@michaelpj
Copy link
Collaborator

Or possibly I'm wrong and it's implicit-hie 🤔 @fendor?

@fendor
Copy link
Collaborator

fendor commented May 10, 2023

@michaelpj While I agree that the issue happens in hie-bios, I don't think hie-bios is in the position to provide less accurate info or should start guessing to what component the file might belong to.

It is not the fault of implicit-hie either here, imo.

I think the best way would be in HLS (likely supported by hie-bios/cabal/stack) to provide better diagnostics, telling the user that they are missing something.

Although, this error message in particular is a combination of implicit-hie and hie-bios providing a subpar developer experience.

@michaelpj
Copy link
Collaborator

Hmm. So what happens is something like:

  • implicit-hie makes a specific hie-bios cradle that matches the various known paths
  • hie-bios notes that this file doesn't match any of the paths, so it gives up

So we're complaining about an issue in a file the user didn't write, which is always awkward. I'll put this back in HLS I guess, since it's kind of a combined issue.

@michaelpj michaelpj transferred this issue from haskell/hie-bios May 10, 2023
@noughtmare
Copy link
Contributor Author

noughtmare commented May 10, 2023

The reason why I think being more flexible is a better solution than just providing better error messages is that cabal build is also flexible in this situation. And I think it would be nice if HLS would always work if cabal build works.

Edit: I have now been convinced that a better error message and a code action to add the module to the cabal package would be a better solution.

@fendor
Copy link
Collaborator

fendor commented May 10, 2023

To be extremely pedantic, cabal is not flexible, it is ghc who picks up the file from the source directories, but HLS doesn't accept that and wants all targets explicitly listed.

@michaelpj
Copy link
Collaborator

I do think this is maybe an implicit-hie issue. implicit-hie could try and emit a match for other modules that are not in the cabal file and guess a component for them. It would be potentially error-prone but would probably work a lot of the time.

@seanhess
Copy link
Contributor

seanhess commented Jul 7, 2023

How can I help? I'm the author of the issue just linked above, and the user from the second discourse link in the OP. I'm an experienced haskeller, but with zero exposure to HLS or hie. If you point me in the right direction I'd be happy to work on it. I have a full week off before I start a new job. I hope that's enough time to become familiar enough to contribute something

@fendor
Copy link
Collaborator

fendor commented Jul 8, 2023

@seanhess Hi! I am currently putting together some thoughts in my head and I am going to write it down later this day.
Do you want to implement a better error message that tells the user potential remedies? This error message will then be used by @VeryMilkyJoe (who is our hls-cabal-plugin author for this summer) to implement a code action for #3595.

If you are interested to do that, then I will write a detailed roadmap for you. I am also available for a call for resolving questions.

@seanhess
Copy link
Contributor

seanhess commented Jul 8, 2023 via email

@fendor
Copy link
Collaborator

fendor commented Jul 8, 2023

closing in favour of #3695 which tracks the effort and outlines an implementation plan.

@fendor fendor closed this as completed Jul 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants