Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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 @@ -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,
Expand Down Expand Up @@ -295,11 +296,19 @@ getNodeNameAndTypes hieKind hieAst =
Nothing -> Nothing
Just name ->
let mTypeOfName = identType identifierDetails
-- 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
15 changes: 15 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,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
Comment thread
vidit-od marked this conversation as resolved.
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))
]
]

Expand Down
Loading