Skip to content

Commit 991f4bf

Browse files
committed
Add ReadOnly to FileOfInterestStatus
1 parent 432a277 commit 991f4bf

File tree

5 files changed

+34
-21
lines changed

5 files changed

+34
-21
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,19 +130,18 @@ scheduleGarbageCollection state = do
130130
-- Could be improved
131131
kick :: Action ()
132132
kick = do
133-
files <- HashMap.keys <$> getFilesOfInterestUntracked
133+
filesOfInterestMap <- getFilesOfInterestUntracked
134134
ShakeExtras{exportsMap, ideTesting = IdeTesting testing, lspEnv, progress} <- getShakeExtras
135135
let signal :: KnownSymbol s => Proxy s -> Action ()
136136
signal msg = when testing $ liftIO $
137137
mRunLspT lspEnv $
138138
LSP.sendNotification (LSP.SMethod_CustomMethod msg) $
139139
toJSON $ map fromNormalizedFilePath files
140-
isProjectFile :: NormalizedFilePath -> Bool
141-
isProjectFile file = case getSourceFileOrigin file of
142-
FromProject -> True
143-
FromDependency -> False
140+
files :: [NormalizedFilePath]
141+
files = HashMap.keys filesOfInterestMap
144142
projectFiles :: [NormalizedFilePath]
145-
projectFiles = filter isProjectFile files
143+
projectFiles = HashMap.keys
144+
$ HashMap.filter (/= ReadOnly) filesOfInterestMap
146145

147146
signal (Proxy @"kick/start")
148147
liftIO $ progressUpdate progress KickStarted

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ instance Hashable GetFileExists
340340

341341
data FileOfInterestStatus
342342
= OnDisk
343+
| ReadOnly
343344
| Modified { firstOpen :: !Bool -- ^ was this file just opened
344345
}
345346
deriving (Eq, Show, Typeable, Generic)

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -569,19 +569,20 @@ reportImportCyclesRule recorder =
569569

570570
getHieAstsRule :: Recorder (WithPriority Log) -> Rules ()
571571
getHieAstsRule recorder =
572-
define (cmapWithPrio LogShake recorder) $ \GetHieAst f ->
573-
case getSourceFileOrigin f of
574-
FromProject -> do
575-
tmr <- use_ TypeCheck f
576-
hsc <- hscEnv <$> use_ GhcSessionDeps f
577-
getHieAstRuleDefinition f hsc tmr
578-
FromDependency -> do
572+
define (cmapWithPrio LogShake recorder) $ \GetHieAst f -> do
573+
isFoi <- use_ IsFileOfInterest f
574+
case isFoi of
575+
IsFOI ReadOnly -> do
579576
se <- getShakeExtras
580577
mHieFile <- liftIO
581578
$ runIdeAction "GetHieAst" se
582579
$ runMaybeT
583580
$ readHieFileForSrcFromDisk recorder f
584581
pure ([], makeHieAstResult <$> mHieFile)
582+
_ -> do
583+
tmr <- use_ TypeCheck f
584+
hsc <- hscEnv <$> use_ GhcSessionDeps f
585+
getHieAstRuleDefinition f isFoi hsc tmr
585586
where
586587
makeHieAstResult :: Compat.HieFile -> HieAstResult
587588
makeHieAstResult hieFile =
@@ -604,12 +605,11 @@ persistentHieFileRule recorder = addPersistentRule GetHieAst $ \file -> runMaybe
604605
del = deltaFromDiff (T.decodeUtf8 $ Compat.hie_hs_src res) currentSource
605606
pure (HAR (Compat.hie_module res) (Compat.hie_asts res) refmap mempty (HieFromDisk res),del,ver)
606607

607-
getHieAstRuleDefinition :: NormalizedFilePath -> HscEnv -> TcModuleResult -> Action (IdeResult HieAstResult)
608-
getHieAstRuleDefinition f hsc tmr = do
608+
getHieAstRuleDefinition :: NormalizedFilePath -> IsFileOfInterestResult -> HscEnv -> TcModuleResult -> Action (IdeResult HieAstResult)
609+
getHieAstRuleDefinition f isFoi hsc tmr = do
609610
(diags, masts) <- liftIO $ generateHieAsts hsc tmr
610611
se <- getShakeExtras
611612

612-
isFoi <- use_ IsFileOfInterest f
613613
diagsWrite <- case isFoi of
614614
IsFOI Modified{firstOpen = False} -> do
615615
when (coerce $ ideTesting se) $ liftIO $ mRunLspT (lspEnv se) $

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,9 +1181,9 @@ defineEarlyCutoff' doDiagnostics cmp key file old mode action = do
11811181
pure (Nothing, ([ideErrorText file $ T.pack $ show e | not $ isBadDependency e],Nothing))
11821182
case getSourceFileOrigin file of
11831183
FromProject -> doAction
1184-
FromDependency -> case eqT @k @GetHieAst of
1185-
Just Refl -> doAction
1186-
Nothing -> error $
1184+
FromDependency -> if isSafeDependencyRule key
1185+
then doAction
1186+
else error $
11871187
"defineEarlyCutoff': Undefined action for dependency source files\n"
11881188
++ show file ++ "\n"
11891189
++ show key
@@ -1229,6 +1229,15 @@ defineEarlyCutoff' doDiagnostics cmp key file old mode action = do
12291229
-- * creating a dependency: If everything depends on GetModificationTime, we lose early cutoff
12301230
-- * creating bogus "file does not exists" diagnostics
12311231
| otherwise = useWithoutDependency (GetModificationTime_ False) fp
1232+
isSafeDependencyRule
1233+
:: forall k v
1234+
. IdeRule k v
1235+
=> k
1236+
-> Bool
1237+
isSafeDependencyRule _k
1238+
| Just Refl <- eqT @k @GetHieAst = True
1239+
| Just Refl <- eqT @k @IsFileOfInterest = True
1240+
| otherwise = False
12321241

12331242
traceA :: A v -> String
12341243
traceA (A Failed{}) = "Failed"

ghcide/src/Development/IDE/LSP/Notifications.hs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,14 @@ descriptor recorder plId = (defaultPluginDescriptor plId) { pluginNotificationHa
6161
\ide vfs _ (DidOpenTextDocumentParams TextDocumentItem{_uri,_version}) -> liftIO $ do
6262
atomically $ updatePositionMapping ide (VersionedTextDocumentIdentifier _uri _version) []
6363
whenUriFile _uri $ \file -> do
64+
let foiStatus = case getSourceFileOrigin file of
65+
FromProject -> Modified{firstOpen=True}
66+
FromDependency -> ReadOnly
6467
-- We don't know if the file actually exists, or if the contents match those on disk
6568
-- For example, vscode restores previously unsaved contents on open
66-
addFileOfInterest ide file Modified{firstOpen=True}
67-
setFileModified (cmapWithPrio LogFileStore recorder) (VFSModified vfs) ide False file
69+
addFileOfInterest ide file foiStatus
70+
unless (foiStatus == ReadOnly)
71+
$ setFileModified (cmapWithPrio LogFileStore recorder) (VFSModified vfs) ide False file
6872
logDebug (ideLogger ide) $ "Opened text document: " <> getUri _uri
6973

7074
, mkPluginNotificationHandler LSP.SMethod_TextDocumentDidChange $

0 commit comments

Comments
 (0)