@@ -78,7 +78,6 @@ import System.FilePath
78
78
import System.IO.Error
79
79
import System.IO.Unsafe
80
80
81
-
82
81
data Log
83
82
= LogCouldNotIdentifyReverseDeps ! NormalizedFilePath
84
83
| LogTypeCheckingReverseDeps ! NormalizedFilePath ! (Maybe [NormalizedFilePath ])
@@ -147,6 +146,29 @@ getModificationTimeImpl missingFileDiags file = do
147
146
then return (Nothing , ([] , Nothing ))
148
147
else return (Nothing , ([diag], Nothing ))
149
148
149
+
150
+ getPhysicalModificationTimeRule :: Recorder (WithPriority Log ) -> Rules ()
151
+ getPhysicalModificationTimeRule recorder = defineEarlyCutoff (cmapWithPrio LogShake recorder) $ Rule $ \ GetPhysicalModificationTime file ->
152
+ getPhysicalModificationTimeImpl file
153
+
154
+ getPhysicalModificationTimeImpl
155
+ :: NormalizedFilePath
156
+ -> Action (Maybe BS. ByteString , ([FileDiagnostic ], Maybe FileVersion ))
157
+ getPhysicalModificationTimeImpl file = do
158
+ let file' = fromNormalizedFilePath file
159
+ let wrap time = (Just $ LBS. toStrict $ B. encode $ toRational time, ([] , Just $ ModificationTime time))
160
+
161
+ alwaysRerun
162
+
163
+ liftIO $ fmap wrap (getModTime file')
164
+ `catch` \ (e :: IOException ) -> do
165
+ let err | isDoesNotExistError e = " File does not exist: " ++ file'
166
+ | otherwise = " IO error while reading " ++ file' ++ " , " ++ displayException e
167
+ diag = ideErrorText file (T. pack err)
168
+ if isDoesNotExistError e
169
+ then return (Nothing , ([] , Nothing ))
170
+ else return (Nothing , ([diag], Nothing ))
171
+
150
172
-- | Interface files cannot be watched, since they live outside the workspace.
151
173
-- But interface files are private, in that only HLS writes them.
152
174
-- So we implement watching ourselves, and bypass the need for alwaysRerun.
@@ -170,7 +192,11 @@ resetFileStore ideState changes = mask $ \_ -> do
170
192
case c of
171
193
LSP. FileChangeType_Changed
172
194
-- already checked elsewhere | not $ HM.member nfp fois
173
- -> atomically $ deleteValue (shakeExtras ideState) GetModificationTime nfp
195
+ ->
196
+ atomically $ do
197
+ ks <- deleteValue (shakeExtras ideState) GetModificationTime nfp
198
+ vs <- deleteValue (shakeExtras ideState) GetPhysicalModificationTime nfp
199
+ pure $ ks ++ vs
174
200
_ -> pure []
175
201
176
202
@@ -233,6 +259,7 @@ getVersionedTextDoc doc = do
233
259
fileStoreRules :: Recorder (WithPriority Log ) -> (NormalizedFilePath -> Action Bool ) -> Rules ()
234
260
fileStoreRules recorder isWatched = do
235
261
getModificationTimeRule recorder
262
+ getPhysicalModificationTimeRule recorder
236
263
getFileContentsRule recorder
237
264
addWatchedFileRule recorder isWatched
238
265
0 commit comments