Skip to content

Commit 800f908

Browse files
committed
Show signature help even when there are type applications
1 parent 3d7a67b commit 800f908

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

plugins/hls-signature-help-plugin/src/Ide/Plugin/SignatureHelp.hs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -291,19 +291,23 @@ getNodeNameAndTypes hieKind hieAst =
291291
isUse :: IdentifierDetails a -> Bool
292292
isUse = identInfo >>> S.member Use
293293

294+
-- TODO(@linj) handle more cases
294295
-- Just 1 means the first argument
295296
getArgumentNumber :: RealSrcSpan -> HieAST a -> Maybe Integer
296-
getArgumentNumber span hieAst =
297-
if nodeHasAnnotation ("HsApp", "HsExpr") hieAst
298-
then
299-
case nodeChildren hieAst of
300-
[leftChild, _] ->
301-
if span `isRealSubspanOf` nodeSpan leftChild
302-
then Nothing
303-
else getArgumentNumber span leftChild >>= \argumentNumber -> Just (argumentNumber + 1)
304-
_ -> Nothing -- impossible
305-
else
306-
case nodeChildren hieAst of
307-
[] -> Just 0 -- the function is found
308-
[child] -> getArgumentNumber span child -- ignore irrelevant nodes
309-
_ -> Nothing -- TODO(@linj) handle more cases such as `if`
297+
getArgumentNumber span hieAst
298+
| nodeHasAnnotation ("HsApp", "HsExpr") hieAst =
299+
case nodeChildren hieAst of
300+
[leftChild, _] ->
301+
if span `isRealSubspanOf` nodeSpan leftChild
302+
then Nothing
303+
else getArgumentNumber span leftChild >>= \argumentNumber -> Just (argumentNumber + 1)
304+
_ -> Nothing -- impossible
305+
| nodeHasAnnotation ("HsAppType", "HsExpr") hieAst =
306+
case nodeChildren hieAst of
307+
[leftChild, _] -> getArgumentNumber span leftChild
308+
_ -> Nothing -- impossible
309+
| otherwise =
310+
case nodeChildren hieAst of
311+
[] -> Just 0 -- the function is found
312+
[child] -> getArgumentNumber span child -- ignore irrelevant nodes
313+
_ -> Nothing

plugins/hls-signature-help-plugin/test/Main.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,19 @@ main =
336336
|]
337337
[ Nothing,
338338
Just $ SignatureHelp [SignatureInformation "mkBytes :: ForeignPtr Word8 -> Word -> Word -> Bytes" (Just $ InR $ MarkupContent MarkupKind_Markdown "\n\nCreate a Bytes datatype representing raw bytes to be embedded into the\n program/library binary.\n\n\\[Documentation\\]\\(file://.*\\)\n\n\\[Source\\]\\(file://.*\\)\n\n") (Just [ParameterInformation (InR (11,27)) (Just $ InR $ MarkupContent MarkupKind_Markdown "\n\nPointer to the data\n\n"), ParameterInformation (InR (31,35)) (Just $ InR $ MarkupContent MarkupKind_Markdown "\n\nOffset from the pointer\n\n"), ParameterInformation (InR (39,43)) (Just $ InR $ MarkupContent MarkupKind_Markdown "\n\nNumber of bytes\n\n")]) (Just (InL 0))] (Just 0) (Just (InL 0))
339+
],
340+
mkTest
341+
"TypeApplications"
342+
[trimming|
343+
f :: a -> b -> c
344+
f = _
345+
x = f @Int @_ 1 True
346+
^ ^ ^ ^
347+
|]
348+
[ Nothing,
349+
Nothing,
350+
Nothing,
351+
Just $ SignatureHelp [SignatureInformation "f :: forall a b c. a -> b -> c" Nothing (Just [ParameterInformation (InR (19,20)) Nothing, ParameterInformation (InR (24,25)) Nothing]) (Just (InL 0))] (Just 0) (Just (InL 0))
339352
]
340353
]
341354

0 commit comments

Comments
 (0)