Skip to content

Commit 9a4e704

Browse files
committed
WIP Add InputPath type to rules
1 parent af47b30 commit 9a4e704

File tree

2 files changed

+59
-49
lines changed

2 files changed

+59
-49
lines changed

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ import Language.LSP.VFS
6969
import System.FilePath
7070
import System.IO.Error
7171
import System.IO.Unsafe
72+
import Development.IDE.Core.InputPath (InputPath (InputPath, unInputPath))
7273

7374

7475
data Log
@@ -88,16 +89,16 @@ instance Pretty Log where
8889
<+> pretty (fmap (fmap show) reverseDepPaths)
8990
LogShake msg -> pretty msg
9091

91-
addWatchedFileRule :: Recorder (WithPriority Log) -> (NormalizedFilePath -> Action Bool) -> Rules ()
92+
addWatchedFileRule :: Recorder (WithPriority Log) -> (InputPath i -> Action Bool) -> Rules ()
9293
addWatchedFileRule recorder isWatched = defineNoDiagnostics (cmapWithPrio LogShake recorder) $ \AddWatchedFile f -> do
9394
isAlreadyWatched <- isWatched f
94-
isWp <- isWorkspaceFile f
95+
isWp <- isWorkspaceFile $ unInputPath f
9596
if isAlreadyWatched then pure (Just True) else
9697
if not isWp then pure (Just False) else do
9798
ShakeExtras{lspEnv} <- getShakeExtras
9899
case lspEnv of
99100
Just env -> fmap Just $ liftIO $ LSP.runLspT env $
100-
registerFileWatches [fromNormalizedFilePath f]
101+
registerFileWatches [fromNormalizedFilePath (unInputPath f)]
101102
Nothing -> pure $ Just False
102103

103104

@@ -107,12 +108,12 @@ getModificationTimeRule recorder = defineEarlyCutoff (cmapWithPrio LogShake reco
107108

108109
getModificationTimeImpl
109110
:: Bool
110-
-> NormalizedFilePath
111+
-> InputPath i
111112
-> Action (Maybe BS.ByteString, ([FileDiagnostic], Maybe FileVersion))
112113
getModificationTimeImpl missingFileDiags file = do
113-
let file' = fromNormalizedFilePath file
114+
let file' = fromNormalizedFilePath $ unInputPath file
114115
let wrap time = (Just $ LBS.toStrict $ B.encode $ toRational time, ([], Just $ ModificationTime time))
115-
mbVf <- getVirtualFile file
116+
mbVf <- getVirtualFile $ unInputPath file
116117
case mbVf of
117118
Just (virtualFileVersion -> ver) -> do
118119
alwaysRerun
@@ -124,7 +125,7 @@ getModificationTimeImpl missingFileDiags file = do
124125
-- but also need a dependency on IsFileOfInterest to reinstall
125126
-- alwaysRerun when the file becomes VFS
126127
void (use_ IsFileOfInterest file)
127-
else if isInterface file
128+
else if isInterface (unInputPath file)
128129
then -- interface files are tracked specially using the closed world assumption
129130
pure ()
130131
else -- in all other cases we will need to freshly check the file system
@@ -134,7 +135,7 @@ getModificationTimeImpl missingFileDiags file = do
134135
`catch` \(e :: IOException) -> do
135136
let err | isDoesNotExistError e = "File does not exist: " ++ file'
136137
| otherwise = "IO error while reading " ++ file' ++ ", " ++ displayException e
137-
diag = ideErrorText file (T.pack err)
138+
diag = ideErrorText (unInputPath file) (T.pack err)
138139
if isDoesNotExistError e && not missingFileDiags
139140
then return (Nothing, ([], Nothing))
140141
else return (Nothing, ([diag], Nothing))
@@ -174,19 +175,19 @@ getFileContentsRule :: Recorder (WithPriority Log) -> Rules ()
174175
getFileContentsRule recorder = define (cmapWithPrio LogShake recorder) $ \GetFileContents file -> getFileContentsImpl file
175176

176177
getFileContentsImpl
177-
:: NormalizedFilePath
178+
:: InputPath i
178179
-> Action ([FileDiagnostic], Maybe (FileVersion, Maybe T.Text))
179180
getFileContentsImpl file = do
180181
-- need to depend on modification time to introduce a dependency with Cutoff
181182
time <- use_ GetModificationTime file
182183
res <- do
183-
mbVirtual <- getVirtualFile file
184+
mbVirtual <- getVirtualFile $ unInputPath file
184185
pure $ virtualFileText <$> mbVirtual
185186
pure ([], Just (time, res))
186187

187188
-- | Returns the modification time and the contents.
188189
-- For VFS paths, the modification time is the current time.
189-
getFileContents :: NormalizedFilePath -> Action (UTCTime, Maybe T.Text)
190+
getFileContents :: InputPath i -> Action (UTCTime, Maybe T.Text)
190191
getFileContents f = do
191192
(fv, txt) <- use_ GetFileContents f
192193
modTime <- case modificationTime fv of
@@ -196,11 +197,11 @@ getFileContents f = do
196197
liftIO $ case foi of
197198
IsFOI Modified{} -> getCurrentTime
198199
_ -> do
199-
posix <- getModTime $ fromNormalizedFilePath f
200+
posix <- getModTime $ fromNormalizedFilePath $ unInputPath f
200201
pure $ posixSecondsToUTCTime posix
201202
return (modTime, txt)
202203

203-
fileStoreRules :: Recorder (WithPriority Log) -> (NormalizedFilePath -> Action Bool) -> Rules ()
204+
fileStoreRules :: Recorder (WithPriority Log) -> (InputPath i -> Action Bool) -> Rules ()
204205
fileStoreRules recorder isWatched = do
205206
getModificationTimeRule recorder
206207
getFileContentsRule recorder
@@ -239,7 +240,7 @@ typecheckParentsAction recorder nfp = do
239240
Nothing -> logWith recorder Info $ LogCouldNotIdentifyReverseDeps nfp
240241
Just rs -> do
241242
logWith recorder Info $ LogTypeCheckingReverseDeps nfp revs
242-
void $ uses GetModIface rs
243+
void $ uses GetModIface (map InputPath rs)
243244

244245
-- | Note that some keys have been modified and restart the session
245246
-- Only valid if the virtual file system was initialised by LSP, as that

0 commit comments

Comments
 (0)