Skip to content

Define Function Code Action should respect Haddock Comments #2715

Closed
@drsooch

Description

@drsooch

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

  1. Use a function that has yet to be defined ex: filter isValidMessage messages (where isValidMessage is not yet created)
  2. 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 ->\\(\\)]+"

Metadata

Metadata

Assignees

No one assigned

    Labels

    component: ghcidetype: 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