Skip to content

Commit d33c32b

Browse files
committed
Load FOIs (otherwise nothing happens) and wait for the hiedb writer
1 parent 38f8e3e commit d33c32b

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

ghcide/src/Development/IDE/Main.hs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ import Text.Printf (printf)
9595
data Command
9696
= Lsp -- ^ Run the LSP server
9797
| Check [FilePath] -- ^ Typecheck some paths and print diagnostics. Exit code is the number of failures
98-
| Index FilePath -- ^ Index the whole project and print the path to the database
98+
| Index [FilePath] -- ^ Index all the targets and print the path to the database
9999
| Db FilePath HieDb.Options HieDb.Command -- ^ Run a command in the hiedb
100100

101101
data Arguments = Arguments
@@ -267,31 +267,38 @@ defaultMain Arguments{..} = do
267267
measureMemory logger [keys] consoleObserver valuesRef
268268

269269
unless (null failed) (exitWith $ ExitFailure (length failed))
270-
Index dir -> do
271-
dbLoc <- getHieDbLoc dir
270+
Index argFiles -> do
271+
dbLoc <- getHieDbLoc "."
272+
files <- expandFiles (argFiles ++ ["." | null argFiles])
272273
runWithDb dbLoc $ \hiedb hieChan -> do
273274
vfs <- makeVFSHandle
274-
sessionLoader <- loadSessionWithOptions argsSessionLoadingOptions dir
275+
sessionLoader <- loadSessionWithOptions argsSessionLoadingOptions "."
275276
let options = (argsIdeOptions argsDefaultHlsConfig sessionLoader)
276277
{ optCheckParents = pure NeverCheck
277278
, optCheckProject = pure False
278279
}
279280
ide <- initialise argsDefaultHlsConfig rules Nothing logger debouncer options vfs hiedb hieChan
280281
registerIdeConfiguration (shakeExtras ide) $ IdeConfiguration mempty (hashed Nothing)
282+
let fois = map toNormalizedFilePath' files
283+
setFilesOfInterest ide $ HashMap.fromList $ map (,OnDisk) fois
281284
results <- runAction "Index" ide $ do
285+
_ <- uses GetModIfaceFromDiskAndIndex fois
282286
allKnownTargets <- toKnownFiles <$> useNoFile_ GetKnownTargets
283-
liftIO $ hPutStrLn stderr $ "Found " <> show(length allKnownTargets) <> " targets"
287+
liftIO $ hPutStrLn stderr $ "Indexing " <> show(length allKnownTargets) <> " targets"
284288
uses GetModIfaceFromDiskAndIndex $ toList allKnownTargets
285-
putStrLn dbLoc
286-
let nfailures = length $ filter isNothing results
287-
let pending = indexPending $ hiedbWriter $ shakeExtras ide
288289

289-
hPutStrLn stderr "Waiting for indexing..."
290+
hPutStrLn stderr "Writing index... "
291+
292+
let !nfailures = length $ filter isNothing results
293+
let !pending = indexPending $ hiedbWriter $ shakeExtras ide
294+
290295
atomically $ do
291296
n <- readTVar pending
292297
unless (HashMap.size n == 0) retry
293298

299+
putStrLn dbLoc
294300
unless (nfailures == 0) $ exitWith $ ExitFailure nfailures
301+
295302
Db dir opts cmd -> do
296303
dbLoc <- getHieDbLoc dir
297304
hPutStrLn stderr $ "Using hiedb at: " ++ dbLoc

0 commit comments

Comments
 (0)