Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/Haskell/Ide/Engine/Plugin/GhcMod.hs
Original file line number Diff line number Diff line change
Expand Up @@ -304,24 +304,27 @@ extractRenamableTerms msg
| "ot in scope:" `T.isInfixOf` msg = extractSuggestions msg
| otherwise = []
where
extractSuggestions = map getEnclosed
extractSuggestions = map extractTerm
. concatMap singleSuggestions
. filter isKnownSymbol
. T.lines
singleSuggestions = T.splitOn "), " -- Each suggestion is comma delimited
isKnownSymbol t = " (imported from" `T.isInfixOf` t || " (line " `T.isInfixOf` t
getEnclosed' b e = T.dropWhile (== b)
. T.dropWhileEnd (== e)
. T.dropAround (\c -> c /= b && c /= e)
getEnclosed txt = case getEnclosed' '‘' '’' txt of
"" -> getEnclosed' '`' '\'' txt -- Needed for windows
enc -> enc

extractTerm :: T.Text -> T.Text
extractTerm txt =
case extract '‘' '’' txt of
"" -> extract '`' '\'' txt -- Needed for windows
term -> term
where extract b e = T.dropWhile (== b)
. T.dropWhileEnd (== e)
. T.dropAround (\c -> c /= b && c /= e)

extractRedundantImport :: T.Text -> Maybe T.Text
extractRedundantImport msg =
if ("The import of " `T.isPrefixOf` firstLine || "The qualified import of " `T.isPrefixOf` firstLine)
&& " is redundant" `T.isSuffixOf` firstLine
then Just $ T.init $ T.tail $ T.dropWhileEnd (/= '’') $ T.dropWhile (/= '‘') firstLine
then Just $ extractTerm firstLine
else Nothing
where
firstLine = case T.lines msg of
Expand Down Expand Up @@ -398,9 +401,6 @@ extractUnusedTerm msg = extractTerm <$> stripMessageStart msg
where
stripMessageStart = T.stripPrefix "Defined but not used:"
. T.strip
extractTerm = T.dropWhile (== '‘')
. T.dropWhileEnd (== '’')
. T.dropAround (\c -> c /= '‘' && c /= '’')

-- ---------------------------------------------------------------------

Expand Down
22 changes: 12 additions & 10 deletions src/Haskell/Ide/Engine/Plugin/HsImport.hs
Original file line number Diff line number Diff line change
Expand Up @@ -483,17 +483,19 @@ extractImportableTerm dirtyMsg = do
$ T.unlines
$ map T.strip
$ T.lines
$ T.replace "* " "" -- Needed for Windows
$ T.replace "• " "" dirtyMsg

extractedTerm = asum
[ importMsg
>>= T.stripPrefix "Variable not in scope: "
>>= \name -> Just (name, Import Symbol)
, importMsg
>>= T.stripPrefix "Not in scope: type constructor or class ‘"
>>= \name -> Just (T.init name, Import Type)
, importMsg
>>= T.stripPrefix "Data constructor not in scope: "
>>= \name -> Just (name, Import Constructor)]
extractTerm prefix symTy =
importMsg
>>= T.stripPrefix prefix
>>= \name -> Just (name, Import symTy)

extractType b =
extractTerm ("Not in scope: type constructor or class " <> b) Type

extractedTerm = asum
[ extractTerm "Variable not in scope: " Symbol
, extractType "‘"
, extractType "`" -- Needed for windows
, extractTerm "Data constructor not in scope: " Constructor]
14 changes: 11 additions & 3 deletions src/Haskell/Ide/Engine/Plugin/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,19 @@ codeActionProvider plId docId _ context = do
-- | Extract a module name from an error message.
extractModuleName :: T.Text -> Maybe Package
extractModuleName msg
| T.isPrefixOf "Could not find module " msg = Just $ T.tail $ T.init nameAndQuotes
| T.isPrefixOf "Could not load module " msg = Just $ T.tail $ T.init nameAndQuotes
| T.isPrefixOf "Could not find module " msg = Just $ extractTerm line
| T.isPrefixOf "Could not load module " msg = Just $ extractTerm line
| otherwise = Nothing
where line = head $ T.lines msg
nameAndQuotes = T.dropWhileEnd (/= '’') $ T.dropWhile (/= '‘') line

extractTerm :: T.Text -> T.Text
extractTerm txt =
case extract '‘' '’' txt of
"" -> extract '`' '\'' txt -- Needed for windows
term -> term
where extract b e = T.dropWhile (== b)
. T.dropWhileEnd (== e)
. T.dropAround (\c -> c /= b && c /= e)

-- Example error messages
{- GHC 8.6.2 error message is
Expand Down