-
-
Notifications
You must be signed in to change notification settings - Fork 400
Description
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 = _
Expected behaviour
Strip the suggestion
fooo :: () -> IO ()
fooo = _
Related code
As I can see, related code is this function:
haskell-language-server/plugins/hls-refactor-plugin/src/Development/IDE/Plugin/Plugins/Diagnostic.hs
Lines 46 to 52 in 1dd54a5
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:
haskell-language-server/plugins/hls-refactor-plugin/src/Development/IDE/Plugin/CodeAction.hs
Lines 880 to 882 in 1dd54a5
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.