Skip to content

Commit

Permalink
Fix hlint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jhrcek committed Feb 11, 2024
1 parent aedf448 commit c733396
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 24 deletions.
9 changes: 3 additions & 6 deletions ghcide/test/exe/InitializeResponseTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,16 @@ tests = withResource acquire release tests where
che :: TestName -> (ServerCapabilities -> Maybe ExecuteCommandOptions) -> [T.Text] -> TestTree
che title getActual expected = testCase title $ do
ir <- getInitializeResponse
ExecuteCommandOptions {_commands = commands} <- assertJust "ExecuteCommandOptions" $ getActual $ innerCaps ir
ExecuteCommandOptions {_commands = commands} <- case getActual $ innerCaps ir of
Just eco -> pure eco
Nothing -> assertFailure "Was expecting Just ExecuteCommandOptions, got Nothing"
let commandNames = (!! 2) . T.splitOn ":" <$> commands
zipWithM_ (\e o -> T.isSuffixOf e o @? show (e,o)) (sort expected) (sort commandNames)

innerCaps :: TResponseMessage Method_Initialize -> ServerCapabilities
innerCaps (TResponseMessage _ _ (Right (InitializeResult c _))) = c
innerCaps (TResponseMessage _ _ (Left _)) = error "Initialization error"

assertJust :: String -> Maybe a -> IO a
assertJust s = \case
Nothing -> assertFailure $ "Expecting Just " <> s <> ", got Nothing"
Just x -> pure x

acquire :: IO (TResponseMessage Method_Initialize)
acquire = run initializeResponse

Expand Down
12 changes: 6 additions & 6 deletions plugins/hls-refactor-plugin/src/Development/IDE/GHC/Dump.hs
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@ showAstDataHtml a0 = html $

srcSpan :: SrcSpan -> SDoc
srcSpan ss = char ' ' <>
(hang (ppr ss) 1
hang (ppr ss) 1
-- TODO: show annotations here
(text ""))
(text "")

realSrcSpan :: RealSrcSpan -> SDoc
realSrcSpan ss = braces $ char ' ' <>
(hang (ppr ss) 1
hang (ppr ss) 1
-- TODO: show annotations here
(text ""))
(text "")

addEpAnn :: AddEpAnn -> SDoc
addEpAnn (AddEpAnn a s) = text "AddEpAnn" <+> ppr a <+> epaAnchor s
Expand Down Expand Up @@ -201,7 +201,7 @@ showAstDataHtml a0 = html $

located :: (Data a, Data b) => GenLocated a b -> SDoc
located (L ss a)
= nested "L" $ (li (showAstDataHtml' ss) $$ li (showAstDataHtml' a))
= nested "L" (li (showAstDataHtml' ss) $$ li (showAstDataHtml' a))

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

Expand Down Expand Up @@ -244,7 +244,7 @@ showAstDataHtml a0 = html $
annotationEpaLocation = annotation' (text "EpAnn EpaLocation")

