Skip to content

Commit d3a6039

Browse files
wz1000fendor
authored andcommitted
cabal plugin
1 parent 4a830e6 commit d3a6039

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

hls-test-utils/src/Test/Hls/Util.hs

+5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ module Test.Hls.Util
3636
, inspectCodeAction
3737
, inspectCommand
3838
, inspectDiagnostic
39+
, inspectDiagnosticAny
3940
, waitForDiagnosticsFrom
4041
, waitForDiagnosticsFromSource
4142
, waitForDiagnosticsFromSourceWithTimeout
@@ -247,6 +248,10 @@ inspectDiagnostic :: [Diagnostic] -> [T.Text] -> IO Diagnostic
247248
inspectDiagnostic diags s = onMatch diags (\ca -> all (`T.isInfixOf` (ca ^. L.message)) s) err
248249
where err = "expected diagnostic matching '" ++ show s ++ "' but did not find one"
249250

251+
inspectDiagnosticAny :: [Diagnostic] -> [T.Text] -> IO Diagnostic
252+
inspectDiagnosticAny diags s = onMatch diags (\ca -> any (`T.isInfixOf` (ca ^. L.message)) s) err
253+
where err = "expected diagnostic matching one of'" ++ show s ++ "' but did not find one"
254+
250255
expectDiagnostic :: [Diagnostic] -> [T.Text] -> IO ()
251256
expectDiagnostic diags s = void $ inspectDiagnostic diags s
252257

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,12 @@ cabalRules recorder plId = do
249249
let warningDiags = fmap (Diagnostics.warningDiagnostic file) pWarnings
250250
case pm of
251251
Left (_cabalVersion, pErrorNE) -> do
252-
let regex :: T.Text
252+
let regexUnknownCabalBefore310 :: T.Text
253253
-- We don't support the cabal version, this should not be an error, as the
254254
-- user did not do anything wrong. Instead we cast it to a warning
255-
regex = "Unsupported cabal-version [0-9]+.[0-9]*"
255+
regexUnknownCabalBefore310 = "Unsupported cabal-version [0-9]+.[0-9]*"
256+
regexUnknownCabalVersion :: T.Text
257+
regexUnknownCabalVersion = "Unsupported cabal format version in cabal-version field: [0-9]+.[0-9]+"
256258
unsupportedCabalHelpText = unlines
257259
[ "The used `cabal-version` is not fully supported by this `HLS` binary."
258260
, "Either the `cabal-version` is unknown, or too new for this executable."
@@ -267,7 +269,10 @@ cabalRules recorder plId = do
267269
NE.toList $
268270
NE.map
269271
( \pe@(PError pos text) ->
270-
if text =~ regex
272+
if any (text =~)
273+
[ regexUnknownCabalBefore310
274+
, regexUnknownCabalVersion
275+
]
271276
then Diagnostics.warningDiagnostic file (Syntax.PWarning Syntax.PWTOther pos $
272277
unlines
273278
[ text

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pluginTests =
110110
, runCabalTestCaseSession "Publishes Diagnostics on unsupported cabal version as Warning" "" $ do
111111
_ <- openDoc "unsupportedVersion.cabal" "cabal"
112112
diags <- cabalCaptureKick
113-
unknownVersionDiag <- liftIO $ inspectDiagnostic diags ["Unsupported cabal-version 99999.0"]
113+
unknownVersionDiag <- liftIO $ inspectDiagnosticAny diags ["Unsupported cabal-version 99999.0", "Unsupported cabal format version in cabal-version field: 99999.0"]
114114
liftIO $ do
115115
length diags @?= 1
116116
unknownVersionDiag ^. L.range @?= Range (Position 0 0) (Position 1 0)

0 commit comments

Comments
 (0)