Skip to content

Commit b543998

Browse files
committed
Add supported cabal-versions to the error message
1 parent 5d7eb82 commit b543998

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

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

+16-2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ import Text.Regex.TDFA
6767
import qualified Data.Text ()
6868
import Distribution.Parsec.Error
6969
import qualified Ide.Plugin.Cabal.CabalAdd as CabalAdd
70+
import qualified Data.List as List
71+
import qualified Distribution.CabalSpecVersion as Cabal
72+
import qualified Ide.Plugin.Cabal.Completion.Data as Data
7073

7174
data Log
7275
= LogModificationTime NormalizedFilePath FileVersion
@@ -252,13 +255,24 @@ cabalRules recorder plId = do
252255
-- We don't support the cabal version, this should not be an error, as the
253256
-- user did not do anything wrong. Instead we cast it to a warning
254257
regex = "Unsupported cabal-version [0-9]+.[0-9]*"
255-
unsupportedCabalHelpText = "\nThe used cabal version is not fully supported by hls. This means that some functionallity might not work as expected.\nIf you face any issues try to downgrade to a supported cabal version."
258+
unsupportedCabalHelpText = unlines
259+
[ "The used cabal version is not fully supported by HLS. This means that some functionality might not work as expected."
260+
, "If you face any issues try to downgrade to a supported cabal version."
261+
, ""
262+
, "Supported versions are: " <>
263+
List.intercalate ", "
264+
(fmap Cabal.showCabalSpecVersion Data.supportedCabalVersions)
265+
]
256266
errorDiags =
257267
NE.toList $
258268
NE.map
259269
( \pe@(PError pos text) ->
260270
if text =~ regex
261-
then Diagnostics.warningDiagnostic file (Syntax.PWarning Syntax.PWTOther pos (text <> unsupportedCabalHelpText))
271+
then Diagnostics.warningDiagnostic file (Syntax.PWarning Syntax.PWTOther pos $
272+
unlines
273+
[ text
274+
, unsupportedCabalHelpText
275+
])
262276
else Diagnostics.errorDiagnostic file pe
263277
)
264278
pErrorNE

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@ import Ide.Plugin.Cabal.LicenseSuggest (licenseNames)
2323
-- Completion Data
2424
-- ----------------------------------------------------------------
2525

26+
supportedCabalVersions :: [CabalSpecVersion]
27+
supportedCabalVersions = [CabalSpecV2_2 .. maxBound]
28+
2629
-- | Keyword for cabal version; required to be the top line in a cabal file
2730
cabalVersionKeyword :: Map KeyWordName Completer
2831
cabalVersionKeyword =
2932
Map.singleton "cabal-version:" $
3033
constantCompleter $
3134
-- We only suggest cabal versions newer than 2.2
3235
-- since we don't recommend using older ones.
33-
map (T.pack . showCabalSpecVersion) [CabalSpecV2_2 .. maxBound]
36+
map (T.pack . showCabalSpecVersion) supportedCabalVersions
3437

3538
-- | Top level keywords of a cabal file.
3639
--

0 commit comments

Comments
 (0)