@@ -62,38 +62,43 @@ constructFromAst nfp pos =
62
62
\ case
63
63
Nothing -> pure Nothing
64
64
Just (HAR _ hf _ _ _) -> do
65
- case listToMaybe $ pointCommand hf pos extract of
66
- Just res -> pure $ Just $ mapMaybe (construct nfp) res
67
- Nothing -> pure Nothing
65
+ resolveIntoCallHierarchy hf pos nfp
66
+
67
+ resolveIntoCallHierarchy :: Applicative f => HieASTs a -> Position -> NormalizedFilePath -> f (Maybe [CallHierarchyItem ])
68
+ resolveIntoCallHierarchy hf pos nfp =
69
+ case listToMaybe $ pointCommand hf pos extract of
70
+ Just res -> pure $ Just $ mapMaybe (construct nfp hf) res
71
+ Nothing -> pure Nothing
68
72
69
73
extract :: HieAST a -> [(Identifier , S. Set ContextInfo , Span )]
70
74
extract ast = let span = nodeSpan ast
71
75
infos = M. toList $ M. map identInfo (Compat. getNodeIds ast)
72
76
in [ (ident, contexts, span ) | (ident, contexts) <- infos ]
73
77
74
78
recFieldInfo, declInfo, valBindInfo, classTyDeclInfo,
75
- useInfo , patternBindInfo :: S. Set ContextInfo -> Maybe ContextInfo
76
- recFieldInfo ctxs = listToMaybe [ctx | ctx@ RecField {} <- S. toList ctxs]
77
- declInfo ctxs = listToMaybe [ctx | ctx@ Decl {} <- S. toList ctxs]
78
- valBindInfo ctxs = listToMaybe [ctx | ctx@ ValBind {} <- S. toList ctxs]
79
- classTyDeclInfo ctxs = listToMaybe [ctx | ctx@ ClassTyDecl {} <- S. toList ctxs]
80
- useInfo ctxs = listToMaybe [Use | Use <- S. toList ctxs]
81
- patternBindInfo ctxs = listToMaybe [ctx | ctx@ PatternBind {} <- S. toList ctxs]
82
-
83
- construct :: NormalizedFilePath -> (Identifier , S. Set ContextInfo , Span ) -> Maybe CallHierarchyItem
84
- construct nfp (ident, contexts, ssp)
79
+ useInfo , patternBindInfo , tyDeclInfo :: [ContextInfo ] -> Maybe ContextInfo
80
+ recFieldInfo ctxs = listToMaybe [ctx | ctx@ RecField {} <- ctxs]
81
+ declInfo ctxs = listToMaybe [ctx | ctx@ Decl {} <- ctxs]
82
+ valBindInfo ctxs = listToMaybe [ctx | ctx@ ValBind {} <- ctxs]
83
+ classTyDeclInfo ctxs = listToMaybe [ctx | ctx@ ClassTyDecl {} <- ctxs]
84
+ useInfo ctxs = listToMaybe [Use | Use <- ctxs]
85
+ patternBindInfo ctxs = listToMaybe [ctx | ctx@ PatternBind {} <- ctxs]
86
+ tyDeclInfo ctxs = listToMaybe [TyDecl | TyDecl <- ctxs]
87
+
88
+ construct :: NormalizedFilePath -> HieASTs a -> (Identifier , S. Set ContextInfo , Span ) -> Maybe CallHierarchyItem
89
+ construct nfp hf (ident, contexts, ssp)
85
90
| isInternalIdentifier ident = Nothing
86
91
87
- | Just (RecField RecFieldDecl _) <- recFieldInfo contexts
92
+ | Just (RecField RecFieldDecl _) <- recFieldInfo ctxList
88
93
-- ignored type span
89
94
= Just $ mkCallHierarchyItem' ident SkField ssp ssp
90
95
91
- | Just ctx <- valBindInfo contexts
96
+ | Just ctx <- valBindInfo ctxList
92
97
= Just $ case ctx of
93
98
ValBind _ _ span -> mkCallHierarchyItem' ident SkFunction (renderSpan span ) ssp
94
99
_ -> mkCallHierarchyItem' ident skUnknown ssp ssp
95
100
96
- | Just ctx <- declInfo contexts
101
+ | Just ctx <- declInfo ctxList
97
102
= Just $ case ctx of
98
103
Decl ClassDec span -> mkCallHierarchyItem' ident SkInterface (renderSpan span ) ssp
99
104
Decl ConDec span -> mkCallHierarchyItem' ident SkConstructor (renderSpan span ) ssp
@@ -103,15 +108,18 @@ construct nfp (ident, contexts, ssp)
103
108
Decl SynDec span -> mkCallHierarchyItem' ident SkTypeParameter (renderSpan span ) ssp
104
109
_ -> mkCallHierarchyItem' ident skUnknown ssp ssp
105
110
106
- | Just (ClassTyDecl span ) <- classTyDeclInfo contexts
111
+ | Just (ClassTyDecl span ) <- classTyDeclInfo ctxList
107
112
= Just $ mkCallHierarchyItem' ident SkMethod (renderSpan span ) ssp
108
113
109
- | Just (PatternBind _ _ span ) <- patternBindInfo contexts
114
+ | Just (PatternBind _ _ span ) <- patternBindInfo ctxList
110
115
= Just $ mkCallHierarchyItem' ident SkFunction (renderSpan span ) ssp
111
116
112
- | Just Use <- useInfo contexts
117
+ | Just Use <- useInfo ctxList
113
118
= Just $ mkCallHierarchyItem' ident SkInterface ssp ssp
114
119
120
+ | Just _ <- tyDeclInfo ctxList
121
+ = renderTyDecl
122
+
115
123
| otherwise = Nothing
116
124
where
117
125
renderSpan = \ case Just span -> span
@@ -125,6 +133,16 @@ construct nfp (ident, contexts, ssp)
125
133
Left _ -> False
126
134
Right name -> isInternalName name
127
135
136
+ ctxList = S. toList contexts
137
+
138
+ renderTyDecl = case ident of
139
+ Left _ -> Nothing
140
+ Right name -> case getNameBindingInClass name ssp (getAsts hf) of
141
+ Nothing -> Nothing
142
+ Just sp -> case resolveIntoCallHierarchy hf (realSrcSpanToRange sp ^. L. start) nfp of
143
+ Just (Just items) -> listToMaybe items
144
+ _ -> Nothing
145
+
128
146
mkCallHierarchyItem :: NormalizedFilePath -> Identifier -> SymbolKind -> Span -> Span -> CallHierarchyItem
129
147
mkCallHierarchyItem nfp ident kind span selSpan =
130
148
CallHierarchyItem
0 commit comments