Skip to content

Commit

Permalink
Refactor - move GetFilesOfInterest type and use the appropriate define
Browse files Browse the repository at this point in the history
  • Loading branch information
pepeiborra committed May 8, 2021
1 parent 04ea534 commit fec01dd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
18 changes: 2 additions & 16 deletions ghcide/src/Development/IDE/Core/OfInterest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,13 @@ module Development.IDE.Core.OfInterest(
) where

import Control.Concurrent.Strict
import Control.DeepSeq
import Control.Exception
import Control.Monad
import Control.Monad.IO.Class
import Data.Binary
import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HashMap
import Data.Hashable
import qualified Data.Text as T
import Data.Typeable
import Development.IDE.Graph
import GHC.Generics

import Control.Monad.Trans.Class
import Control.Monad.Trans.Maybe
Expand All @@ -44,24 +39,15 @@ import Development.IDE.Types.Options
newtype OfInterestVar = OfInterestVar (Var (HashMap NormalizedFilePath FileOfInterestStatus))
instance IsIdeGlobal OfInterestVar

type instance RuleResult GetFilesOfInterest = HashMap NormalizedFilePath FileOfInterestStatus

data GetFilesOfInterest = GetFilesOfInterest
deriving (Eq, Show, Typeable, Generic)
instance Hashable GetFilesOfInterest
instance NFData GetFilesOfInterest
instance Binary GetFilesOfInterest


-- | The rule that initialises the files of interest state.
ofInterestRules :: Rules ()
ofInterestRules = do
addIdeGlobal . OfInterestVar =<< liftIO (newVar HashMap.empty)
defineEarlyCutoff $ RuleNoDiagnostics $ \GetFilesOfInterest _file -> assert (null $ fromNormalizedFilePath _file) $ do
defineEarlyCutOffNoFile $ \GetFilesOfInterest -> do
alwaysRerun
filesOfInterest <- getFilesOfInterestUntracked
let !cutoff = LBS.toStrict $ encode $ HashMap.toList filesOfInterest
pure (Just cutoff, Just filesOfInterest)
pure (cutoff, filesOfInterest)

-- | Get the files that are open in the IDE.
getFilesOfInterest :: Action (HashMap NormalizedFilePath FileOfInterestStatus)
Expand Down
9 changes: 9 additions & 0 deletions ghcide/src/Development/IDE/Core/RuleTypes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import HscTypes (HomeModInfo,
import qualified Data.Binary as B
import Data.ByteString (ByteString)
import qualified Data.ByteString.Lazy as LBS
import Data.HashMap.Strict (HashMap)
import Data.Text (Text)
import Data.Time
import Development.IDE.Import.FindImports (ArtifactsLocation)
Expand Down Expand Up @@ -353,6 +354,8 @@ type instance RuleResult GetModSummary = ModSummaryResult
-- | Generate a ModSummary with the timestamps and preprocessed content elided, for more successful early cutoff
type instance RuleResult GetModSummaryWithoutTimestamps = ModSummaryResult

type instance RuleResult GetFilesOfInterest = HashMap NormalizedFilePath FileOfInterestStatus

data GetParsedModule = GetParsedModule
deriving (Eq, Show, Typeable, Generic)
instance Hashable GetParsedModule
Expand Down Expand Up @@ -510,6 +513,12 @@ instance Hashable GhcSessionIO
instance NFData GhcSessionIO
instance Binary GhcSessionIO

data GetFilesOfInterest = GetFilesOfInterest
deriving (Eq, Show, Typeable, Generic)
instance Hashable GetFilesOfInterest
instance NFData GetFilesOfInterest
instance Binary GetFilesOfInterest

makeLensesWith
(lensRules & lensField .~ mappingNamer (pure . (++ "L")))
''Splices

0 comments on commit fec01dd

Please sign in to comment.