Skip to content

Commit 9f4ec33

Browse files
committed
ghcide: m refactors
1 parent 88de59c commit 9f4ec33

File tree

4 files changed

+14
-15
lines changed

4 files changed

+14
-15
lines changed

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

Lines changed: 2 additions & 1 deletion
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
@@ -996,6 +996,7 @@ getDocsBatch
996996
:: HscEnv
997997
-> Module -- ^ a moudle where the names are in scope
998998
-> [Name]
999+
-- 2021-11-18: NOTE: Map Int would become IntMap if next GHCs.
9991000
-> IO (Either ErrorMessages (Map.Map Name (Either GetDocsFailure (Maybe HsDocString, Maybe (Map.Map Int HsDocString)))))
10001001
-- ^ Return a 'Map' of 'Name's to 'Either' (no docs messages) (general doc body & arg docs)
10011002
getDocsBatch hsc_env _mod _names = do

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -574,9 +574,9 @@ getBindingsRule :: Rules ()
574574
getBindingsRule =
575575
define $ \GetBindings f -> do
576576
HAR{hieKind=kind, refMap=rm} <- use_ GetHieAst f
577-
case kind of
578-
HieFresh -> pure ([], Just $ bindings rm)
579-
HieFromDisk _ -> pure ([], Nothing)
577+
pure . (mempty,) $ case kind of
578+
HieFresh -> Just $ bindings rm
579+
HieFromDisk _ -> Nothing
580580

581581
getDocMapRule :: Rules ()
582582
getDocMapRule =
@@ -688,8 +688,7 @@ loadGhcSession ghcSessionDepsConfig = do
688688
afp <- liftIO $ makeAbsolute fp
689689
let nfp = toNormalizedFilePath' afp
690690
itExists <- getFileExists nfp
691-
when itExists $ void $ do
692-
use_ GetModificationTime nfp
691+
when itExists $ void $ use_ GetModificationTime nfp
693692
mapM_ addDependency deps
694693

695694
opts <- getIdeOptions
@@ -722,7 +721,7 @@ ghcSessionDepsDefinition
722721
ghcSessionDepsDefinition fullModSummary GhcSessionDepsConfig{..} env file = do
723722
let hsc = hscEnv env
724723

725-
mbdeps <- mapM(fmap artifactFilePath . snd) <$> use_ GetLocatedImports file
724+
mbdeps <- traverse (fmap artifactFilePath . snd) <$> use_ GetLocatedImports file
726725
case mbdeps of
727726
Nothing -> return Nothing
728727
Just deps -> do

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

Lines changed: 6 additions & 5 deletions
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

Lines changed: 1 addition & 3 deletions
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)