-
-
Notifications
You must be signed in to change notification settings - Fork 389
Track file versions accurately. #2735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
52c7f7a
cee793f
71da540
c0a52a6
cc6fc51
64f8380
036b303
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{-# LANGUAGE CPP #-} | ||
|
||
module Development.IDE.Core.FileUtils( | ||
getModTime, | ||
) where | ||
|
||
|
||
import Data.Time.Clock.POSIX | ||
#ifdef mingw32_HOST_OS | ||
import qualified System.Directory as Dir | ||
#else | ||
import System.Posix.Files (getFileStatus, | ||
modificationTimeHiRes) | ||
#endif | ||
|
||
-- Dir.getModificationTime is surprisingly slow since it performs | ||
-- a ton of conversions. Since we do not actually care about | ||
-- the format of the time, we can get away with something cheaper. | ||
-- For now, we only try to do this on Unix systems where it seems to get the | ||
-- time spent checking file modifications (which happens on every change) | ||
-- from > 0.5s to ~0.15s. | ||
-- We might also want to try speeding this up on Windows at some point. | ||
-- TODO leverage DidChangeWatchedFile lsp notifications on clients that | ||
-- support them, as done for GetFileExists | ||
getModTime :: FilePath -> IO POSIXTime | ||
getModTime f = | ||
#ifdef mingw32_HOST_OS | ||
utcTimeToPOSIXSeconds <$> Dir.getModificationTime f | ||
#else | ||
modificationTimeHiRes <$> getFileStatus f | ||
#endif |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -290,10 +290,12 @@ pattern GetModificationTime = GetModificationTime_ {missingFileDiagnostics=True} | |||||
-- | Get the modification time of a file. | ||||||
type instance RuleResult GetModificationTime = FileVersion | ||||||
|
||||||
-- | Either athe mtime from disk or an LSP version | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
-- LSP versions always compare as greater than on disk versions | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? Is that important? |
||||||
data FileVersion | ||||||
= VFSVersion !Int32 | ||||||
| ModificationTime !POSIXTime | ||||||
deriving (Show, Generic) | ||||||
= ModificationTime !POSIXTime | ||||||
| VFSVersion !Int32 | ||||||
deriving (Show, Generic, Eq, Ord) | ||||||
|
||||||
instance NFData FileVersion | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,6 +85,7 @@ import qualified Data.HashMap.Strict as HM | |
import qualified Data.HashSet as HashSet | ||
import Data.Hashable | ||
import Data.IORef | ||
import Control.Concurrent.STM.TVar | ||
import Data.IntMap.Strict (IntMap) | ||
import qualified Data.IntMap.Strict as IntMap | ||
import Data.List | ||
|
@@ -99,8 +100,7 @@ import Data.Tuple.Extra | |
import Development.IDE.Core.Compile | ||
import Development.IDE.Core.FileExists hiding (LogShake, Log) | ||
import Development.IDE.Core.FileStore (getFileContents, | ||
modificationTime, | ||
resetInterfaceStore) | ||
resetInterfaceStore, modificationTime) | ||
import Development.IDE.Core.IdeConfiguration | ||
import Development.IDE.Core.OfInterest hiding (LogShake, Log) | ||
import Development.IDE.Core.PositionMapping | ||
|
@@ -555,12 +555,11 @@ getHieAstsRule recorder = | |
persistentHieFileRule :: Recorder (WithPriority Log) -> Rules () | ||
persistentHieFileRule recorder = addPersistentRule GetHieAst $ \file -> runMaybeT $ do | ||
res <- readHieFileForSrcFromDisk recorder file | ||
vfs <- asks vfs | ||
(currentSource,ver) <- liftIO $ do | ||
mvf <- getVirtualFile vfs $ filePathToUri' file | ||
case mvf of | ||
Nothing -> (,Nothing) . T.decodeUtf8 <$> BS.readFile (fromNormalizedFilePath file) | ||
Just vf -> pure (Rope.toText $ _text vf, Just $ _lsp_version vf) | ||
vfsRef <- asks vfs | ||
vfsData <- liftIO $ vfsMap <$> readTVarIO vfsRef | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use the |
||
(currentSource, ver) <- liftIO $ case M.lookup (filePathToUri' file) vfsData of | ||
Nothing -> (,Nothing) . T.decodeUtf8 <$> BS.readFile (fromNormalizedFilePath file) | ||
Just vf -> pure (Rope.toText $ _text vf, Just $ _lsp_version vf) | ||
let refmap = Compat.generateReferencesMap . Compat.getAsts . Compat.hie_asts $ res | ||
del = deltaFromDiff (T.decodeUtf8 $ Compat.hie_hs_src res) currentSource | ||
pure (HAR (Compat.hie_module res) (Compat.hie_asts res) refmap mempty (HieFromDisk res),del,ver) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this TODO in the right place?