Skip to content

Commit 295dcb8

Browse files
committed
cast unsupported cabal version as warning
1 parent 9460d61 commit 295dcb8

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import Text.Regex.TDFA
6565

6666

6767
import qualified Data.Text ()
68+
import Distribution.Parsec.Error
6869
import qualified Ide.Plugin.Cabal.CabalAdd as CabalAdd
6970

7071
data Log
@@ -220,8 +221,9 @@ cabalRules recorder plId = do
220221
fields <- use_ ParseCabalFields file
221222
let commonSections = Maybe.mapMaybe (\case
222223
commonSection@(Syntax.Section (Syntax.Name _ "common") _ _) -> Just commonSection
223-
_ -> Nothing)
224-
fields
224+
_ -> Nothing
225+
)
226+
fields
225227
pure ([], Just commonSections)
226228

227229
define (cmapWithPrio LogShake recorder) $ \ParseCabalFile file -> do
@@ -247,7 +249,19 @@ cabalRules recorder plId = do
247249
let warningDiags = fmap (Diagnostics.warningDiagnostic file) pWarnings
248250
case pm of
249251
Left (_cabalVersion, pErrorNE) -> do
250-
let errorDiags = NE.toList $ NE.map (Diagnostics.errorDiagnostic file) pErrorNE
252+
let regex :: T.Text
253+
-- We don't support the cabal version, this should not be an error, as the
254+
-- user did not do anything wrong. Instead we cast it to a warning
255+
regex = "Unsupported cabal-version [0-9]+.[0-9]*"
256+
errorDiags =
257+
NE.toList $
258+
NE.map
259+
( \pe@(PError pos text) ->
260+
if text =~ regex
261+
then Diagnostics.warningDiagnostic file (Syntax.PWarning Syntax.PWTOther pos text)
262+
else Diagnostics.errorDiagnostic file pe
263+
)
264+
pErrorNE
251265
allDiags = errorDiags <> warningDiags
252266
pure (allDiags, Nothing)
253267
Right gpd -> do

plugins/hls-cabal-plugin/test/Main.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ pluginTests =
107107
length diags @?= 1
108108
unknownLicenseDiag ^. L.range @?= Range (Position 3 24) (Position 4 0)
109109
unknownLicenseDiag ^. L.severity @?= Just DiagnosticSeverity_Error
110-
, runCabalTestCaseSession "Publishes Diagnostics on Error in the first line" "" $ do
110+
, runCabalTestCaseSession "Publishes Diagnostics on unsupported cabal version as Warning" "" $ do
111111
_ <- openDoc "unsupportedVersion.cabal" "cabal"
112112
diags <- cabalCaptureKick
113113
unknownVersionDiag <- liftIO $ inspectDiagnostic diags ["Unsupported cabal-version 99999.0"]
114114
liftIO $ do
115115
length diags @?= 1
116116
unknownVersionDiag ^. L.range @?= Range (Position 0 0) (Position 1 0)
117-
unknownVersionDiag ^. L.severity @?= Just DiagnosticSeverity_Error
117+
unknownVersionDiag ^. L.severity @?= Just DiagnosticSeverity_Warning
118118
, runCabalTestCaseSession "Clears diagnostics" "" $ do
119119
doc <- openDoc "invalid.cabal" "cabal"
120120
diags <- cabalCaptureKick

0 commit comments

Comments
 (0)