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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nitpicking:

The existing import style of this file is explicit. I think it's a good idea to follow that.

Suggested change
import Control.Applicative
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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

For some identifier, are Identifiers of SourceInfo and GeneratedInfo the same? In other words, does this M.lookup always return Nothing?

Needs to verify.

identType details
Comment thread
jian-lin marked this conversation as resolved.
Comment on lines +300 to +303

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@vidit-od Can we extract this do block into a function with some documentation?

-- types from the source NodeInfo
Comment thread
vidit-od marked this conversation as resolved.
typesOfNode = case sourceNodeInfo hieAst of

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The fallback logic is:

  • get mTypeOfName from SourceInfo or GeneratedInfo
  • get typesOfNode from SourceInfo or GeneratedInfo

The current implementation uses two separated checks for mTypeOfName and typesOfNode. Alternatively, we can use only one check for both mTypeOfName and typesOfNode. Which way is better needs further investigation.

Nothing -> []
Just nodeInfo -> nodeType nodeInfo
-- fall back to generated NodeInfo when source has no types
Comment on lines +304 to +308

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The comment is kind of confusing: it comes too late because mTypeOfName also has the fallback logic.

I think we should move the comment to the top of the let block.

typesOfGeneratedNode = case generatedNodeInfo hieAst of
Nothing -> []
Just nodeInfo -> nodeType nodeInfo
allTypes = case mTypeOfName of
Nothing -> typesOfNode
Nothing ->
case typesOfNode of
[] -> typesOfGeneratedNode
ts -> ts
Comment on lines -302 to +316

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

blocking:

This handles the fallback of typesOfNode. The fallback should be done in all cases. However, currently, it is only done in the Nothing case, but not the Just case.

I would handle the fallback in one place before allTypes and keep the allTypes code unchanged.

-- (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