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 295dcb8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
20 changes: 17 additions & 3 deletions 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 @@ -220,8 +221,9 @@ cabalRules recorder plId = do
fields <- use_ ParseCabalFields file
let commonSections = Maybe.mapMaybe (\case

Check failure on line 222 in plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs

View workflow job for this annotation

GitHub Actions / test (9.10, ubuntu-latest, true)

View pattern in expression context:

Check failure on line 222 in plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs

View workflow job for this annotation

GitHub Actions / flags (9.10, ubuntu-latest)

View pattern in expression context:

Check failure on line 222 in plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs

View workflow job for this annotation

GitHub Actions / test (9.8, ubuntu-latest, true)

View pattern in expression context:

Check failure on line 222 in plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs

View workflow job for this annotation

GitHub Actions / test (9.8, macOS-latest, false)

View pattern in expression context:

Check failure on line 222 in plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs

View workflow job for this annotation

GitHub Actions / test (9.4, macOS-latest, false)

View pattern in expression context:

Check failure on line 222 in plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs

View workflow job for this annotation

GitHub Actions / test (9.6, macOS-latest, false)

View pattern in expression context:

Check failure on line 222 in plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs

View workflow job for this annotation

GitHub Actions / test (9.4, ubuntu-latest, true)

View pattern in expression context:

Check failure on line 222 in plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs

View workflow job for this annotation

GitHub Actions / test (9.6, ubuntu-latest, true)

View pattern in expression context:

Check failure on line 222 in plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs

View workflow job for this annotation

GitHub Actions / test (9.10, macOS-latest, false)

View pattern in expression context:

Check failure on line 222 in plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs

View workflow job for this annotation

GitHub Actions / test (9.4, windows-latest, true)

View pattern in expression context:

Check failure on line 222 in plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs

View workflow job for this annotation

GitHub Actions / test (9.10, windows-latest, true)

View pattern in expression context:

Check failure on line 222 in plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs

View workflow job for this annotation

GitHub Actions / test (9.6, windows-latest, true)

View pattern in expression context:

Check failure on line 222 in plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs

View workflow job for this annotation

GitHub Actions / test (9.8, windows-latest, true)

View pattern in expression context:
commonSection@(Syntax.Section (Syntax.Name _ "common") _ _) -> Just commonSection
_ -> Nothing)
fields
_ -> Nothing
)
fields
pure ([], Just commonSections)

define (cmapWithPrio LogShake recorder) $ \ParseCabalFile file -> do
Expand All @@ -247,7 +249,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 295dcb8

Please sign in to comment.