File tree 4 files changed +36
-1
lines changed
plugins/hls-semantic-tokens-plugin
src/Ide/Plugin/SemanticTokens
4 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -81,14 +81,21 @@ tyThingSemantic ty = case ty of
81
81
isFunVar :: Var -> Bool
82
82
isFunVar var = isFunType $ varType var
83
83
84
+ -- expand the type synonym https://hackage.haskell.org/package/ghc-9.8.1/docs/src/GHC.Core.Type.html
85
+ expandTypeSyn :: Type -> Type
86
+ expandTypeSyn ty
87
+ | Just ty' <- coreView ty = expandTypeSyn ty'
88
+ | otherwise = ty
89
+
84
90
isFunType :: Type -> Bool
85
- isFunType a = case a of
91
+ isFunType a = case expandTypeSyn a of
86
92
ForAllTy _ t -> isFunType t
87
93
-- Development.IDE.GHC.Compat.Core.FunTy(pattern synonym), FunTyFlag which is used to distinguish
88
94
-- (->, =>, etc..)
89
95
FunTy flg _ rhs -> isVisibleFunArg flg || isFunType rhs
90
96
_x -> isFunTy a
91
97
98
+
92
99
hieKindFunMasksKind :: HieKind a -> HieFunMaskKind a
93
100
hieKindFunMasksKind hieKind = case hieKind of
94
101
HieFresh -> HieFreshFun
@@ -119,6 +126,7 @@ recoverFunMaskArray flattened = unflattened
119
126
go (HQualTy _constraint b) = b
120
127
go (HCastTy b) = b
121
128
go HCoercionTy = False
129
+ -- we have no enough information to expand the type synonym
122
130
go (HTyConApp _ _) = False
123
131
124
132
typeSemantic :: HieFunMaskKind hType -> hType -> Maybe HsSemanticTokenType
Original file line number Diff line number Diff line change @@ -215,6 +215,7 @@ semanticTokensFunctionTests =
215
215
" get semantic of functions"
216
216
[ goldenWithSemanticTokensWithDefaultConfig " functions" " TFunction" ,
217
217
goldenWithSemanticTokensWithDefaultConfig " local functions" " TFunctionLocal" ,
218
+ goldenWithSemanticTokensWithDefaultConfig " functions under type synonym" " TFunctionUnderTypeSynonym" ,
218
219
goldenWithSemanticTokensWithDefaultConfig " function in let binding" " TFunctionLet" ,
219
220
goldenWithSemanticTokensWithDefaultConfig " negative case non-function with constraint" " TNoneFunctionWithConstraint"
220
221
]
Original file line number Diff line number Diff line change
1
+ 3:6-8 TTypeSynonym "T1"
2
+ 3:11-14 TTypeConstructor "Int"
3
+ 3:18-21 TTypeConstructor "Int"
4
+ 4:6-8 TTypeSynonym "T2"
5
+ 4:18-19 TTypeVariable "a"
6
+ 4:21-22 TTypeVariable "a"
7
+ 4:26-27 TTypeVariable "a"
8
+ 5:1-3 TFunction "f1"
9
+ 5:7-9 TTypeSynonym "T1"
10
+ 6:1-3 TFunction "f1"
11
+ 6:4-5 TVariable "x"
12
+ 6:8-9 TVariable "x"
13
+ 7:1-3 TFunction "f2"
14
+ 7:7-9 TTypeSynonym "T2"
15
+ 8:1-3 TFunction "f2"
16
+ 8:4-5 TVariable "x"
17
+ 8:8-9 TVariable "x"
Original file line number Diff line number Diff line change
1
+ module TFunctionUnderTypeSynonym where
2
+
3
+ type T1 = Int -> Int
4
+ type T2 = forall a . a -> a
5
+ f1 :: T1
6
+ f1 x = x
7
+ f2 :: T2
8
+ f2 x = x
9
+
You can’t perform that action at this time.
0 commit comments