Skip to content

Commit 38463da

Browse files
committed
ghcide: m refactors
1 parent dbb4cd2 commit 38463da

File tree

4 files changed

+14
-15
lines changed

4 files changed

+14
-15
lines changed

ghcide/src/Development/IDE/Core/Compile.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ mergeEnvs :: HscEnv -> [ModSummary] -> [HomeModInfo] -> [HscEnv] -> IO HscEnv
694694
mergeEnvs env extraModSummaries extraMods envs = do
695695
prevFinderCache <- concatFC <$> mapM (readIORef . hsc_FC) envs
696696
let ims = map (Compat.installedModule (homeUnitId_ $ hsc_dflags env) . moduleName . ms_mod) extraModSummaries
697-
ifrs = zipWith (\ms -> InstalledFound (ms_location ms)) extraModSummaries ims
697+
ifrs = zipWith (InstalledFound . ms_location) extraModSummaries ims
698698
newFinderCache <- newIORef $
699699
foldl'
700700
(\fc (im, ifr) -> Compat.extendInstalledModuleEnv fc im ifr) prevFinderCache
@@ -992,6 +992,7 @@ getDocsBatch
992992
:: HscEnv
993993
-> Module -- ^ a moudle where the names are in scope
994994
-> [Name]
995+
-- 2021-11-18: NOTE: Map Int would become IntMap if next GHCs.
995996
-> IO (Either ErrorMessages (Map.Map Name (Either GetDocsFailure (Maybe HsDocString, Maybe (Map.Map Int HsDocString)))))
996997
-- ^ Return a 'Map' of 'Name's to 'Either' (no docs messages) (general doc body & arg docs)
997998
getDocsBatch hsc_env _mod _names = do

ghcide/src/Development/IDE/Core/Rules.hs

+5-6
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,9 @@ getBindingsRule :: Rules ()
553553
getBindingsRule =
554554
define $ \GetBindings f -> do
555555
HAR{hieKind=kind, refMap=rm} <- use_ GetHieAst f
556-
case kind of
557-
HieFresh -> pure ([], Just $ bindings rm)
558-
HieFromDisk _ -> pure ([], Nothing)
556+
pure . (mempty,) $ case kind of
557+
HieFresh -> Just $ bindings rm
558+
HieFromDisk _ -> Nothing
559559

560560
getDocMapRule :: Rules ()
561561
getDocMapRule =
@@ -667,8 +667,7 @@ loadGhcSession ghcSessionDepsConfig = do
667667
afp <- liftIO $ makeAbsolute fp
668668
let nfp = toNormalizedFilePath' afp
669669
itExists <- getFileExists nfp
670-
when itExists $ void $ do
671-
use_ GetModificationTime nfp
670+
when itExists $ void $ use_ GetModificationTime nfp
672671
mapM_ addDependency deps
673672

674673
opts <- getIdeOptions
@@ -702,7 +701,7 @@ ghcSessionDepsDefinition :: GhcSessionDepsConfig -> HscEnvEq -> NormalizedFilePa
702701
ghcSessionDepsDefinition GhcSessionDepsConfig{..} env file = do
703702
let hsc = hscEnv env
704703

705-
mbdeps <- mapM(fmap artifactFilePath . snd) <$> use_ GetLocatedImports file
704+
mbdeps <- traverse (fmap artifactFilePath . snd) <$> use_ GetLocatedImports file
706705
case mbdeps of
707706
Nothing -> return Nothing
708707
Just deps -> do

ghcide/src/Development/IDE/Spans/AtPoint.hs

+6-5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import Data.List.Extra (dropEnd1, nubOrd)
5454
import Data.Version (showVersion)
5555
import HieDb hiding (pointCommand)
5656
import System.Directory (doesFileExist)
57+
import Data.Bool (bool)
5758

5859
-- | Gives a Uri for the module, given the .hie file location and the the module info
5960
-- The Bool denotes if it is a boot module
@@ -63,13 +64,13 @@ type LookupModule m = FilePath -> ModuleName -> Unit -> Bool -> MaybeT m Uri
6364
newtype FOIReferences = FOIReferences (HM.HashMap NormalizedFilePath (HieAstResult, PositionMapping))
6465

6566
computeTypeReferences :: Foldable f => f (HieAST Type) -> M.Map Name [Span]
66-
computeTypeReferences = foldr (\ast m -> M.unionWith (++) (go ast) m) M.empty
67+
computeTypeReferences = foldr (\ast m -> M.unionWith (<>) (go ast) m) M.empty
6768
where
6869
go ast = M.unionsWith (++) (this : map go (nodeChildren ast))
6970
where
7071
this = M.fromListWith (++)
7172
$ map (, [nodeSpan ast])
72-
$ concatMap namesInType
73+
$ foldMap namesInType
7374
$ mapMaybe (\x -> guard (not $ all isOccurrence $ identInfo x) *> identType x)
7475
$ M.elems
7576
$ nodeIdentifiers $ nodeInfo ast
@@ -212,9 +213,9 @@ atPoint IdeOptions{} (HAR _ hf _ _ kind) (DKMap dm km) env pos = listToMaybe $ p
212213
-- | Get hover info for values/data
213214
hoverInfo ast = (Just range, prettyNames ++ pTypes)
214215
where
215-
pTypes
216-
| Prelude.length names == 1 = dropEnd1 $ map wrapHaskell prettyConcreteTypes
217-
| otherwise = map wrapHaskell prettyConcreteTypes
216+
pTypes =
217+
bool id dropEnd1 (Prelude.length names == 1)
218+
$ map wrapHaskell prettyConcreteTypes
218219

219220
range = realSrcSpanToRange $ nodeSpan ast
220221

ghcide/src/Development/IDE/Spans/Common.hs

+1-3
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,7 @@ spanDocToMarkdownForTest
9797
= haddockToMarkdown . H.toRegular . H._doc . H.parseParas Nothing
9898

9999
-- Simple (and a bit hacky) conversion from Haddock markup to Markdown
100-
haddockToMarkdown
101-
:: H.DocH String String -> String
102-
100+
haddockToMarkdown :: H.DocH String String -> String
103101
haddockToMarkdown H.DocEmpty
104102
= ""
105103
haddockToMarkdown (H.DocAppend d1 d2)

0 commit comments

Comments
 (0)