diff --git a/GenChangelogs.hs b/GenChangelogs.hs index 908d2998ebc..bbb4b69443c 100755 --- a/GenChangelogs.hs +++ b/GenChangelogs.hs @@ -24,7 +24,7 @@ main = do prs <- github' $ pullRequestsForR "haskell" "haskell-language-server" stateClosed FetchAll let prsAfterLastTag = either (error . show) - (foldMap (\pr -> if inRange pr then [pr] else [])) + (foldMap (\pr -> [pr | inRange pr])) prs inRange pr | Just mergedDate <- simplePullRequestMergedAt pr = mergedDate > lastDate diff --git a/ghcide/.hlint.yaml b/ghcide/.hlint.yaml index 1829f648ff6..a429553bf8b 100644 --- a/ghcide/.hlint.yaml +++ b/ghcide/.hlint.yaml @@ -11,7 +11,6 @@ - ignore: {name: "Redundant do"} - ignore: {name: "Avoid lambda"} - ignore: {name: "Use newtype instead of data"} -- ignore: {name: "Use fromMaybe"} - ignore: {name: "Use unless"} - ignore: {name: "Move brackets to avoid $"} - ignore: {name: "Eta reduce"} @@ -25,6 +24,16 @@ - ignore: {name: "Use uncurry"} - ignore: {name: "Avoid lambda using `infix`"} +# We are using the "redundant" return/pure to assign a name. We do not want to +# delete it. In particular, this is not an improvement: +# Found: +# do options <- somethingComplicated +# pure options +# Perhaps: +# do somethingComplicated +- ignore: {name: "Redundant return"} +- ignore: {name: "Redundant pure"} + # Off by default hints we like - warn: {name: Use module export list} @@ -107,7 +116,7 @@ # Things that are unsafe in Haskell base library - {name: unsafeInterleaveIO, within: []} - {name: unsafeDupablePerformIO, within: []} - - {name: unsafeCoerce, within: []} + - {name: unsafeCoerce, within: [Ide.Plugin.Eval.Code]} # Things that are a bit dangerous in the GHC API - {name: nameModule, within: []} diff --git a/ghcide/session-loader/Development/IDE/Session.hs b/ghcide/session-loader/Development/IDE/Session.hs index b15adf694e4..341f489eeda 100644 --- a/ghcide/session-loader/Development/IDE/Session.hs +++ b/ghcide/session-loader/Development/IDE/Session.hs @@ -120,7 +120,7 @@ setInitialDynFlags = do hPutStrLn stderr $ "Couldn't load cradle for libdir: " ++ show (err,dir,hieYaml,cradle) pure Nothing CradleNone -> do - hPutStrLn stderr $ "Couldn't load cradle (CradleNone)" + hPutStrLn stderr "Couldn't load cradle (CradleNone)" pure Nothing dynFlags <- mapM dynFlagsForPrinting libdir mapM_ setUnsafeGlobalDynFlags dynFlags diff --git a/ghcide/src/Development/IDE/Spans/AtPoint.hs b/ghcide/src/Development/IDE/Spans/AtPoint.hs index 8007e839a74..243959e97af 100644 --- a/ghcide/src/Development/IDE/Spans/AtPoint.hs +++ b/ghcide/src/Development/IDE/Spans/AtPoint.hs @@ -158,7 +158,7 @@ documentHighlight hf rf pos = pure highlights ns = concat $ pointCommand hf pos (rights . M.keys . nodeIdentifiers . nodeInfo) highlights = do n <- ns - ref <- maybe [] id (M.lookup (Right n) rf) + ref <- fromMaybe [] (M.lookup (Right n) rf) pure $ makeHighlight ref makeHighlight (sp,dets) = DocumentHighlight (realSrcSpanToRange sp) (Just $ highlightType $ identInfo dets) @@ -266,12 +266,12 @@ typeLocationsAtPoint hiedb lookupModule _ideOptions pos (HAR _ ast _ _ hieKind) HQualTy a b -> getTypes [a,b] HCastTy a -> getTypes [a] _ -> [] - in fmap nubOrd $ concatMapM (fmap (maybe [] id) . nameToLocation hiedb lookupModule) (getTypes ts) + in fmap nubOrd $ concatMapM (fmap (fromMaybe []) . nameToLocation hiedb lookupModule) (getTypes ts) HieFresh -> let ts = concat $ pointCommand ast pos getts getts x = nodeType ni ++ (mapMaybe identType $ M.elems $ nodeIdentifiers ni) where ni = nodeInfo x - in fmap nubOrd $ concatMapM (fmap (maybe [] id) . nameToLocation hiedb lookupModule) (getTypes ts) + in fmap nubOrd $ concatMapM (fmap (fromMaybe []) . nameToLocation hiedb lookupModule) (getTypes ts) namesInType :: Type -> [Name] namesInType (TyVarTy n) = [Var.varName n] diff --git a/hls-plugin-api/src/Ide/PluginUtils.hs b/hls-plugin-api/src/Ide/PluginUtils.hs index 92da82629b1..00ff4fd550d 100644 --- a/hls-plugin-api/src/Ide/PluginUtils.hs +++ b/hls-plugin-api/src/Ide/PluginUtils.hs @@ -135,7 +135,7 @@ clientSupportsDocumentChanges caps = WorkspaceEditClientCapabilities mDc _ _ <- _workspaceEdit wCaps mDc in - fromMaybe False supports + Just True == supports -- --------------------------------------------------------------------- @@ -214,7 +214,7 @@ allLspCmdIds' pid mp = mkPlugin (allLspCmdIds pid) (Just . pluginCommands) allLspCmdIds :: T.Text -> [(PluginId, [PluginCommand ideState])] -> [T.Text] -allLspCmdIds pid commands = concat $ map go commands +allLspCmdIds pid commands = concatMap go commands where go (plid, cmds) = map (mkLspCmdId pid plid . commandId) cmds diff --git a/hls-plugin-api/src/Ide/Types.hs b/hls-plugin-api/src/Ide/Types.hs index f99ab309c0f..5f67c5b6a43 100644 --- a/hls-plugin-api/src/Ide/Types.hs +++ b/hls-plugin-api/src/Ide/Types.hs @@ -1,7 +1,6 @@ {-# LANGUAGE GADTs #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TupleSections #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE ViewPatterns #-} diff --git a/install/src/Cabal.hs b/install/src/Cabal.hs index 81a648ee28f..0a4733daff8 100644 --- a/install/src/Cabal.hs +++ b/install/src/Cabal.hs @@ -96,7 +96,7 @@ getProjectFile ver = do else "cabal.project" checkCabal_ :: [String] -> Action () -checkCabal_ args = checkCabal args >> return () +checkCabal_ args = void $ checkCabal args -- | check `cabal` has the required version checkCabal :: [String] -> Action String diff --git a/install/src/Env.hs b/install/src/Env.hs index 63883386397..397b9108f67 100644 --- a/install/src/Env.hs +++ b/install/src/Env.hs @@ -54,7 +54,7 @@ findInstalledGhcs = do -- sort by version to make it coherent with getHlsVersions $ sortBy (comparing fst) -- nub by version. knownGhcs takes precedence. - $ nubBy ((==) `on` fst) + $ nubOrdBy (compare `on` fst) -- filter out stack provided GHCs (assuming that stack programs path is the default one in linux) $ filter (not . isInfixOf ".stack" . snd) (knownGhcs ++ availableGhcs) diff --git a/install/src/Print.hs b/install/src/Print.hs index 063525e7ecd..b4937f4a323 100644 --- a/install/src/Print.hs +++ b/install/src/Print.hs @@ -25,7 +25,7 @@ printInStars = liftIO . putStrLn . embedInStars -- | Trim whitespace of both ends of a string trim :: String -> String -trim = dropWhileEnd isSpace . dropWhile isSpace +trim = trimEnd . trimStart -- | Trim the whitespace of the stdout of a command trimmedStdout :: Stdout String -> String diff --git a/plugins/default/src/Ide/Plugin/Fourmolu.hs b/plugins/default/src/Ide/Plugin/Fourmolu.hs index 95c0943f4c4..002fdc08481 100644 --- a/plugins/default/src/Ide/Plugin/Fourmolu.hs +++ b/plugins/default/src/Ide/Plugin/Fourmolu.hs @@ -93,7 +93,7 @@ provider ideState typ contents fp fo = withIndefiniteProgress title Cancellable convertDynFlags :: DynFlags -> IO [DynOption] convertDynFlags df = - let pp = if null p then [] else ["-pgmF=" <> p] + let pp = ["-pgmF=" <> p | not (null p)] p = D.sPgm_F $ D.settings df pm = map (("-fplugin=" <>) . moduleNameString) $ D.pluginModNames df ex = map showExtension $ S.toList $ D.extensionFlags df diff --git a/plugins/default/src/Ide/Plugin/Ormolu.hs b/plugins/default/src/Ide/Plugin/Ormolu.hs index bafee34f50c..1a1cee45bc5 100644 --- a/plugins/default/src/Ide/Plugin/Ormolu.hs +++ b/plugins/default/src/Ide/Plugin/Ormolu.hs @@ -44,7 +44,7 @@ provider ideState typ contents fp _ = withIndefiniteProgress title Cancellable $ let pp = let p = D.sPgm_F $ D.settings df - in if null p then [] else ["-pgmF=" <> p] + in ["-pgmF=" <> p | not (null p)] pm = map (("-fplugin=" <>) . moduleNameString) $ D.pluginModNames df ex = map showExtension $ S.toList $ D.extensionFlags df in diff --git a/plugins/default/src/Ide/Plugin/Pragmas.hs b/plugins/default/src/Ide/Plugin/Pragmas.hs index f1a3fc4926c..bef200645a7 100644 --- a/plugins/default/src/Ide/Plugin/Pragmas.hs +++ b/plugins/default/src/Ide/Plugin/Pragmas.hs @@ -1,5 +1,3 @@ -{-# LANGUAGE DeriveAnyClass #-} -{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ViewPatterns #-} @@ -12,6 +10,7 @@ module Ide.Plugin.Pragmas import Control.Lens hiding (List) import qualified Data.HashMap.Strict as H +import Data.Maybe (catMaybes) import qualified Data.Text as T import Development.IDE as D import Ide.Types @@ -78,7 +77,7 @@ codeActionProvider state _plId (CodeActionParams _ _ docId _ (J.CodeActionContex disabled | Just dynFlags <- mDynflags -- GHC does not export 'OnOff', so we have to view it as string - = [ e | Just e <- T.stripPrefix "Off " . T.pack . prettyPrint <$> extensions dynFlags] + = catMaybes $ T.stripPrefix "Off " . T.pack . prettyPrint <$> extensions dynFlags | otherwise -- When the module failed to parse, we don't have access to its -- dynFlags. In that case, simply don't disable any pragmas. diff --git a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs index 2b31039fb79..381b7b387e3 100644 --- a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs +++ b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs @@ -1,8 +1,6 @@ {-# LANGUAGE TypeApplications #-} {-# LANGUAGE ViewPatterns #-} {-# LANGUAGE LambdaCase #-} -{-# LANGUAGE DeriveAnyClass #-} -{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE ExtendedDefaultRules #-} {-# LANGUAGE FlexibleContexts #-} diff --git a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/Types.hs b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/Types.hs index d50b6652781..f981b4a37f4 100644 --- a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/Types.hs +++ b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/Types.hs @@ -55,6 +55,8 @@ type Loc = Located Line type Line = Int +{- HLINT ignore locate "Use zipWithFrom" -} + locate :: Loc [a] -> [Loc a] locate (Located l tst) = zipWith Located [l ..] tst diff --git a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/Util.hs b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/Util.hs index 1f573a58ac0..8406975c3eb 100644 --- a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/Util.hs +++ b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/Util.hs @@ -15,6 +15,7 @@ module Ide.Plugin.Eval.Util ( logWith, ) where +import Control.Monad.Extra (maybeM) import Control.Monad.IO.Class (MonadIO (liftIO)) import Control.Monad.Trans.Class (lift) import Control.Monad.Trans.Except ( @@ -84,7 +85,7 @@ handleMaybe :: Monad m => e -> Maybe b -> ExceptT e m b handleMaybe msg = maybe (throwE msg) return handleMaybeM :: Monad m => e -> m (Maybe b) -> ExceptT e m b -handleMaybeM msg act = maybe (throwE msg) return =<< lift act +handleMaybeM msg act = maybeM (throwE msg) return $ lift act response :: Functor f => ExceptT String f c -> f (Either ResponseError c) response = diff --git a/plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs b/plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs index e3027b1c24b..63290406da7 100644 --- a/plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs +++ b/plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs @@ -278,7 +278,7 @@ codeActionProvider ideState plId (CodeActionParams _ _ docId _ context) = Right in LSP.CodeAction "Apply all hints" (Just LSP.CodeActionQuickFix) Nothing Nothing Nothing Nothing (Just cmd) applyOneActions :: [LSP.CodeAction] - applyOneActions = catMaybes $ map mkHlintAction (filter validCommand diags) + applyOneActions = mapMaybe mkHlintAction (filter validCommand diags) -- |Some hints do not have an associated refactoring validCommand (LSP.Diagnostic _ _ (Just (InR code)) (Just "hlint") _ _ _) = diff --git a/plugins/hls-retrie-plugin/src/Ide/Plugin/Retrie.hs b/plugins/hls-retrie-plugin/src/Ide/Plugin/Retrie.hs index f6ee55f4fe7..f7b74032918 100644 --- a/plugins/hls-retrie-plugin/src/Ide/Plugin/Retrie.hs +++ b/plugins/hls-retrie-plugin/src/Ide/Plugin/Retrie.hs @@ -20,6 +20,7 @@ import Control.Concurrent.Extra (readVar) import Control.Exception.Safe (Exception (..), SomeException, catch, throwIO, try) import Control.Monad (forM, unless) +import Control.Monad.Extra (maybeM) import Control.Monad.IO.Class (MonadIO (liftIO)) import Control.Monad.Trans.Class (MonadTrans (lift)) import Control.Monad.Trans.Except (ExceptT (..), runExceptT, @@ -146,14 +147,14 @@ extractImports ModSummary{ms_mod} topLevelBinds (Unfold thing) , names <- listify p fun_matches = [ AddImport {..} - | name <- names, - Just ideclNameString <- - [moduleNameString . GHC.moduleName <$> nameModule_maybe name], - let ideclSource = False, + | let ideclSource = False, + name <- names, let r = nameRdrName name, let ideclQualifiedBool = isQual r, let ideclAsString = moduleNameString . fst <$> isQual_maybe r, - let ideclThing = Just (IEVar $ occNameString $ rdrNameOcc r) + let ideclThing = Just (IEVar $ occNameString $ rdrNameOcc r), + Just ideclNameString <- + [moduleNameString . GHC.moduleName <$> nameModule_maybe name] ] where p name = nameModule_maybe name /= Just ms_mod @@ -178,8 +179,8 @@ provider state plId (CodeActionParams _ _ (TextDocumentIdentifier uri) range ca) ++ [ r | TyClGroup {group_tyclds} <- hs_tyclds, L l g <- group_tyclds, - r <- suggestTypeRewrites uri ms_mod g, - pos `isInsideSrcSpan` l + pos `isInsideSrcSpan` l, + r <- suggestTypeRewrites uri ms_mod g ] @@ -235,7 +236,6 @@ suggestBindRewrites originatingFile pos ms_mod FunBind {fun_id = L l' rdrName} description = "Fold " <> pprNameText <> describeRestriction restrictToOriginatingFile in (description, CodeActionRefactorExtract, RunRetrieParams {..}) in [unfoldRewrite False, unfoldRewrite True, foldRewrite False, foldRewrite True] - where suggestBindRewrites _ _ _ _ = [] describeRestriction :: IsString p => Bool -> p @@ -409,9 +409,7 @@ callRetrie state session rewrites origin restrictToOriginatingFile = do -- TODO add the imports to the resulting edits (_user, ast, change@(Change _replacements _imports)) <- lift $ runRetrie fixityEnv retrie cpp - case ast of - _ -> - return $ asTextEdits change + return $ asTextEdits change let (errors :: [CallRetrieError], replacements) = partitionEithers results editParams :: WorkspaceEdit @@ -485,7 +483,7 @@ handleMaybe :: Monad m => e -> Maybe b -> ExceptT e m b handleMaybe msg = maybe (throwE msg) return handleMaybeM :: Monad m => e -> m (Maybe b) -> ExceptT e m b -handleMaybeM msg act = maybe (throwE msg) return =<< lift act +handleMaybeM msg act = maybeM (throwE msg) return $ lift act response :: Monad m => ExceptT String m a -> m (Either ResponseError a) response = diff --git a/plugins/hls-splice-plugin/hls-splice-plugin.cabal b/plugins/hls-splice-plugin/hls-splice-plugin.cabal index 407b4ce5066..bb5c4ee8206 100644 --- a/plugins/hls-splice-plugin/hls-splice-plugin.cabal +++ b/plugins/hls-splice-plugin/hls-splice-plugin.cabal @@ -18,6 +18,7 @@ library build-depends: aeson , base >=4.12 && <5 , containers + , extra , foldl , lsp , hls-plugin-api diff --git a/plugins/hls-splice-plugin/src/Ide/Plugin/Splice.hs b/plugins/hls-splice-plugin/src/Ide/Plugin/Splice.hs index f5d47ad9d50..577975c4084 100644 --- a/plugins/hls-splice-plugin/src/Ide/Plugin/Splice.hs +++ b/plugins/hls-splice-plugin/src/Ide/Plugin/Splice.hs @@ -25,6 +25,7 @@ import Control.Arrow import qualified Control.Foldl as L import Control.Lens (ix, view, (%~), (<&>), (^.)) import Control.Monad +import Control.Monad.Extra (eitherM) import qualified Control.Monad.Fail as Fail import Control.Monad.Trans.Class import Control.Monad.Trans.Except @@ -324,8 +325,8 @@ manualCalcEdit clientCapabilities reportEditor ran ps hscEnv typechkd srcSpan _e graftDeclsWithM (RealSrcSpan srcSpan) $ \case (L _spn (SpliceD _ (SpliceDecl _ (L _ spl) _))) -> do eExpr <- - either (fail . show) pure - =<< lift + eitherM (fail . show) pure + $ lift ( lift $ gtry @_ @SomeException $ (fst <$> rnTopSpliceDecls spl) @@ -337,8 +338,8 @@ manualCalcEdit clientCapabilities reportEditor ran ps hscEnv typechkd srcSpan _e graftWithM (RealSrcSpan srcSpan) $ \case (L _spn (matchSplice astP -> Just spl)) -> do eExpr <- - either (fail . show) pure - =<< lift + eitherM (fail . show) pure + $ lift ( lift $ gtry @_ @SomeException $ (fst <$> expandSplice astP spl) diff --git a/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic.hs b/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic.hs index 74bba3f52c9..9832f7df642 100644 --- a/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic.hs +++ b/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic.hs @@ -27,6 +27,7 @@ import Data.Functor ((<&>)) import Data.Generics.Aliases (mkQ) import Data.Generics.Schemes (everything) import Data.List +import Data.List.Extra (enumerate) import Data.Map (Map) import qualified Data.Map as M import Data.Maybe @@ -75,7 +76,7 @@ descriptor plId = (defaultPluginDescriptor plId) (tcCommandId tc) (tacticDesc $ tcCommandName tc) (tacticCmd $ commandTactic tc)) - [minBound .. maxBound] + (enumerate :: [TacticCommand]) , pluginHandlers = mkPluginHandler STextDocumentCodeAction codeActionProvider } @@ -173,7 +174,7 @@ codeActionProvider state plId (CodeActionParams _ _ (TextDocumentIdentifier uri) (_, jdg, _, dflags) <- judgementForHole state nfp range actions <- lift $ -- This foldMap is over the function monoid. - foldMap commandProvider [minBound .. maxBound] + foldMap commandProvider (enumerate :: [TacticCommand]) dflags plId uri @@ -207,9 +208,9 @@ provide tc name _ plId uri range _ = do -- predicate holds for the goal. requireExtension :: Extension -> TacticProvider -> TacticProvider requireExtension ext tp dflags plId uri range jdg = - case xopt ext dflags of - True -> tp dflags plId uri range jdg - False -> pure [] + if xopt ext dflags + then tp dflags plId uri range jdg + else pure [] ------------------------------------------------------------------------------ @@ -217,9 +218,9 @@ requireExtension ext tp dflags plId uri range jdg = -- predicate holds for the goal. filterGoalType :: (Type -> Bool) -> TacticProvider -> TacticProvider filterGoalType p tp dflags plId uri range jdg = - case p $ unCType $ jGoal jdg of - True -> tp dflags plId uri range jdg - False -> pure [] + if p $ unCType $ jGoal jdg + then tp dflags plId uri range jdg + else pure [] ------------------------------------------------------------------------------ @@ -234,9 +235,9 @@ filterBindingType p tp dflags plId uri range jdg = g = jGoal jdg in fmap join $ for (unHypothesis hy) $ \hi -> let ty = unCType $ hi_type hi - in case p (unCType g) ty of - True -> tp (hi_name hi) ty dflags plId uri range jdg - False -> pure [] + in if p (unCType g) ty + then tp (hi_name hi) ty dflags plId uri range jdg + else pure [] data TacticParams = TacticParams diff --git a/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/CodeGen.hs b/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/CodeGen.hs index d84e2b7e43e..3877eba920a 100644 --- a/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/CodeGen.hs +++ b/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/CodeGen.hs @@ -1,7 +1,6 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE TupleSections #-} {-# LANGUAGE TypeApplications #-} -{-# LANGUAGE ViewPatterns #-} module Ide.Plugin.Tactic.CodeGen ( module Ide.Plugin.Tactic.CodeGen @@ -202,4 +201,3 @@ buildDataCon jdg dc tyapps = do pure . (rose (show dc) $ pure tr,) $ mkCon dc sgs - diff --git a/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/Context.hs b/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/Context.hs index ad5f937f6f4..8878fd3b8b4 100644 --- a/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/Context.hs +++ b/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/Context.hs @@ -22,6 +22,9 @@ import TcType (substTy, tcSplitSigmaTy) import Unify (tcUnifyTy) +{- HLINT ignore mkContext "Redundant fmap" -} +{- HLINT ignore mkContext "Use <=<" -} + mkContext :: [(OccName, CType)] -> TcGblEnv -> Context mkContext locals tcg = Context { ctxDefiningFuncs = locals @@ -33,6 +36,9 @@ mkContext locals tcg = Context } + +{- HLINT ignore contextMethodHypothesis "Redundant fmap" -} + ------------------------------------------------------------------------------ -- | Find all of the class methods that exist from the givens in the context. contextMethodHypothesis :: Context -> Hypothesis CType diff --git a/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/GHC.hs b/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/GHC.hs index e7c473e4718..5e4021b8bb4 100644 --- a/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/GHC.hs +++ b/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/GHC.hs @@ -7,7 +7,7 @@ module Ide.Plugin.Tactic.GHC where import Control.Monad.State import qualified Data.Map as M -import Data.Maybe (isJust) +import Data.Maybe (isJust, fromMaybe) import Data.Traversable import DataCon import Development.IDE.GHC.Compat @@ -81,11 +81,8 @@ freshTyvars t = do pure (tv, setTyVarUnique tv uniq) pure $ everywhere - (mkT $ \tv -> - case M.lookup tv reps of - Just tv' -> tv' - Nothing -> tv - ) t + (mkT $ \tv -> fromMaybe tv $ M.lookup tv reps) + t ------------------------------------------------------------------------------ diff --git a/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/Judgements.hs b/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/Judgements.hs index 06d070548d9..7e1dcbb092c 100644 --- a/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/Judgements.hs +++ b/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/Judgements.hs @@ -89,6 +89,8 @@ withNewGoal :: a -> Judgement' a -> Judgement' a withNewGoal t = field @"_jGoal" .~ t +{- HLINT ignore introducing "Use zipFrom" -} + ------------------------------------------------------------------------------ -- | Helper function for implementing functions which introduce new hypotheses. introducing @@ -132,9 +134,9 @@ hasPositionalAncestry -- otherwise nothing hasPositionalAncestry ancestors jdg name | not $ null ancestors - = case any (== name) ancestors of - True -> Just True - False -> + = if name `elem` ancestors + then Just True + else case M.lookup name $ jAncestryMap jdg of Just ancestry -> bool Nothing (Just False) $ any (flip S.member ancestry) ancestors @@ -154,9 +156,7 @@ filterAncestry ancestry reason jdg = disallowing reason (M.keys $ M.filterWithKey go $ hyByName $ jHypothesis jdg) jdg where go name _ - = not - . isJust - $ hasPositionalAncestry ancestry jdg name + = isNothing $ hasPositionalAncestry ancestry jdg name ------------------------------------------------------------------------------ @@ -218,6 +218,8 @@ filterSameTypeFromOtherPositions dcon pos jdg = in disallowing Shadowed (M.keys to_remove) jdg +{- HLINT ignore getAncestry "Replace case with maybe" -} + ------------------------------------------------------------------------------ -- | Return the ancestry of a 'PatVal', or 'mempty' otherwise. getAncestry :: Judgement' a -> OccName -> Set OccName @@ -229,7 +231,7 @@ getAncestry jdg name = jAncestryMap :: Judgement' a -> Map OccName (Set OccName) jAncestryMap jdg = - flip M.map (jPatHypothesis jdg) pv_ancestry + M.map pv_ancestry (jPatHypothesis jdg) ------------------------------------------------------------------------------ @@ -271,9 +273,9 @@ introducingPat scrutinee dc ns jdg disallowing :: DisallowReason -> [OccName] -> Judgement' a -> Judgement' a disallowing reason (S.fromList -> ns) = field @"_jHypothesis" %~ (\z -> Hypothesis . flip fmap (unHypothesis z) $ \hi -> - case S.member (hi_name hi) ns of - True -> overProvenance (DisallowedPrv reason) hi - False -> hi + if hi_name hi `S.member` ns + then overProvenance (DisallowedPrv reason) hi + else hi ) diff --git a/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/KnownStrategies/QuickCheck.hs b/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/KnownStrategies/QuickCheck.hs index 7c595a0b570..f62d36d67ff 100644 --- a/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/KnownStrategies/QuickCheck.hs +++ b/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/KnownStrategies/QuickCheck.hs @@ -100,11 +100,11 @@ doesTypeContain recursive_tc = mkArbitraryCall :: TyCon -> Integer -> Type -> HsExpr GhcPs mkArbitraryCall recursive_tc n ty = let arbitrary = mkFunc "arbitrary" - in case doesTypeContain recursive_tc ty of - True -> + in if doesTypeContain recursive_tc ty + then mkFunc "scale" @@ bool (mkFunc "flip" @@ mkFunc "div" @@ int n) (mkFunc "subtract" @@ int 1) (n == 1) @@ arbitrary - False -> arbitrary + else arbitrary diff --git a/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/Naming.hs b/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/Naming.hs index fbc72dd7bee..a279f4550ab 100644 --- a/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/Naming.hs +++ b/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/Naming.hs @@ -71,9 +71,9 @@ mkGoodName -> OccName mkGoodName in_scope t = let tn = mkTyName t - in mkVarOcc $ case S.member (mkVarOcc tn) in_scope of - True -> tn ++ show (length in_scope) - False -> tn + in mkVarOcc $ if S.member (mkVarOcc tn) in_scope + then tn ++ show (length in_scope) + else tn ------------------------------------------------------------------------------ diff --git a/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/Simplify.hs b/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/Simplify.hs index c125d508764..417e17daa81 100644 --- a/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/Simplify.hs +++ b/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/Simplify.hs @@ -41,8 +41,7 @@ pattern Lambda pats body <- -- | Simlify an expression. simplify :: LHsExpr GhcPs -> LHsExpr GhcPs simplify - = head - . drop 3 -- Do three passes; this should be good enough for the limited + = (!! 3) -- Do three passes; this should be good enough for the limited -- amount of gas we give to auto . iterate (everywhere $ foldEndo [ simplifyEtaReduce @@ -78,7 +77,7 @@ simplifyEtaReduce = mkT $ \case (HsVar _ (L _ a)) | pat == a -> var "id" Lambda - (unsnoc -> Just (pats, (VarPat _ (L _ pat)))) + (unsnoc -> Just (pats, VarPat _ (L _ pat))) (HsApp _ (L _ f) (L _ (HsVar _ (L _ a)))) | pat == a -- We can only perform this simplifiation if @pat@ is otherwise unused. @@ -93,8 +92,8 @@ simplifyEtaReduce = mkT $ \case simplifyCompose :: GenericT simplifyCompose = mkT $ \case Lambda - (unsnoc -> Just (pats, (VarPat _ (L _ pat)))) - (unroll -> (fs@(_:_), (HsVar _ (L _ a)))) + (unsnoc -> Just (pats, VarPat _ (L _ pat))) + (unroll -> (fs@(_:_), HsVar _ (L _ a))) | pat == a -- We can only perform this simplifiation if @pat@ is otherwise unused. , not (containsHsVar pat fs) -> @@ -119,4 +118,3 @@ unroll (HsApp _ (L _ f) (L _ a)) = let (fs, r) = unroll a in (f : fs, r) unroll x = ([], x) - diff --git a/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/Tactics.hs b/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/Tactics.hs index 44c53b3d951..afa1164785f 100644 --- a/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/Tactics.hs +++ b/plugins/hls-tactics-plugin/src/Ide/Plugin/Tactic/Tactics.hs @@ -100,16 +100,16 @@ destructAuto :: HyInfo CType -> TacticsM () destructAuto hi = requireConcreteHole $ tracing "destruct(auto)" $ do jdg <- goal let subtactic = rule $ destruct' (const subgoal) hi - case isPatternMatch $ hi_provenance hi of - True -> + if isPatternMatch $ hi_provenance hi + then pruning subtactic $ \jdgs -> let getHyTypes = S.fromList . fmap hi_type . unHypothesis . jHypothesis new_hy = foldMap getHyTypes jdgs old_hy = getHyTypes jdg - in case S.null $ new_hy S.\\ old_hy of - True -> Just $ UnhelpfulDestruct $ hi_name hi - False -> Nothing - False -> subtactic + in if S.null $ new_hy S.\\ old_hy + then Just $ UnhelpfulDestruct $ hi_name hi + else Nothing + else subtactic ------------------------------------------------------------------------------ @@ -196,9 +196,9 @@ splitAuto = requireConcreteHole $ tracing "split(auto)" $ do Nothing -> throwError $ GoalMismatch "split" g Just (tc, _) -> do let dcs = tyConDataCons tc - case isSplitWhitelisted jdg of - True -> choice $ fmap splitDataCon dcs - False -> do + if isSplitWhitelisted jdg + then choice $ fmap splitDataCon dcs + else do choice $ flip fmap dcs $ \dc -> requireNewHoles $ splitDataCon dc @@ -210,9 +210,9 @@ requireNewHoles :: TacticsM () -> TacticsM () requireNewHoles m = do jdg <- goal pruning m $ \jdgs -> - case null jdgs || any (/= jGoal jdg) (fmap jGoal jdgs) of - True -> Nothing - False -> Just NoProgress + if null jdgs || any (/= jGoal jdg) (fmap jGoal jdgs) + then Nothing + else Just NoProgress ------------------------------------------------------------------------------ @@ -223,9 +223,9 @@ splitDataCon dc = let g = jGoal jdg case splitTyConApp_maybe $ unCType g of Just (tc, apps) -> do - case elem dc $ tyConDataCons tc of - True -> buildDataCon (unwhitelistingSplit jdg) dc apps - False -> throwError $ IncorrectDataCon dc + if dc `elem` tyConDataCons tc + then buildDataCon (unwhitelistingSplit jdg) dc apps + else throwError $ IncorrectDataCon dc Nothing -> throwError $ GoalMismatch "splitDataCon" g @@ -278,4 +278,3 @@ overAlgebraicTerms = allNames :: Judgement -> Set OccName allNames = hyNamesInScope . jHypothesis - diff --git a/plugins/hls-tactics-plugin/test/AutoTupleSpec.hs b/plugins/hls-tactics-plugin/test/AutoTupleSpec.hs index d1e9a6ce5ff..e4315449258 100644 --- a/plugins/hls-tactics-plugin/test/AutoTupleSpec.hs +++ b/plugins/hls-tactics-plugin/test/AutoTupleSpec.hs @@ -3,7 +3,6 @@ module AutoTupleSpec where import Data.Either (isRight) -import qualified Data.Map as M import Ide.Plugin.Tactic.Debug import Ide.Plugin.Tactic.Judgements (mkFirstJudgement) import Ide.Plugin.Tactic.Machinery @@ -52,6 +51,4 @@ randomGroups :: [a] -> Gen [[a]] randomGroups [] = pure [] randomGroups as = do n <- choose (1, length as) - (:) <$> pure (take n as) - <*> randomGroups (drop n as) - + (take n as:) <$> randomGroups (drop n as) diff --git a/src/Ide/Main.hs b/src/Ide/Main.hs index ee365768433..f955db33e86 100644 --- a/src/Ide/Main.hs +++ b/src/Ide/Main.hs @@ -5,10 +5,7 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TupleSections #-} {-# LANGUAGE TypeFamilies #-} -{-# LANGUAGE ViewPatterns #-} -{-# LANGUAGE NamedFieldPuns #-} module Ide.Main(defaultMain, runLspMode) where diff --git a/stack.yaml b/stack.yaml index 51e7b86da10..8ac168836b3 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,4 +1,4 @@ -resolver: lts-14.27 # Last 8.6.5 +resolver: nightly-2020-12-09 packages: - . @@ -18,79 +18,37 @@ packages: ghc-options: "$everything": -haddock - - extra-deps: - - aeson-1.5.2.0 - apply-refact-0.9.0.0 - - ansi-terminal-0.10.3 - - base-compat-0.10.5 - brittany-0.13.1.0 - - butcher-1.3.3.1 - Cabal-3.0.2.0 - - cabal-plan-0.6.2.0 - clock-0.7.2 - - Diff-0.4.0 + - data-tree-print-0.1.0.2@rev:2 - floskell-0.10.4 - fourmolu-0.3.0.0 - - fuzzy-0.1.0.0 - - ghc-check-0.5.0.1 - - ghc-events-0.13.0 - ghc-exactprint-0.6.3.4 - ghc-lib-8.10.3.20201220 - ghc-lib-parser-8.10.3.20201220 - - ghc-lib-parser-ex-8.10.0.17 - - ghc-source-gen-0.4.0.0 - - ghc-trace-events-0.1.2.1 - - haddock-api-2.22.0@rev:1 - - haddock-library-1.8.0 - - hashable-1.3.0.0 + - lsp-1.1.0.0 + - lsp-types-1.1.0.0 + - lsp-test-0.13.0.0 - heapsize-0.3.0 - - hie-bios-0.7.1 - - hlint-3.2.3 - - HsYAML-0.2.1.0@rev:1 - - HsYAML-aeson-0.2.0.0@rev:2 - implicit-hie-cradle-0.3.0.2 - implicit-hie-0.1.2.5 - - indexed-profunctors-0.1 - - lens-4.18 - - megaparsec-9.0.1 - monad-dijkstra-0.1.1.2 - - opentelemetry-0.6.1 - - opentelemetry-extra-0.6.1 - - optics-core-0.2 - - optparse-applicative-0.15.1.0 - - ormolu-0.1.4.1 - - parser-combinators-1.2.1 - - primitive-0.7.1.0 - refinery-0.3.0.0 - - regex-base-0.94.0.0 - - regex-pcre-builtin-0.95.1.1.8.43 - - regex-tdfa-1.3.1.0 - retrie-0.1.1.1 - - semialign-1.1 - stylish-haskell-0.12.2.0 - - tasty-rerun-1.1.17 + - semigroups-0.18.5 - temporary-1.2.1.1 - - these-1.1.1.1 - - type-equality-1 - - topograph-1 - - uniplate-1.6.13 - - with-utf8-1.0.2.1@sha256:95c02fffa643ddbeb092359802a512007c3e644cd509809f4716ad54592c437b,3057 - - th-env-0.1.0.2@sha256:d8f1f37f42a8f1a22404d7d0579528af18f5dac7232cca6bdbd5117c115a0ad5,1370 - bytestring-encoding-0.1.0.0@sha256:460b49779fbf0112e8e2f1753c1ed9131eb18827600c298f4d6bb51c4e8c1c0d,1727 - hiedb-0.3.0.1 - - extra-1.7.9@sha256:f1dec740f0f2025790c540732bfd52c556ec55bde4f5dfd7cf18e22bd44ff3d0,2683 - - lsp-1.1.0.0 - - lsp-types-1.1.0.0 - - lsp-test-0.13.0.0 - dependent-map-0.4.0.0@sha256:ca2b131046f4340a1c35d138c5a003fe4a5be96b14efc26291ed35fd08c62221,1657 - dependent-sum-0.7.1.0@sha256:5599aa89637db434431b1dd3fa7c34bc3d565ee44f0519bfbc877be1927c2531,2068 - dependent-sum-template-0.1.0.3@sha256:0bbbacdfbd3abf2a15aaf0cf2c27e5bdd159b519441fec39e1e6f2f54424adde,1682 - constraints-extras-0.3.0.2@sha256:013b8d0392582c6ca068e226718a4fe8be8e22321cc0634f6115505bf377ad26,1853 - some-1.0.1@sha256:26e5bab7276f48b25ea8660d3fd1166c0f20fd497dac879a40f408e23211f93e,2055 - unliftio-core-0.2.0.1@sha256:9b3e44ea9aacacbfc35b3b54015af450091916ac3618a41868ebf6546977659a,1082 - - resourcet-1.2.3 configure-options: ghcide: @@ -106,8 +64,6 @@ flags: retrie: BuildExecutable: false -# allow-newer: true - nix: packages: [icu libcxx zlib] diff --git a/test/functional/Progress.hs b/test/functional/Progress.hs index 676e4dc664b..9df8de0fa62 100644 --- a/test/functional/Progress.hs +++ b/test/functional/Progress.hs @@ -3,7 +3,6 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE DataKinds #-} -{-# LANGUAGE TypeOperators #-} {-# LANGUAGE GADTs #-} module Progress (tests) where @@ -106,9 +105,9 @@ expectProgressReports xs = expectProgressReports' [] xs EndM msg -> do liftIO $ token msg `expectElem` tokens expectProgressReports' (delete (token msg) tokens) expectedTitles - title msg = msg ^. L.value ^. L.title + title msg = msg ^. L.value . L.title token msg = msg ^. L.token - create = CreateM . view L.params <$> (message SWindowWorkDoneProgressCreate) + create = CreateM . view L.params <$> message SWindowWorkDoneProgressCreate begin = BeginM <$> satisfyMaybe (\case FromServerMess SProgress (NotificationMessage _ _ (ProgressParams t (Begin x))) -> Just (ProgressParams t x) _ -> Nothing) diff --git a/test/functional/Reference.hs b/test/functional/Reference.hs index c4718e7e350..dabfa4a9d14 100644 --- a/test/functional/Reference.hs +++ b/test/functional/Reference.hs @@ -25,7 +25,7 @@ tests = testGroup "references" [ , mkRange 4 14 4 17 , mkRange 4 0 4 3 , mkRange 2 6 2 9 - ] `isInfixOf` (coerce refs) @? "Contains references" + ] `isInfixOf` coerce refs @? "Contains references" -- TODO: Respect withDeclaration parameter -- ignoreTestBecause "Broken" $ testCase "works without definitions" $ runSession hlsCommand fullCaps "test/testdata" $ do -- doc <- openDoc "References.hs" "haskell" diff --git a/test/functional/Tactic.hs b/test/functional/Tactic.hs index c48bdc24111..6bac33728f0 100644 --- a/test/functional/Tactic.hs +++ b/test/functional/Tactic.hs @@ -150,7 +150,7 @@ mkTest name fp line col ts = for_ ts $ \(f, tc, var) -> do let title = tacticTitle tc var liftIO $ - f (elem title titles) + f (title `elem` titles) @? ("Expected a code action with title " <> T.unpack title) diff --git a/test/utils/Test/Hls/Util.hs b/test/utils/Test/Hls/Util.hs index b3b4296f3b4..0b64ea73380 100644 --- a/test/utils/Test/Hls/Util.hs +++ b/test/utils/Test/Hls/Util.hs @@ -173,6 +173,7 @@ logFilePath = "hls-" ++ show ghcVersion ++ ".log" -- on PATH. Cabal seems to respond to @build-tool-depends@ specifically while -- stack just puts all project executables on PATH. hlsCommand :: String +{-# NOINLINE hlsCommand #-} hlsCommand = unsafePerformIO $ do testExe <- fromMaybe "haskell-language-server" <$> lookupEnv "HLS_TEST_EXE" pure $ testExe ++ " --lsp -d -j2 -l test-logs/" ++ logFilePath diff --git a/test/wrapper/Main.hs b/test/wrapper/Main.hs index 06aef44d258..6a8c19be38f 100644 --- a/test/wrapper/Main.hs +++ b/test/wrapper/Main.hs @@ -1,5 +1,4 @@ -import Data.Char -import Data.List +import Data.List.Extra (trimEnd) import Data.Maybe import Test.Hls.Util import Test.Tasty @@ -23,7 +22,7 @@ projectGhcVersionTests = testGroup "--project-ghc-version" , testCase "stack with ghc 8.8.3" $ testDir "test/wrapper/testdata/stack-8.8.3" "8.8.3" , testCase "cabal with global ghc" $ do - ghcVer <- trim <$> readProcess "ghc" ["--numeric-version"] "" + ghcVer <- trimEnd <$> readProcess "ghc" ["--numeric-version"] "" testDir "test/wrapper/testdata/cabal-cur-ver" ghcVer ] @@ -32,8 +31,5 @@ testDir dir expectedVer = withCurrentDirectoryInTmp dir $ do testExe <- fromMaybe "haskell-language-server-wrapper" <$> lookupEnv "HLS_WRAPPER_TEST_EXE" - actualVer <- trim <$> readProcess testExe ["--project-ghc-version"] "" + actualVer <- trimEnd <$> readProcess testExe ["--project-ghc-version"] "" actualVer @?= expectedVer - -trim :: String -> String -trim = dropWhileEnd isSpace