From 85b02d3bc48f6354418e8fdcb2b9f5dc7a591748 Mon Sep 17 00:00:00 2001 From: vidit-od Date: Sun, 19 Apr 2026 16:23:21 +0530 Subject: [PATCH 1/4] Traverse Generated Nodes Some nodes have there type info stored in nodes generated by ghc. In case no type info found in source node, fall back to traversing ghc generated nodes for types Signed-off-by: vidit-od --- .../src/Ide/Plugin/SignatureHelp.hs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/hls-signature-help-plugin/src/Ide/Plugin/SignatureHelp.hs b/plugins/hls-signature-help-plugin/src/Ide/Plugin/SignatureHelp.hs index e8ac3cac0d..73e77a062c 100644 --- a/plugins/hls-signature-help-plugin/src/Ide/Plugin/SignatureHelp.hs +++ b/plugins/hls-signature-help-plugin/src/Ide/Plugin/SignatureHelp.hs @@ -29,6 +29,7 @@ import Development.IDE.Core.PluginUtils (runIdeActionE, import Development.IDE.Core.PositionMapping (fromCurrentPosition) import Development.IDE.GHC.Compat (FastStringCompat, Name, RealSrcSpan, + generatedNodeInfo, getSourceNodeIds, isAnnotationInNodeInfo, mkRealSrcLoc, @@ -295,11 +296,19 @@ getNodeNameAndTypes hieKind hieAst = Nothing -> Nothing Just name -> let mTypeOfName = identType identifierDetails + -- types from the source NodeInfo typesOfNode = case sourceNodeInfo hieAst of Nothing -> [] Just nodeInfo -> nodeType nodeInfo + -- fall back to generated NodeInfo when source has no types + typesOfGeneratedNode = case generatedNodeInfo hieAst of + Nothing -> [] + Just nodeInfo -> nodeType nodeInfo allTypes = case mTypeOfName of - Nothing -> typesOfNode + Nothing -> + case typesOfNode of + [] -> typesOfGeneratedNode + ts -> ts -- (the last?) one type of 'typesOfNode' may (always?) be the same as 'typeOfName' -- To avoid generating two identical signature helps, we do a filtering here -- This is similar to 'dropEnd1' in Development.IDE.Spans.AtPoint.atPoint From e108151802f9cf74599bb667bf4acbf7cde959a3 Mon Sep 17 00:00:00 2001 From: vidit-od Date: Tue, 21 Apr 2026 12:10:33 +0530 Subject: [PATCH 2/4] Add regression tests Signed-off-by: vidit-od --- plugins/hls-signature-help-plugin/test/Main.hs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/plugins/hls-signature-help-plugin/test/Main.hs b/plugins/hls-signature-help-plugin/test/Main.hs index 9e3b0c0ea3..733b34e357 100644 --- a/plugins/hls-signature-help-plugin/test/Main.hs +++ b/plugins/hls-signature-help-plugin/test/Main.hs @@ -381,6 +381,21 @@ main = Nothing, Nothing, Just $ SimilarSignatureHelp $ 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)) + ], + -- Prevents https://github.com/haskell/haskell-language-server/issues/4769 + mkTest + "inside do block" + [__i| + f :: Int -> Int -> Int + f = _ + test :: IO () + test = do + x <- pure 1 + print (f x 2) + ^ ^ + |] + [ Just $ SimilarSignatureHelp $ SignatureHelp [SignatureInformation "f :: Int -> Int -> Int" Nothing (Just [ParameterInformation (InR (5, 8)) Nothing, ParameterInformation (InR (12, 15)) Nothing]) (Just (InL 0))] (Just 0) (Just (InL 0)), + Just $ SimilarSignatureHelp $ SignatureHelp [SignatureInformation "f :: Int -> Int -> Int" Nothing (Just [ParameterInformation (InR (5, 8)) Nothing, ParameterInformation (InR (12, 15)) Nothing]) (Just (InL 1))] (Just 0) (Just (InL 1)) ] ] From 9344a715facf6cbbba6711a3ef89d24fa69dc5bd Mon Sep 17 00:00:00 2001 From: vidit-od Date: Fri, 1 May 2026 13:48:15 +0530 Subject: [PATCH 3/4] Add one more regression test Signed-off-by: vidit-od --- plugins/hls-signature-help-plugin/test/Main.hs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/hls-signature-help-plugin/test/Main.hs b/plugins/hls-signature-help-plugin/test/Main.hs index 733b34e357..0881f12c52 100644 --- a/plugins/hls-signature-help-plugin/test/Main.hs +++ b/plugins/hls-signature-help-plugin/test/Main.hs @@ -391,10 +391,12 @@ main = test :: IO () test = do x <- pure 1 + ^ print (f x 2) ^ ^ |] - [ Just $ SimilarSignatureHelp $ SignatureHelp [SignatureInformation "f :: Int -> Int -> Int" Nothing (Just [ParameterInformation (InR (5, 8)) Nothing, ParameterInformation (InR (12, 15)) Nothing]) (Just (InL 0))] (Just 0) (Just (InL 0)), + [ Just $ SimilarSignatureHelp $ SignatureHelp [SignatureInformation "pure :: forall (f :: Type -> Type) a. Applicative f => a -> f a" (Just $ InR $ MarkupContent MarkupKind_Markdown "Lift a value") (Just [ParameterInformation (InR (55,56)) Nothing]) (Just (InL 0)), SignatureInformation "pure :: Int -> IO Int" (Just $ InR $ MarkupContent MarkupKind_Markdown "Lift a value") (Just [ParameterInformation (InR (8,11)) Nothing]) (Just (InL 0)), SignatureInformation "pure :: forall a. a -> IO a" (Just $ InR $ MarkupContent MarkupKind_Markdown "Lift a value") (Just [ParameterInformation (InR (18,19)) Nothing]) (Just (InL 0))] (Just 0) (Just (InL 0)), + Just $ SimilarSignatureHelp $ SignatureHelp [SignatureInformation "f :: Int -> Int -> Int" Nothing (Just [ParameterInformation (InR (5, 8)) Nothing, ParameterInformation (InR (12, 15)) Nothing]) (Just (InL 0))] (Just 0) (Just (InL 0)), Just $ SimilarSignatureHelp $ SignatureHelp [SignatureInformation "f :: Int -> Int -> Int" Nothing (Just [ParameterInformation (InR (5, 8)) Nothing, ParameterInformation (InR (12, 15)) Nothing]) (Just (InL 1))] (Just 0) (Just (InL 1)) ] ] From 20e9d05b1fc586c09e0ae9851a4d6361f3d76b16 Mon Sep 17 00:00:00 2001 From: vidit-od Date: Fri, 1 May 2026 17:19:57 +0530 Subject: [PATCH 4/4] Handle identifier info If source -> identifier info -> details == Nothing, then we fallback to generated by ghc node and explore generated by ghc -> identifier info -> details Signed-off-by: vidit-od --- .../src/Ide/Plugin/SignatureHelp.hs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/hls-signature-help-plugin/src/Ide/Plugin/SignatureHelp.hs b/plugins/hls-signature-help-plugin/src/Ide/Plugin/SignatureHelp.hs index 73e77a062c..3d60af9a56 100644 --- a/plugins/hls-signature-help-plugin/src/Ide/Plugin/SignatureHelp.hs +++ b/plugins/hls-signature-help-plugin/src/Ide/Plugin/SignatureHelp.hs @@ -4,6 +4,7 @@ module Ide.Plugin.SignatureHelp (descriptor) where +import Control.Applicative import Control.Arrow ((>>>)) import Control.Monad.Trans.Except (ExceptT (ExceptT)) import Data.Bifunctor (bimap) @@ -49,6 +50,7 @@ import GHC.Iface.Ext.Types (ContextInfo (Use), HieAST (nodeChildren, nodeSpan), HieASTs (getAsts), IdentifierDetails (identInfo, identType), + NodeInfo (nodeIdentifiers), nodeType) import GHC.Iface.Ext.Utils (smallestContainingSatisfying) import GHC.Types.Name.Env (lookupNameEnv) @@ -295,7 +297,10 @@ getNodeNameAndTypes hieKind hieAst = case extractName identifier of Nothing -> Nothing Just name -> - let mTypeOfName = identType identifierDetails + let mTypeOfName = identType identifierDetails <|> do + nodeInfo <- generatedNodeInfo hieAst + details <- M.lookup identifier (nodeIdentifiers nodeInfo) + identType details -- types from the source NodeInfo typesOfNode = case sourceNodeInfo hieAst of Nothing -> []