Closed
Description
Your environment
Which OS do you use:
Ubuntu
Which LSP client (editor/plugin) do you use:
emacs+lsp-mode
Describe your project (alternative: link to the project):
HLS :)
Steps to reproduce
- Use a function that has yet to be defined ex:
filter isValidMessage messages
(whereisValidMessage
is not yet created) - Apply code action to define
isValidMessage
Expected behaviour
The function should be added, without disrupting another binding and it's Haddock Comment.
Actual behaviour
The function is defined underneath an existing Haddock Comment
Include debug information
Before:
-- | If a diagnostic has the proper message create a ChangeSignature from it
matchingDiagnostic :: Uri -> Diagnostic -> Maybe ChangeSignature
matchingDiagnostic uri diag@Diagnostic{_message} = case map (unwrapMatch . (=~) _message) errorMessageRegexes of
[] -> Nothing
css -> join $ find isJust $ filter isValidMessage css
where
unwrapMatch :: (Text, Text, Text, [Text]) -> Maybe ChangeSignature
-- due to using (.|\n) in regex we have to drop the erroneous, but necessary ("." doesn't match newlines), match
unwrapMatch (_, _, _, [exp, act, _, name]) = Just $ ChangeSignature exp act name Nothing diag uri
unwrapMatch _ = Nothing
-- | List of regexes that match various Error Messages
errorMessageRegexes :: [Text]
errorMessageRegexes = [ -- be sure to add new Error Messages Regexes at the bottom to not fail any existing tests
"Expected type: (" <> typeSigRegex <> ")\n +Actual type: (" <> typeSigRegex <> ")\n(.|\n)+In an equation for ‘(.+)’"
, "Couldn't match expected type ‘(" <> typeSigRegex <> ")’ with actual type ‘(" <> typeSigRegex <> ")’\n(.|\n)+In an equation for ‘(.+)’"
]
where
typeSigRegex = "[a-zA-Z0-9 ->\\(\\)]+"
After:
-- | If a diagnostic has the proper message create a ChangeSignature from it
matchingDiagnostic :: Uri -> Diagnostic -> Maybe ChangeSignature
matchingDiagnostic uri diag@Diagnostic{_message} = case map (unwrapMatch . (=~) _message) errorMessageRegexes of
[] -> Nothing
css -> join $ find isJust $ filter isValidMessage css
where
unwrapMatch :: (Text, Text, Text, [Text]) -> Maybe ChangeSignature
-- due to using (.|\n) in regex we have to drop the erroneous, but necessary ("." doesn't match newlines), match
unwrapMatch (_, _, _, [exp, act, _, name]) = Just $ ChangeSignature exp act name Nothing diag uri
unwrapMatch _ = Nothing
-- | List of regexes that match various Error Messages
isValidMessage :: Maybe ChangeSignature -> Maybe ChangeSignature
isValidMessage = error "not implemented"
errorMessageRegexes :: [Text]
errorMessageRegexes = [ -- be sure to add new Error Messages Regexes at the bottom to not fail any existing tests
"Expected type: (" <> typeSigRegex <> ")\n +Actual type: (" <> typeSigRegex <> ")\n(.|\n)+In an equation for ‘(.+)’"
, "Couldn't match expected type ‘(" <> typeSigRegex <> ")’ with actual type ‘(" <> typeSigRegex <> ")’\n(.|\n)+In an equation for ‘(.+)’"
]
where
typeSigRegex = "[a-zA-Z0-9 ->\\(\\)]+"