From c17d3203b9fcd4b9797a8d64578f0dac22ce56e6 Mon Sep 17 00:00:00 2001 From: VeryMilkyJoe Date: Sat, 8 Jun 2024 18:35:05 +0200 Subject: [PATCH] Call useWithStale instead of useWithStaleFast when calling ParseCabalFields Add documentation about this choice --- plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs b/plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs index c483ddc1d5..40892b8b12 100644 --- a/plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs +++ b/plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs @@ -314,7 +314,9 @@ completion recorder ide _ complParams = do mVf <- lift $ getVirtualFile $ toNormalizedUri uri case (,) <$> mVf <*> uriToFilePath' uri of Just (cnts, path) -> do - mFields <- liftIO $ runIdeAction "cabal-plugin.fields" (shakeExtras ide) $ useWithStaleFast ParseCabalFields $ toNormalizedFilePath path + -- We decide on `useWithStale` here, since `useWithStaleFast` often leads to the wrong completions being suggested. + -- In case it fails, we still will get some completion results instead of an error. + mFields <- liftIO $ runAction "cabal-plugin.fields" ide $ useWithStale ParseCabalFields $ toNormalizedFilePath path case mFields of Nothing -> pure . InR $ InR Null @@ -335,6 +337,9 @@ completion recorder ide _ complParams = do let completer = Completions.contextToCompleter ctx let completerData = CompleterTypes.CompleterData { getLatestGPD = do + -- We decide on useWithStaleFast here, since we mostly care about the file's meta information, + -- thus, a quick response gives us the desired result most of the time. + -- The `withStale` option is very important here, since we often call this rule with invalid cabal files. mGPD <- runIdeAction "cabal-plugin.modulesCompleter.gpd" (shakeExtras ide) $ useWithStaleFast ParseCabalFile $ toNormalizedFilePath fp pure $ fmap fst mGPD , cabalPrefixInfo = prefInfo