Skip to content

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

Closed
@s-and-witch

Description

@s-and-witch

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: needs triagetype: bugSomething isn't right: doesn't work as intended, documentation is missing/outdated, etc..

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions