Skip to content

Refector plugin doesn't strip GHC suggestion on Define code action #4165

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

Closed
s-and-witch opened this issue Apr 7, 2024 · 3 comments
Closed
Labels
status: needs triage type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@s-and-witch
Copy link

s-and-witch commented Apr 7, 2024

HLS version:

I'm using

$ haskell-language-server --version 
haskell-language-server version: 2.6.0.0 (GHC: 9.6.4)

But this behavior could be reproduced with earlier versions of GHC.

Steps to reproduce

Try to use Define code action on name that is close enough to already existing identifier, e.g.

main :: IO ()
main = fooo ()

foo :: Int
foo = _

Here we already have foo (two "o") in the scope and on unknown identifier fooo (three "o") GHC will suggest fix "Perhaps use ‘foo’". This suggestion goes directly into code action, so it will define

fooo :: () -> IO () Suggested fix: Perhaps use foo (line 7)
fooo = _
Screenshots

изображение
изображение

Expected behaviour

Strip the suggestion

fooo :: () -> IO ()
fooo = _

Related code

As I can see, related code is this function:

matchVariableNotInScopeTyped message
| Just [name, typ0] <- matchRegexUnifySpaces message "Variable not in scope: ([^ ]+) :: ([^*•]+)"
, -- When some name in scope is similar to not-in-scope variable, the type is followed by
-- "Suggested fix: Perhaps use ..."
typ:_ <- T.splitOn " Suggested fix:" typ0 =
Just (name, typ)
| otherwise = Nothing

It propagates parsed type to code action builder here:

suggestNewDefinition ideOptions parsedModule contents Diagnostic {_message, _range}
| Just (name, typ) <- matchVariableNotInScope message =
newDefinitionAction ideOptions parsedModule _range name typ

And newDefinitionAction builds code action without any post-processing.

I'm not sure why typ:_ <- T.splitOn " Suggested fix:" typ0 doesn't work, additional debug is required.

@s-and-witch s-and-witch added status: needs triage type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. labels Apr 7, 2024
@michaelpj
Copy link
Collaborator

I think this got fixed recently? #4080 ?

Might well not be in 2.6, can you try with a later version or master?

@jhrcek
Copy link
Collaborator

jhrcek commented Apr 8, 2024

This should be fixed in 2.7.0.0.
I can't reproduce it with that version anymore:

fixed

@fendor
Copy link
Collaborator

fendor commented Apr 8, 2024

Thanks for verifying! Closing this as already fixed.

@fendor fendor closed this as completed Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage 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