Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -29,6 +30,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,
Expand All @@ -48,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)
Expand Down Expand Up @@ -294,12 +297,23 @@ 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
Comment on lines +300 to +303
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jian-lin This should take care of lookup to generated nodes on fallback for identifier details.

-- types from the source NodeInfo
Comment thread
vidit-od marked this conversation as resolved.
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
Expand Down
17 changes: 17 additions & 0 deletions plugins/hls-signature-help-plugin/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,23 @@ 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
Comment thread
vidit-od marked this conversation as resolved.
^
print (f x 2)
^ ^
|]
[ 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))
]
]

Expand Down
Loading