annotation' :: forall a. Data a => SDoc -> EpAnn a -> SDoc
annotation' _tag anns = nested (text (showConstr (toConstr anns)) )
annotation' _tag anns = nested (text $ showConstr (toConstr anns))
(vcat (map li $ gmapQ showAstDataHtml' anns))

-- -------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -Wno-orphans #-}

-- | This module hosts various abstractions and utility functions to work with ghc-exactprint.
module Development.IDE.GHC.ExactPrint
( Graft(..),
Expand Down Expand Up @@ -435,7 +436,7 @@ modifySmallestDeclWithM validSpan f a = do
TransformT (lift $ validSpan $ locA src) >>= \case
True -> do
(decs', r) <- f ldecl
pure $ (DL.fromList decs' <> DL.fromList rest, Just r)
pure (DL.fromList decs' <> DL.fromList rest, Just r)
False -> first (DL.singleton ldecl <>) <$> modifyMatchingDecl rest
modifyDeclsT' (fmap (first DL.toList) . modifyMatchingDecl) a

Expand Down Expand Up @@ -477,7 +478,7 @@ modifySigWithM ::
TransformT m a
modifySigWithM queryId f a = do
let modifyMatchingSigD :: [LHsDecl GhcPs] -> TransformT m (DL.DList (LHsDecl GhcPs))
modifyMatchingSigD [] = pure (DL.empty)
modifyMatchingSigD [] = pure DL.empty
modifyMatchingSigD (ldecl@(L annSigD (SigD xsig (TypeSig xTypeSig ids (HsWC xHsWc lHsSig)))) : rest)
| queryId `elem` (unLoc <$> ids) = do
let newSig = f lHsSig
Expand Down Expand Up @@ -547,7 +548,7 @@ modifyMgMatchesT' (MG xMg (L locMatches matches)) f def combineResults = do
modifyMgMatchesT' (MG xMg (L locMatches matches) originMg) f def combineResults = do
(unzip -> (matches', rs)) <- mapM f matches
r' <- lift $ foldM combineResults def rs
pure $ (MG xMg (L locMatches matches') originMg, r')
pure (MG xMg (L locMatches matches') originMg, r')
#endif

graftSmallestDeclsWithM ::
Expand Down Expand Up @@ -716,7 +717,7 @@ modifyAnns x f = first ((fmap.fmap) f) x
removeComma :: SrcSpanAnnA -> SrcSpanAnnA
removeComma it@(SrcSpanAnn EpAnnNotUsed _) = it
removeComma (SrcSpanAnn (EpAnn anc (AnnListItem as) cs) l)
= (SrcSpanAnn (EpAnn anc (AnnListItem (filter (not . isCommaAnn) as)) cs) l)
= SrcSpanAnn (EpAnn anc (AnnListItem (filter (not . isCommaAnn) as)) cs) l
where
isCommaAnn AddCommaAnn{} = True
isCommaAnn _ = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ codeAction state _ (CodeActionParams _ _ (TextDocumentIdentifier uri) _range Cod
let
actions = caRemoveRedundantImports parsedModule text diag xs uri
<> caRemoveInvalidExports parsedModule text diag xs uri
pure $ InL $ actions
pure $ InL actions

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

Expand Down Expand Up @@ -189,7 +189,7 @@ extendImportHandler :: CommandFunction IdeState ExtendImport
extendImportHandler ideState _ edit@ExtendImport {..} = ExceptT $ do
res <- liftIO $ runMaybeT $ extendImportHandler' ideState edit
whenJust res $ \(nfp, wedit@WorkspaceEdit {_changes}) -> do
let (_, (head -> TextEdit {_range})) = fromJust $ _changes >>= listToMaybe . M.toList
let (_, head -> TextEdit {_range}) = fromJust $ _changes >>= listToMaybe . M.toList
srcSpan = rangeToSrcSpan nfp _range
LSP.sendNotification SMethod_WindowShowMessage $
ShowMessageParams MessageType_Info $
Expand Down Expand Up @@ -1532,7 +1532,8 @@ constructNewImportSuggestions
constructNewImportSuggestions exportsMap (qual, thingMissing) notTheseModules qis = nubOrdBy simpleCompareImportSuggestion
[ suggestion
| Just name <- [T.stripPrefix (maybe "" (<> ".") qual) $ notInScope thingMissing] -- strip away qualified module names from the unknown name
, identInfo <- maybe [] Set.toList $ (lookupOccEnv (getExportsMap exportsMap) (mkVarOrDataOcc name)) <> (lookupOccEnv (getExportsMap exportsMap) (mkTypeOcc name)) -- look up the modified unknown name in the export map
, identInfo <- maybe [] Set.toList $ lookupOccEnv (getExportsMap exportsMap) (mkVarOrDataOcc name)
<> lookupOccEnv (getExportsMap exportsMap) (mkTypeOcc name) -- look up the modified unknown name in the export map
, canUseIdent thingMissing identInfo -- check if the identifier information retrieved can be used
, moduleNameText identInfo `notElem` fromMaybe [] notTheseModules -- check if the module of the identifier is allowed
, suggestion <- renderNewImport identInfo -- creates a list of import suggestions for the retrieved identifier information
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,9 @@ extendImportViaParent df parent child (L l it@ImportDecl{..})
#endif
thing = IEThingWith newl twIE (IEWildcard 2) []
#if MIN_VERSION_ghc(9,7,0)
newl = fmap (\ann -> ann ++ [(AddEpAnn AnnDotdot d0)]) <$> l'''
newl = fmap (\ann -> ann ++ [AddEpAnn AnnDotdot d0]) <$> l'''
#else
newl = (\ann -> ann ++ [(AddEpAnn AnnDotdot d0)]) <$> l'''
newl = (\ann -> ann ++ [AddEpAnn AnnDotdot d0]) <$> l'''
#endif
lies = L l' $ reverse pre ++ [L l'' thing] ++ xs
return $ L l it'
Expand Down Expand Up @@ -383,12 +383,12 @@ extendImportViaParent df parent child (L l it@ImportDecl{..})
parentRdr <- liftParseAST df parent
let childRdr = reLocA $ L srcChild $ mkRdrUnqual $ mkVarOcc child
isParentOperator = hasParen parent
let parentLIE = reLocA $ L srcParent $ (if isParentOperator then IEType (epl 0) parentRdr'
let parentLIE = reLocA $ L srcParent $ if isParentOperator then IEType (epl 0) parentRdr'
else IEName
#if MIN_VERSION_ghc(9,5,0)
noExtField
#endif
parentRdr')
parentRdr'
parentRdr' = modifyAnns parentRdr $ \case
it@NameAnn{nann_adornment = NameParens} -> it{nann_open = epl 1, nann_close = epl 0}
other -> other
Expand Down
2 changes: 1 addition & 1 deletion plugins/hls-refactor-plugin/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ initializeTests = withResource acquire release tests
ir <- getInitializeResponse
ExecuteCommandOptions {_commands = commands} <- case getActual $ innerCaps ir of
Just eco -> pure eco
Nothing -> assertFailure $ "Was expecting Just ExecuteCommandOptions, got Nothing"
Nothing -> assertFailure "Was expecting Just ExecuteCommandOptions, got Nothing"
-- Check if expected exists in commands. Note that commands can arrive in different order.
mapM_ (\e -> any (\o -> T.isSuffixOf e o) commands @? show (expected, show commands)) expected

Expand Down

0 comments on commit c733396

Please sign in to comment.