Skip to content

Commit

Permalink
Add supported cabal-versions to the error message
Browse files Browse the repository at this point in the history
  • Loading branch information
fendor committed Oct 20, 2024
1 parent 688c575 commit 869e8a3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
26 changes: 19 additions & 7 deletions plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import qualified Data.ByteString as BS
import Data.Hashable
import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HashMap
import qualified Data.List as List
import qualified Data.List.NonEmpty as NE
import qualified Data.Maybe as Maybe
import qualified Data.Text ()
import qualified Data.Text as T
import qualified Data.Text.Encoding as Encoding
import Data.Text.Utf16.Rope.Mixed as Rope
Expand All @@ -33,17 +35,21 @@ import Development.IDE.Graph (Key,
import Development.IDE.LSP.HoverDefinition (foundHover)
import qualified Development.IDE.Plugin.Completions.Logic as Ghcide
import Development.IDE.Types.Shake (toKey)
import qualified Distribution.CabalSpecVersion as Cabal
import qualified Distribution.Fields as Syntax
import Distribution.Package (Dependency)
import Distribution.PackageDescription (allBuildDepends,
depPkgName,
unPackageName)
import Distribution.PackageDescription.Configuration (flattenPackageDescription)
import Distribution.Parsec.Error
import qualified Distribution.Parsec.Position as Syntax
import GHC.Generics
import qualified Ide.Plugin.Cabal.CabalAdd as CabalAdd
import Ide.Plugin.Cabal.Completion.CabalFields as CabalFields
import qualified Ide.Plugin.Cabal.Completion.Completer.Types as CompleterTypes
import qualified Ide.Plugin.Cabal.Completion.Completions as Completions
import qualified Ide.Plugin.Cabal.Completion.Data as Data
import Ide.Plugin.Cabal.Completion.Types (ParseCabalCommonSections (ParseCabalCommonSections),
ParseCabalFields (..),
ParseCabalFile (..))
Expand All @@ -63,11 +69,6 @@ import Language.LSP.Protocol.Types
import qualified Language.LSP.VFS as VFS
import Text.Regex.TDFA


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

data Log
= LogModificationTime NormalizedFilePath FileVersion
| LogShake Shake.Log
Expand Down Expand Up @@ -252,13 +253,24 @@ cabalRules recorder plId = do
-- 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]*"
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."
unsupportedCabalHelpText = unlines
[ "The used cabal version is not fully supported by HLS. This means that some functionality might not work as expected."
, "If you face any issues try to downgrade to a supported cabal version."
, ""
, "Supported versions are: " <>
List.intercalate ", "
(fmap Cabal.showCabalSpecVersion Data.supportedCabalVersions)
]
errorDiags =
NE.toList $
NE.map
( \pe@(PError pos text) ->
if text =~ regex
then Diagnostics.warningDiagnostic file (Syntax.PWarning Syntax.PWTOther pos (text <> unsupportedCabalHelpText))
then Diagnostics.warningDiagnostic file (Syntax.PWarning Syntax.PWTOther pos $
unlines
[ text
, unsupportedCabalHelpText
])
else Diagnostics.errorDiagnostic file pe
)
pErrorNE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ import Ide.Plugin.Cabal.LicenseSuggest (licenseNames)
-- Completion Data
-- ----------------------------------------------------------------

supportedCabalVersions :: [CabalSpecVersion]
supportedCabalVersions = [CabalSpecV2_2 .. maxBound]

-- | Keyword for cabal version; required to be the top line in a cabal file
cabalVersionKeyword :: Map KeyWordName Completer
cabalVersionKeyword =
Map.singleton "cabal-version:" $
constantCompleter $
-- We only suggest cabal versions newer than 2.2
-- since we don't recommend using older ones.
map (T.pack . showCabalSpecVersion) [CabalSpecV2_2 .. maxBound]
map (T.pack . showCabalSpecVersion) supportedCabalVersions

-- | Top level keywords of a cabal file.
--
Expand Down

0 comments on commit 869e8a3

Please sign in to comment.