Skip to content

Code action to define undefined variables includes suggestions in type signature #3795

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
jameshaydon opened this issue Sep 7, 2023 · 5 comments
Labels
type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@jameshaydon
Copy link

jameshaydon commented Sep 7, 2023

Your environment

MacOS
GHC 9.4.5 from ghcup
cabal
emacs+lsp-mode
HLS v2.2.0.0 from ghcup

Steps to reproduce

Write some code with an undefined variable, e.g.:

foo :: Int -> Int
foo x = plus x (plus x x)

Invoke the code action Define plus...

Result:

plus :: Int -> t0 -> Int Suggested fix: Perhaps use mplus (imported from Control.Monad.Reader)
plus = _

Expected behaviour

The suggestion should not be in the type signature, possibly it could be a comment before/after the type signature.

Actual behaviour

Suggestion in the signature, causing a parse error.

@jameshaydon jameshaydon added status: needs triage type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. labels Sep 7, 2023
@michaelpj
Copy link
Collaborator

Looks like a bug in the regex for parsing stuff out of the GHC error message...

@jhrcek
Copy link
Collaborator

jhrcek commented Jan 24, 2024

Stumbled upon this while checking for some easy bugs to fix.
It seems the problem is that the bug is coming from this regex and the fact that

  • the regex works on pre-processed error message in which spaces have been unified (that is replace every sequence of whitespace (including newlines) in the error with a single space).
  • it seems that recent GHCs don't contain the "bulletpoint" characters that the regex uses to detect the end of type signature in the error.

This shouldn't be that hard to fix, but I wonder if it's worth trying to make the regexes more robust, or try to use the new structured erros for this (which were only introduced in recent GHCs, something like 9.6+?)

@michaelpj any opinions?

@michaelpj
Copy link
Collaborator

I think using the structured errors is a whole project, I'm planning to propose it as a GSoC project. So probably not a quick fix. Whereas fixing the regex is a patch, but at least should be quick. What would be extremely helpful in any case would be writing a test that shows the problem!

jhrcek added a commit to jhrcek/haskell-language-server that referenced this issue Jan 24, 2024
fendor pushed a commit that referenced this issue Jan 26, 2024
* refactor plugin: add reproducer for #3795, fix few warnings in test

* Simplify reproducer, first attempt at fix
@jhrcek
Copy link
Collaborator

jhrcek commented Jan 26, 2024

Fixed in #4016 so this can be closed.

@fendor fendor closed this as completed Jan 26, 2024
@jameshaydon
Copy link
Author

Thanks!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
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

4 participants