Skip to content

Commit 938cdcd

Browse files
committed
Only show linear arrows on datacons with LinearTypes
1 parent 7d02159 commit 938cdcd

6 files changed

Lines changed: 30 additions & 21 deletions

File tree

ghcide/src/Development/IDE/Core/Actions.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@ getAtPoint file pos = runMaybeT $ do
5252
shakeExtras <- lift askShake
5353

5454
env <- hscEnv . fst <$> useWithStaleFastMT GhcSession file
55+
parsedModule <- fst <$> useWithStaleFastMT GetParsedModule file
5556
dkMap <- lift $ maybe (DKMap mempty mempty mempty) fst <$> runMaybeT (useWithStaleFastMT GetDocMap file)
5657

5758
!pos' <- MaybeT (return $ fromCurrentPosition mapping pos)
5859

5960
MaybeT $ liftIO $ fmap (first (toCurrentRange mapping =<<)) <$>
60-
AtPoint.atPoint opts shakeExtras hf dkMap env pos'
61+
AtPoint.atPoint opts shakeExtras hf dkMap env pos' parsedModule
6162

6263
-- | Converts locations in the source code to their current positions,
6364
-- taking into account changes that may have occurred due to edits.

ghcide/src/Development/IDE/GHC/Compat/Util.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ module Development.IDE.GHC.Compat.Util (
3131
Pair(..),
3232
-- * EnumSet
3333
EnumSet,
34+
member,
3435
toList,
3536
-- * FastString exports
3637
FastString,

ghcide/src/Development/IDE/GHC/Util.hs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module Development.IDE.GHC.Util(
2929
printOutputable,
3030
printOutputableOneLine,
3131
getExtensions,
32+
getExtensionsSet,
3233
stripOccNamePrefix,
3334
) where
3435

@@ -279,7 +280,10 @@ printOutputable' print =
279280
{-# INLINE printOutputable #-}
280281

281282
getExtensions :: ParsedModule -> [Extension]
282-
getExtensions = toList . extensionFlags . ms_hspp_opts . pm_mod_summary
283+
getExtensions = toList . getExtensionsSet
284+
285+
getExtensionsSet :: ParsedModule -> EnumSet Extension
286+
getExtensionsSet = extensionFlags . ms_hspp_opts . pm_mod_summary
283287

284288
-- | When e.g. DuplicateRecordFields is enabled, compiler generates
285289
-- names like "$sel:accessor:One" and "$sel:accessor:Two" to
@@ -331,4 +335,3 @@ occNamePrefixes =
331335
, "$c"
332336
, "$m"
333337
]
334-

ghcide/src/Development/IDE/Plugin/Completions.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ resolveCompletion ide _pid comp@CompletionItem{_detail,_documentation,_data_} ur
139139
Nothing -> liftIO $ spanDocToMarkdown . fst <$> getDocumentationTryGhc (hscEnv sess) name
140140
typ <- case lookupNameEnv km name of
141141
_ | not needType -> pure Nothing
142-
Just ty -> pure (safeTyThingType ty)
142+
Just ty -> pure (safeTyThingType True ty)
143143
Nothing -> do
144-
(safeTyThingType =<<) <$> liftIO (lookupName (hscEnv sess) name)
144+
(safeTyThingType True =<<) <$> liftIO (lookupName (hscEnv sess) name)
145145
let det1 = case typ of
146146
Just ty -> Just (":: " <> printOutputable (stripForall ty) <> "\n")
147147
Nothing -> Nothing

ghcide/src/Development/IDE/Spans/AtPoint.hs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ import Development.IDE.Core.PositionMapping
4141
import Development.IDE.Core.RuleTypes
4242
import Development.IDE.GHC.Compat
4343
import qualified Development.IDE.GHC.Compat.Util as Util
44-
import Development.IDE.GHC.Util (printOutputable,
44+
import Development.IDE.GHC.Util (getExtensions,
45+
getExtensionsSet,
46+
printOutputable,
4547
printOutputableOneLine)
4648
import Development.IDE.Spans.Common
4749
import Development.IDE.Types.Options
@@ -69,9 +71,12 @@ import qualified Data.Set as S
6971
import Data.Tree
7072
import qualified Data.Tree as T
7173
import Data.Version (showVersion)
74+
import Debug.Trace (traceShow, traceShowId)
7275
import Development.IDE.Core.LookupMod (LookupModule, lookupMod)
76+
import Development.IDE.Core.PluginUtils (runActionE)
7377
import Development.IDE.Core.Shake (ShakeExtras (..),
74-
runIdeAction)
78+
runIdeAction, use,
79+
useWithStaleFast)
7580
import Development.IDE.Types.Shake (WithHieDb)
7681
import GHC.Iface.Ext.Types (EvVarSource (..),
7782
HieAST (..),
@@ -261,8 +266,9 @@ atPoint
261266
-> DocAndTyThingMap
262267
-> HscEnv
263268
-> Position
269+
-> ParsedModule
264270
-> IO (Maybe (Maybe Range, [T.Text]))
265-
atPoint opts@IdeOptions{} shakeExtras@ShakeExtras{ withHieDb, hiedbWriter } har@(HAR _ (hf :: HieASTs a) rf _ (kind :: HieKind hietype)) (DKMap dm km _am) env pos =
271+
atPoint opts@IdeOptions{} shakeExtras@ShakeExtras{ withHieDb, hiedbWriter } har@(HAR _ (hf :: HieASTs a) rf _ (kind :: HieKind hietype)) (DKMap dm km _am) env pos parsedModule =
266272
listToMaybe <$> sequence (pointCommand hf pos hoverInfo)
267273
where
268274
-- Hover info for values/data
@@ -282,6 +288,9 @@ atPoint opts@IdeOptions{} shakeExtras@ShakeExtras{ withHieDb, hiedbWriter } har@
282288
prettyNames <- mapM (prettyName locationsMap) names
283289
pure (Just range, prettyNames ++ pTypes locationsMap)
284290
where
291+
enabledExtensions :: Util.EnumSet Extension
292+
enabledExtensions = getExtensionsSet $ parsedModule
293+
285294
pTypes :: M.Map Name Location -> [T.Text]
286295
pTypes locationsMap =
287296
case names of
@@ -318,7 +327,7 @@ atPoint opts@IdeOptions{} shakeExtras@ShakeExtras{ withHieDb, hiedbWriter } har@
318327
let
319328
typeSig = case identType dets of
320329
Just t -> prettyType (Just n) locationsMap t
321-
Nothing -> case safeTyThingType =<< lookupNameEnv km n of
330+
Nothing -> case safeTyThingType (Util.member LinearTypes enabledExtensions) =<< lookupNameEnv km n of
322331
Just kind -> prettyTypeFromType (Just n) locationsMap kind
323332
Nothing -> wrapHaskell (printOutputable n)
324333
definitionLoc = maybeToList (pretty (definedAt n) (prettyPackageName n))

ghcide/src/Development/IDE/Spans/Common.hs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
module Development.IDE.Spans.Common (
66
unqualIEWrapName
7-
, safeTyThingId
87
, safeTyThingType
98
, SpanDoc(..)
109
, SpanDocUris(..)
@@ -39,22 +38,18 @@ import Language.LSP.Protocol.Types
3938
type DocMap = NameEnv SpanDoc
4039
type TyThingMap = NameEnv TyThing
4140
type ArgDocMap = NameEnv (IntMap SpanDoc)
41+
data A = A Word Bool
4242

4343
-- | Shows IEWrappedName, without any modifier, qualifier or unique identifier.
4444
unqualIEWrapName :: IEWrappedName GhcPs -> T.Text
4545
unqualIEWrapName = printOutputable . rdrNameOcc . ieWrappedName
4646

47-
-- From haskell-ide-engine/src/Haskell/Ide/Engine/Support/HieExtras.hs
48-
safeTyThingType :: TyThing -> Maybe Type
49-
safeTyThingType thing
50-
| Just i <- safeTyThingId thing = Just (varType i)
51-
safeTyThingType (ATyCon tycon) = Just (tyConKind tycon)
52-
safeTyThingType _ = Nothing
53-
54-
safeTyThingId :: TyThing -> Maybe Id
55-
safeTyThingId (AnId i) = Just i
56-
safeTyThingId (AConLike (RealDataCon dataCon)) = Just (dataConWrapId dataCon)
57-
safeTyThingId _ = Nothing
47+
safeTyThingType :: Bool -> TyThing -> Maybe Type
48+
safeTyThingType showLinearType (AConLike (RealDataCon dataCon))
49+
= Just (dataConDisplayType showLinearType dataCon)
50+
safeTyThingType _ (AnId i) = Just (varType i)
51+
safeTyThingType _ (ATyCon tycon) = Just (tyConKind tycon)
52+
safeTyThingType _ _ = Nothing
5853

5954
-- Possible documentation for an element in the code
6055
data SpanDoc

0 commit comments

Comments
 (0)