Skip to content

Commit dc8fd6d

Browse files
committed
1. Relax GetDocMap kindMap to get TyThing for more than type variables.
2. Backport isVisibleFunArg
1 parent 193b15a commit dc8fd6d

File tree

4 files changed

+31
-21
lines changed

4 files changed

+31
-21
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ module Development.IDE.GHC.Compat.Core (
407407
field_label,
408408
#endif
409409
groupOrigin,
410+
isVisibleFunArg,
410411
) where
411412

412413
import qualified GHC
@@ -489,6 +490,8 @@ import qualified GHC.Types.SrcLoc as SrcLoc
489490
import GHC.Types.Unique.Supply
490491
import GHC.Types.Var (Var (varName), setTyVarUnique,
491492
setVarUnique)
493+
494+
import qualified GHC.Types.Var as TypesVar
492495
import GHC.Unit.Info (PackageName (..))
493496
import GHC.Unit.Module hiding (ModLocation (..), UnitId,
494497
moduleUnit,
@@ -630,9 +633,18 @@ pattern ExposePackage s a mr <- DynFlags.ExposePackage s a _ mr
630633
pattern ExposePackage s a mr = DynFlags.ExposePackage s a mr
631634
#endif
632635

633-
pattern FunTy :: FunTyFlag -> Type -> Type -> Type
636+
#if __GLASGOW_HASKELL__ >= 906
637+
isVisibleFunArg = TypesVar.isVisibleFunArg
638+
type FunTyFlag = TypesVar.FunTyFlag
639+
#else
640+
isVisibleFunArg VisArg = True
641+
isVisibleFunArg _ = False
642+
type FunTyFlag = TypesVar.AnonArgFlag
643+
#endif
644+
pattern FunTy :: Development.IDE.GHC.Compat.Core.FunTyFlag -> Type -> Type -> Type
634645
pattern FunTy af arg res <- TyCoRep.FunTy {ft_af = af, ft_arg = arg, ft_res = res}
635646

647+
636648
-- type HasSrcSpan x a = (GenLocated SrcSpan a ~ x)
637649
-- type HasSrcSpan x = () :: Constraint
638650

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ mkDocMap env rm this_mod =
6161
doc <- getDocumentationTryGhc env n
6262
pure $ extendNameEnv nameMap n doc
6363
getType n nameMap
64-
| isTcOcc $ occName n
65-
, Nothing <- lookupNameEnv nameMap n
64+
| Nothing <- lookupNameEnv nameMap n
6665
= do kind <- lookupKind env n
6766
pure $ maybe nameMap (extendNameEnv nameMap n) kind
6867
| otherwise = pure nameMap

plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Internal.hs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
{-# LANGUAGE ScopedTypeVariables #-}
1414
{-# LANGUAGE TupleSections #-}
1515
{-# LANGUAGE TypeFamilies #-}
16-
{-# LANGUAGE ViewPatterns #-}
1716

1817
-- |
1918
-- This module provides the core functionality of the plugin.
@@ -28,24 +27,22 @@ import qualified Data.Map as Map
2827
import Data.Maybe (listToMaybe, mapMaybe)
2928
import qualified Data.Text as T
3029
import Development.IDE (Action,
30+
GetDocMap (GetDocMap),
3131
GetHieAst (GetHieAst),
32-
GhcSessionDeps (GhcSessionDeps),
3332
HieAstResult (HAR, hieAst, hieModule, refMap),
3433
IdeState, Priority (..),
3534
Recorder, Rules,
3635
WithPriority,
37-
catchSrcErrors,
3836
cmapWithPrio, define,
3937
hieKind, ideLogger,
4038
logPriority, use_)
41-
import Development.IDE.Core.Compile (lookupName)
4239
import Development.IDE.Core.PluginUtils (runActionE,
4340
useWithStaleE)
4441
import Development.IDE.Core.PositionMapping (idDelta, toCurrentRange)
4542
import Development.IDE.Core.Rules (Log (LogShake))
43+
import Development.IDE.Core.RuleTypes (DocAndKindMap (..))
4644
import Development.IDE.Core.Shake (addPersistentRule)
4745
import Development.IDE.GHC.Compat
48-
import Development.IDE.Types.HscEnvEq (hscEnv)
4946
import Ide.Plugin.Error (PluginError (PluginInternalError),
5047
getNormalizedFilePathE)
5148
import Ide.Plugin.SemanticTokens.Mappings
@@ -93,30 +90,33 @@ semanticTokensFull state _ param = do
9390
getSemanticTokensRule :: Recorder (WithPriority Log) -> Rules ()
9491
getSemanticTokensRule recorder =
9592
define (cmapWithPrio LogShake recorder) $ \GetSemanticTokens nfp -> do
96-
(hscEnv -> hsc) <- use_ GhcSessionDeps nfp
93+
-- (hscEnv -> hsc) <- use_ GhcSessionDeps nfp
9794
(HAR {..}) <- use_ GetHieAst nfp
95+
(DKMap{getKindMap}) <- use_ GetDocMap nfp
9896
Just (_, ast) <- return $ listToMaybe $ Map.toList $ getAsts hieAst
9997
-- get current location from the old ones
10098
let spanNamesMap = hieAstSpanNames ast
10199
let names = nameSetElemsStable $ unionNameSets $ Map.elems spanNamesMap
102100
let localSemanticMap = mkLocalNameSemanticFromAst names (hieKindFunMasksKind hieKind) refMap
103101
-- get imported name semantic map
104102
-- liftIO $ putStrLn $ unlines $ fmap showClearName $ nameSetElemsStable nameSet
105-
importedNameSemanticMap <- liftIO $ foldrM (getTypeExclude localSemanticMap hsc) emptyNameEnv names
103+
let importedNameSemanticMap = foldr (getTypeExclude localSemanticMap getKindMap) emptyNameEnv names
106104
-- let importedNameSemanticMap = computeImportedNameSemanticMap $ nameSetElemsStable nameSet
107105
let sMap = plusNameEnv_C (<>) importedNameSemanticMap localSemanticMap
108106
let rangeTokenType = extractSemanticTokensFromNames sMap spanNamesMap
109107
return ([], Just $ RangeHsSemanticTokenTypes rangeTokenType)
110108
where
111109
-- ignore one already in discovered in local
112-
getTypeExclude localEnv env n nameMap
113-
| n `elemNameEnv` localEnv = pure nameMap
110+
getTypeExclude :: NameEnv a
111+
-> NameEnv TyThing
112+
-> Name
113+
-> NameEnv HsSemanticTokenType
114+
-> NameEnv HsSemanticTokenType
115+
getTypeExclude localEnv kindMap n nameMap
116+
| n `elemNameEnv` localEnv = nameMap
114117
| otherwise =
115-
do
116-
tyThing <- lookupImported env n
117-
pure $ maybe nameMap (extendNameEnv nameMap n) (tyThing >>= tyThingSemantic)
118-
lookupImported :: HscEnv -> Name -> IO (Maybe TyThing)
119-
lookupImported env = fmap (fromRight Nothing) . catchSrcErrors (hsc_dflags env) "span" . lookupName env
118+
let tyThing = lookupNameEnv kindMap n in
119+
maybe nameMap (extendNameEnv nameMap n) (tyThing >>= tyThingSemantic)
120120

121121
-- | Persistent rule to ensure that semantic tokens doesn't block on startup
122122
persistentGetSemanticTokensRule :: Rules ()

plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Mappings.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,11 @@ tyThingSemantic ty = case ty of
8989

9090
isFunType :: Type -> Bool
9191
isFunType a = case a of
92-
ForAllTy _ t -> isFunType t
92+
ForAllTy _ t -> isFunType t
9393
-- Development.IDE.GHC.Compat.Core.FunTy(pattern synonym), FunTyFlag which is used to distinguish
9494
-- (->, =>, etc..)
95-
FunTy FTF_T_T _ _ -> True
96-
FunTy _ _ rhs -> isFunType rhs
97-
_x -> isFunTy a
95+
FunTy flg _ rhs-> if isVisibleFunArg flg then True else isFunType rhs
96+
_x -> isFunTy a
9897

9998
hieKindFunMasksKind :: HieKind a -> HieFunMaskKind a
10099
hieKindFunMasksKind hieKind = case hieKind of

0 commit comments

Comments
 (0)