3
3
{-# LANGUAGE LambdaCase #-}
4
4
{-# LANGUAGE OverloadedStrings #-}
5
5
{-# LANGUAGE TypeFamilies #-}
6
- {-# LANGUAGE ViewPatterns #-}
6
+ {-# LANGUAGE ViewPatterns #-}
7
7
8
8
module Ide.Plugin.Cabal (descriptor , haskellInteractionDescriptor , Log (.. )) where
9
9
@@ -56,6 +56,7 @@ import Ide.Plugin.Cabal.Completion.Types (ParseCabalCommon
56
56
ParseCabalFile (.. ))
57
57
import qualified Ide.Plugin.Cabal.Completion.Types as Types
58
58
import Ide.Plugin.Cabal.Definition (gotoDefinition )
59
+ import qualified Ide.Plugin.Cabal.Dependencies as Dependencies
59
60
import qualified Ide.Plugin.Cabal.Diagnostics as Diagnostics
60
61
import qualified Ide.Plugin.Cabal.FieldSuggest as FieldSuggest
61
62
import qualified Ide.Plugin.Cabal.LicenseSuggest as LicenseSuggest
@@ -69,9 +70,6 @@ import qualified Language.LSP.Protocol.Message as LSP
69
70
import Language.LSP.Protocol.Types
70
71
import qualified Language.LSP.VFS as VFS
71
72
import Text.Regex.TDFA
72
- import Development.IDE.GHC.Compat (getUnitInfoMap , unitPackageNameString , unitPackageVersion , filterUniqMap , nonDetEltsUniqMap )
73
- import Data.Version (Version (.. ))
74
- import qualified Data.Char as Char
75
73
76
74
data Log
77
75
= LogModificationTime NormalizedFilePath FileVersion
@@ -385,44 +383,9 @@ hints :: PluginMethodHandler IdeState LSP.Method_TextDocumentInlayHint
385
383
hints state _plId clp = do
386
384
let uri = clp ^. JL. textDocument . JL. uri
387
385
nfp <- getNormalizedFilePathE uri
388
- cabalFields <- runActionE " cabal.cabal-lens" state $ useE ParseCabalFields nfp
389
- (hscEnv -> hsc) <- runActionE " classplugin.codeAction.GhcSession" state $ useE GhcSession nfp
390
- let lookupVersion pkgName = Maybe. listToMaybe $ nonDetEltsUniqMap $ fmap unitPackageVersion $ filterUniqMap ((==) pkgName . unitPackageNameString) $ getUnitInfoMap hsc
391
- pure $ InL $ fmap hint $ collectPackageVersions (fmap printVersion . lookupVersion . T. unpack) =<< cabalFields
392
- where
393
- collectPackageVersions :: (T. Text -> Maybe T. Text ) -> Syntax. Field Syntax. Position -> [(Syntax. Position , LicenseSuggest. Text )]
394
- collectPackageVersions lookupVersion (Syntax. Field (Syntax. Name _ " build-depends" ) pos) = concatMap (fieldLinePackageVersions lookupVersion) pos
395
- collectPackageVersions lookupVersion (Syntax. Section _ _ fields) = concatMap (collectPackageVersions lookupVersion) fields
396
- collectPackageVersions _ _ = []
397
-
398
- fieldLinePackageVersions :: (T. Text -> Maybe T. Text ) -> Syntax. FieldLine Syntax. Position -> [(Syntax. Position , LicenseSuggest. Text )]
399
- fieldLinePackageVersions lookupVersion (Syntax. FieldLine pos x) =
400
- let splitted = T. splitOn " ," $ Encoding. decodeUtf8Lenient x
401
- calcStartPosition (prev, start) = T. length prev + 1 + start
402
- potentialPkgs = List. foldl' (\ a b -> a <> [(b, Maybe. maybe 0 calcStartPosition $ Maybe. listToMaybe $ reverse a)]) [] splitted
403
- versions = do
404
- (pkg', pkgStartOffset) <- potentialPkgs
405
- let pkgName = T. takeWhile (not . Char. isSpace) . T. strip $ pkg'
406
- endOfPackage = T. length pkgName + (T. length $ T. takeWhile Char. isSpace pkg')
407
- version <- Maybe. maybeToList $ lookupVersion $ T. takeWhile (not . Char. isSpace) . T. strip $ pkg'
408
- pure (Syntax. Position (Syntax. positionRow pos) (Syntax. positionCol pos + pkgStartOffset + endOfPackage), version)
409
- in versions
410
-
411
- printVersion v = T. intercalate " ." (fmap (T. pack . show ) $ versionBranch v)
412
-
413
- hint :: (Syntax. Position , LicenseSuggest. Text ) -> InlayHint
414
- hint (pos, foo) =
415
- let cPos = Types. cabalPositionToLSPPosition pos
416
- mkInlayHintLabelPart = InlayHintLabelPart (" (" <> foo <> " )" ) Nothing Nothing Nothing
417
- in InlayHint { _position = cPos
418
- , _label = InR $ pure mkInlayHintLabelPart
419
- , _kind = Nothing -- neither a type nor a parameter
420
- , _textEdits = Nothing -- same as CodeAction
421
- , _tooltip = Nothing
422
- , _paddingLeft = Nothing
423
- , _paddingRight = Nothing
424
- , _data_ = Nothing
425
- }
386
+ cabalFields <- runActionE " cabal.cabal-hints" state $ useE ParseCabalFields nfp
387
+ (hscEnv -> hsc) <- runActionE " cabal.cabal-hints" state $ useE GhcSession nfp
388
+ pure $ InL $ Dependencies. dependencyVersionHints cabalFields hsc
426
389
427
390
-- | Handler for hover messages.
428
391
--
0 commit comments