From 16d3deea4606fb6f404b9c0468d30dfe84630e54 Mon Sep 17 00:00:00 2001 From: Zubin Duggal Date: Fri, 12 Feb 2021 18:35:52 +0530 Subject: [PATCH] Index files on first open --- ghcide/src/Development/IDE/Core/FileStore.hs | 2 +- ghcide/src/Development/IDE/Core/RuleTypes.hs | 5 ++++- ghcide/src/Development/IDE/Core/Rules.hs | 2 +- ghcide/src/Development/IDE/LSP/Notifications.hs | 4 ++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ghcide/src/Development/IDE/Core/FileStore.hs b/ghcide/src/Development/IDE/Core/FileStore.hs index 2f87bd8d41..94333714e7 100644 --- a/ghcide/src/Development/IDE/Core/FileStore.hs +++ b/ghcide/src/Development/IDE/Core/FileStore.hs @@ -179,7 +179,7 @@ getFileContents f = do Nothing -> do foi <- use_ IsFileOfInterest f liftIO $ case foi of - IsFOI Modified -> getCurrentTime + IsFOI Modified{} -> getCurrentTime _ -> do (large,small) <- getModTime $ fromNormalizedFilePath f pure $ internalTimeToUTCTime large small diff --git a/ghcide/src/Development/IDE/Core/RuleTypes.hs b/ghcide/src/Development/IDE/Core/RuleTypes.hs index ddee675fab..2f7f817f8b 100644 --- a/ghcide/src/Development/IDE/Core/RuleTypes.hs +++ b/ghcide/src/Development/IDE/Core/RuleTypes.hs @@ -296,7 +296,10 @@ instance NFData GetFileContents instance Binary GetFileContents -data FileOfInterestStatus = OnDisk | Modified +data FileOfInterestStatus + = OnDisk + | Modified { firstOpen :: !Bool -- ^ was this file just opened + } deriving (Eq, Show, Typeable, Generic) instance Hashable FileOfInterestStatus instance NFData FileOfInterestStatus diff --git a/ghcide/src/Development/IDE/Core/Rules.hs b/ghcide/src/Development/IDE/Core/Rules.hs index ec2a28f7de..fdece3ae2f 100644 --- a/ghcide/src/Development/IDE/Core/Rules.hs +++ b/ghcide/src/Development/IDE/Core/Rules.hs @@ -593,7 +593,7 @@ getHieAstRuleDefinition f hsc tmr = do isFoi <- use_ IsFileOfInterest f diagsWrite <- case isFoi of - IsFOI Modified -> do + IsFOI Modified{firstOpen = False} -> do when (coerce $ ideTesting se) $ liftIO $ eventer se $ LSP.NotCustomServer $ LSP.NotificationMessage "2.0" (LSP.CustomServerMethod "ghcide/reference/ready") (toJSON $ fromNormalizedFilePath f) diff --git a/ghcide/src/Development/IDE/LSP/Notifications.hs b/ghcide/src/Development/IDE/LSP/Notifications.hs index deeb24e303..c464d0210b 100644 --- a/ghcide/src/Development/IDE/LSP/Notifications.hs +++ b/ghcide/src/Development/IDE/LSP/Notifications.hs @@ -47,7 +47,7 @@ setHandlersNotifications = PartialHandlers $ \WithMessage{..} x -> return x whenUriFile _uri $ \file -> do -- We don't know if the file actually exists, or if the contents match those on disk -- For example, vscode restores previously unsaved contents on open - modifyFilesOfInterest ide (M.insert file Modified) + modifyFilesOfInterest ide (M.insert file Modified{firstOpen=True}) setFileModified ide False file logInfo (ideLogger ide) $ "Opened text document: " <> getUri _uri @@ -55,7 +55,7 @@ setHandlersNotifications = PartialHandlers $ \WithMessage{..} x -> return x \_ ide (DidChangeTextDocumentParams identifier@VersionedTextDocumentIdentifier{_uri} changes) -> do updatePositionMapping ide identifier changes whenUriFile _uri $ \file -> do - modifyFilesOfInterest ide (M.insert file Modified) + modifyFilesOfInterest ide (M.insert file Modified{firstOpen=False}) setFileModified ide False file logInfo (ideLogger ide) $ "Modified text document: " <> getUri _uri