Skip to content

Commit 3c9ae07

Browse files
committed
Make ideErrorWithSource produce FileDiagnostic by adding filepath arg
1 parent d5b70e0 commit 3c9ae07

File tree

3 files changed

+15
-19
lines changed

3 files changed

+15
-19
lines changed

ghcide/session-loader/Development/IDE/Session.hs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
599599
this_target_details = TargetDetails (TargetFile _cfp) this_error_env this_dep_info [_cfp]
600600
this_flags = (this_error_env, this_dep_info)
601601
this_error_env = ([this_error], Nothing)
602-
this_error = uncurry (FileDiagnostic _cfp) $ ideErrorWithSource (Just "cradle") (Just DiagnosticSeverity_Error)
602+
this_error = ideErrorWithSource (Just "cradle") (Just DiagnosticSeverity_Error) _cfp
603603
$ T.unlines
604604
[ "No cradle target found. Is this file listed in the targets of your cradle?"
605605
, "If you are using a .cabal file, please ensure that this module is listed in either the exposed-modules or other-modules section"
@@ -923,7 +923,7 @@ newComponentCache recorder exts cradlePath _cfp hsc_env old_cis new_cis dir = do
923923

924924
#if MIN_VERSION_ghc(9,3,0)
925925
let closure_errs = checkHomeUnitsClosed' (hsc_unit_env hscEnv') (hsc_all_home_unit_ids hscEnv')
926-
multi_errs = map (uncurry (FileDiagnostic _cfp) . ideErrorWithSource (Just "cradle") (Just DiagnosticSeverity_Warning) . T.pack . Compat.printWithoutUniques) closure_errs
926+
multi_errs = map (ideErrorWithSource (Just "cradle") (Just DiagnosticSeverity_Warning) _cfp . T.pack . Compat.printWithoutUniques) closure_errs
927927
bad_units = OS.fromList $ concat $ do
928928
x <- bagToList $ mapBag errMsgDiagnostic $ unionManyBags $ map Compat.getMessages closure_errs
929929
DriverHomePackagesNotClosed us <- pure x
@@ -1311,6 +1311,4 @@ showPackageSetupException PackageSetupException{..} = unwords
13111311

13121312
renderPackageSetupException :: FilePath -> PackageSetupException -> FileDiagnostic
13131313
renderPackageSetupException fp e =
1314-
let (showDiag, lspDiag) = ideErrorWithSource (Just "cradle") (Just DiagnosticSeverity_Error) (T.pack $ showPackageSetupException e)
1315-
in
1316-
FileDiagnostic (toNormalizedFilePath' fp) showDiag lspDiag
1314+
ideErrorWithSource (Just "cradle") (Just DiagnosticSeverity_Error) (toNormalizedFilePath' fp) (T.pack $ showPackageSetupException e)

ghcide/session-loader/Development/IDE/Session/Diagnostics.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ data CradleErrorDetails =
2727
Depicts the cradle error in a user-friendly way.
2828
-}
2929
renderCradleError :: CradleError -> Cradle a -> NormalizedFilePath -> FileDiagnostic
30-
renderCradleError (CradleError deps _ec ms) cradle nfp
31-
| HieBios.isCabalCradle cradle =
32-
let (showDiag, diag) = ideErrorWithSource (Just "cradle") (Just DiagnosticSeverity_Error) $ T.unlines $ map T.pack userFriendlyMessage
33-
in FileDiagnostic nfp showDiag diag{_data_ = Just $ Aeson.toJSON CradleErrorDetails{cabalProjectFiles=absDeps}}
34-
| otherwise =
35-
let (showDiag, diag) = ideErrorWithSource (Just "cradle") (Just DiagnosticSeverity_Error) $ T.unlines $ map T.pack userFriendlyMessage
36-
in FileDiagnostic nfp showDiag diag
30+
renderCradleError (CradleError deps _ec ms) cradle nfp =
31+
let noDetails =
32+
ideErrorWithSource (Just "cradle") (Just DiagnosticSeverity_Error) nfp $ T.unlines $ map T.pack userFriendlyMessage
33+
in
34+
if HieBios.isCabalCradle cradle
35+
then flip modifyFdLspDiagnostic noDetails $ \diag -> diag{_data_ = Just $ Aeson.toJSON CradleErrorDetails{cabalProjectFiles=absDeps}}
36+
else noDetails
3737
where
3838
absDeps = fmap (cradleRootDir cradle </>) deps
3939
userFriendlyMessage :: [String]

ghcide/src/Development/IDE/Types/Diagnostics.hs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,15 @@ type IdeResultNoDiagnosticsEarlyCutoff v = (Maybe ByteString, Maybe v)
4949

5050
ideErrorText :: NormalizedFilePath -> T.Text -> FileDiagnostic
5151
ideErrorText fdFilePath msg =
52-
let (fdShouldShowDiagnostic, fdLspDiagnostic) =
53-
ideErrorWithSource (Just "compiler") (Just DiagnosticSeverity_Error) msg
54-
in
55-
FileDiagnostic{..}
52+
ideErrorWithSource (Just "compiler") (Just DiagnosticSeverity_Error) fdFilePath msg
5653

5754
ideErrorWithSource
5855
:: Maybe T.Text
5956
-> Maybe DiagnosticSeverity
57+
-> NormalizedFilePath
6058
-> T.Text
61-
-> (ShowDiagnostic, Diagnostic)
62-
ideErrorWithSource source sev msg = (ShowDiag, LSP.Diagnostic {
59+
-> FileDiagnostic
60+
ideErrorWithSource source sev fp msg = FileDiagnostic fp ShowDiag LSP.Diagnostic {
6361
_range = noRange,
6462
_severity = sev,
6563
_code = Nothing,
@@ -69,7 +67,7 @@ ideErrorWithSource source sev msg = (ShowDiag, LSP.Diagnostic {
6967
_tags = Nothing,
7068
_codeDescription = Nothing,
7169
_data_ = Nothing
72-
})
70+
}
7371

7472
-- | Defines whether a particular diagnostic should be reported
7573
-- back to the user.

0 commit comments

Comments
 (0)