Skip to content

Commit 0412b6f

Browse files
committed
Call useWithStale instead of useWithStaleFast when calling ParseCabalFields
Add documentation about this choice
1 parent 7563439 commit 0412b6f

File tree

1 file changed

+6
-1
lines changed
  • plugins/hls-cabal-plugin/src/Ide/Plugin

1 file changed

+6
-1
lines changed

plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs

+6-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,9 @@ completion recorder ide _ complParams = do
314314
mVf <- lift $ getVirtualFile $ toNormalizedUri uri
315315
case (,) <$> mVf <*> uriToFilePath' uri of
316316
Just (cnts, path) -> do
317-
mFields <- liftIO $ runIdeAction "cabal-plugin.fields" (shakeExtras ide) $ useWithStaleFast ParseCabalFields $ toNormalizedFilePath path
317+
-- We decide on `useWithStale` here, since `useWithStaleFast` often leads to the wrong completions being suggested.
318+
-- In case it fails, we still will get some completion results instead of an error.
319+
mFields <- liftIO $ runAction "cabal-plugin.fields" ide $ useWithStale ParseCabalFields $ toNormalizedFilePath path
318320
case mFields of
319321
Nothing ->
320322
pure . InR $ InR Null
@@ -335,6 +337,9 @@ completion recorder ide _ complParams = do
335337
let completer = Completions.contextToCompleter ctx
336338
let completerData = CompleterTypes.CompleterData
337339
{ getLatestGPD = do
340+
-- We decide on useWithStaleFast here, since we mostly care about the file's meta information,
341+
-- thus, a quick response gives us the desired result most of the time.
342+
-- The `withStale` option is very important here, since we often call this rule with invalid cabal files.
338343
mGPD <- runIdeAction "cabal-plugin.modulesCompleter.gpd" (shakeExtras ide) $ useWithStaleFast ParseCabalFile $ toNormalizedFilePath fp
339344
pure $ fmap fst mGPD
340345
, cabalPrefixInfo = prefInfo

0 commit comments

Comments
 (0)