Skip to content

Commit df95e6b

Browse files
committed
ghcide: Core.Compile: getDocsBatch: instead of IO throw use Either
Throw was vacuous - it was thrown & catched & ignored. At least it shows explicit type to process further.
1 parent 2bdd7fd commit df95e6b

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

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

+3-5
Original file line numberDiff line numberDiff line change
@@ -965,12 +965,12 @@ getDocsBatch
965965
:: HscEnv
966966
-> Module -- ^ a moudle where the names are in scope
967967
-> [Name]
968-
-> IO (Map.Map Name (Either T.Text (Maybe HsDocString, Map.Map Int HsDocString)))
968+
-> IO (Either ErrorMessages (Map.Map Name (Either T.Text (Maybe HsDocString, Map.Map Int HsDocString))))
969969
getDocsBatch hsc_env _mod _names = do
970970
((_warns,errs), res) <- initTc hsc_env HsSrcFile False _mod fakeSpan $ Map.fromList <$> traverse findNameInfo _names
971971
case res of
972-
Just x -> return $ fun x
973-
Nothing -> throwErrors errs
972+
Just x -> pure $ pure $ fun x
973+
Nothing -> pure $ Left errs
974974
where
975975
fun :: Map.Map Name (Either GetDocsFailure c) -> Map.Map Name (Either T.Text c)
976976
fun =
@@ -979,8 +979,6 @@ getDocsBatch hsc_env _mod _names = do
979979
fun1 :: Either GetDocsFailure c -> Either T.Text c
980980
fun1 = first showGhc
981981

982-
throwErrors = liftIO . throwIO . mkSrcErr
983-
984982
findNameInfo :: Name -> IOEnv (Env TcGblEnv TcLclEnv) (Name, Either GetDocsFailure (Maybe HsDocString, Map.Map Int HsDocString))
985983
findNameInfo name =
986984
case nameModule_maybe name of

ghcide/src/Development/IDE/Spans/Documentation.hs

+4-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import System.FilePath
3333

3434
import Language.LSP.Types (filePathToUri, getUri)
3535
import qualified Data.Map as Map
36-
import Development.IDE.Types.Diagnostics (FileDiagnostic)
3736

3837
mkDocMap
3938
:: HscEnv
@@ -72,11 +71,11 @@ getDocumentationsTryGhc :: HscEnv -> Module -> [Name] -> IO (Map.Map Name SpanDo
7271
getDocumentationsTryGhc env mod names = do
7372
res <- fun
7473
case res of
75-
Left _ -> return mempty
76-
Right res -> fmap Map.fromList $ sequenceA $ uncurry unwrap <$> Map.toList res
74+
Left _ -> return mempty -- catchSrcErrors (hsc_dflags env) "docs"
75+
Right res -> fmap Map.fromList $ sequenceA $ uncurry unwrap <$> Map.toList res
7776
where
78-
fun :: IO (Either [FileDiagnostic] (Map.Map Name (Either T.Text (Maybe HsDocString, Map.Map Int HsDocString))))
79-
fun = catchSrcErrors (hsc_dflags env) "docs" $ getDocsBatch env mod names
77+
fun :: IO (Either ErrorMessages (Map.Map Name (Either T.Text (Maybe HsDocString, Map.Map Int HsDocString))))
78+
fun = getDocsBatch env mod names
8079

8180
unwrap :: Name -> Either a (Maybe HsDocString, b) -> IO (Name, SpanDoc)
8281
unwrap name a = (name,) . extractDocString a <$> getSpanDocUris name

0 commit comments

Comments
 (0)