Skip to content

Commit

Permalink
cast unsupported cabal version as warning
Browse files Browse the repository at this point in the history
  • Loading branch information
fridewald committed Oct 13, 2024
1 parent 9460d61 commit 40173f4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 14 additions & 1 deletion plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import Text.Regex.TDFA


import qualified Data.Text ()
import Distribution.Parsec.Error
import qualified Ide.Plugin.Cabal.CabalAdd as CabalAdd

data Log
Expand Down Expand Up @@ -247,7 +248,19 @@ cabalRules recorder plId = do
let warningDiags = fmap (Diagnostics.warningDiagnostic file) pWarnings
case pm of
Left (_cabalVersion, pErrorNE) -> do
let errorDiags = NE.toList $ NE.map (Diagnostics.errorDiagnostic file) pErrorNE
let regex :: T.Text
-- We don't support the cabal version, this should not be an error, as the
-- user did not do anything wrong. Instead we cast it to a warning
regex = "Unsupported cabal-version [0-9]+.[0-9]*"
errorDiags =
NE.toList $
NE.map
( \pe@(PError pos text) ->
if text =~ regex
then Diagnostics.warningDiagnostic file (Syntax.PWarning Syntax.PWTOther pos text)
else Diagnostics.errorDiagnostic file pe
)
pErrorNE
allDiags = errorDiags <> warningDiags
pure (allDiags, Nothing)
Right gpd -> do
Expand Down
4 changes: 2 additions & 2 deletions plugins/hls-cabal-plugin/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ pluginTests =
length diags @?= 1
unknownLicenseDiag ^. L.range @?= Range (Position 3 24) (Position 4 0)
unknownLicenseDiag ^. L.severity @?= Just DiagnosticSeverity_Error
, runCabalTestCaseSession "Publishes Diagnostics on Error in the first line" "" $ do
, runCabalTestCaseSession "Publishes Diagnostics on unsupported cabal version as Warning" "" $ do
_ <- openDoc "unsupportedVersion.cabal" "cabal"
diags <- cabalCaptureKick
unknownVersionDiag <- liftIO $ inspectDiagnostic diags ["Unsupported cabal-version 99999.0"]
liftIO $ do
length diags @?= 1
unknownVersionDiag ^. L.range @?= Range (Position 0 0) (Position 1 0)
unknownVersionDiag ^. L.severity @?= Just DiagnosticSeverity_Error
unknownVersionDiag ^. L.severity @?= Just DiagnosticSeverity_Warning
, runCabalTestCaseSession "Clears diagnostics" "" $ do
doc <- openDoc "invalid.cabal" "cabal"
diags <- cabalCaptureKick
Expand Down

0 comments on commit 40173f4

Please sign in to comment.