Skip to content

Fix Signature Help inside do Notation in GHC >= 9.10#4904

Open
vidit-od wants to merge 4 commits into
haskell:masterfrom
vidit-od:Do-Signature-Traversal
Open

Fix Signature Help inside do Notation in GHC >= 9.10#4904
vidit-od wants to merge 4 commits into
haskell:masterfrom
vidit-od:Do-Signature-Traversal

Conversation

@vidit-od

@vidit-od vidit-od commented Apr 19, 2026

Copy link
Copy Markdown
Collaborator

Closes : #4769

As recommended, Type information of Some nodes were stored in GHC generated nodes.
This PR keeps the old pipeline and add a Fall back to traverse these generated nodes in case source node lack type information.

Attached image of signature help in cases where we did not get them before;
image

Prerequisite :

  • passes all hls-signature-help-plugin tests on GHC 9.12.2 :
image
Major Finding credits : @jian-lin

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 <vidit894@gmail.com>
@vidit-od vidit-od requested review from fendor and jian-lin April 19, 2026 11:06
@vidit-od vidit-od changed the title Traverse Generated Nodes Fix Signature Help inside do Notation Apr 19, 2026

@jian-lin jian-lin left a comment

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.

Looks good. I'll do a more careful review later.

In the meantime, it would be good to add a test case for the issue.

Signed-off-by: vidit-od <vidit894@gmail.com>
@vidit-od vidit-od requested a review from jian-lin April 21, 2026 06:41
Comment thread plugins/hls-signature-help-plugin/test/Main.hs
@fendor

fendor commented Apr 30, 2026

Copy link
Copy Markdown
Collaborator

@jian-lin I think this is ready for a review now

@fendor fendor added the status: needs review This PR is ready for review label Apr 30, 2026
Comment thread plugins/hls-signature-help-plugin/test/Main.hs Outdated
Comment thread plugins/hls-signature-help-plugin/test/Main.hs Outdated
Comment thread plugins/hls-signature-help-plugin/src/Ide/Plugin/SignatureHelp.hs
@jian-lin jian-lin changed the title Fix Signature Help inside do Notation Fix Signature Help inside do Notation in GHC >= 9.10 Apr 30, 2026
Signed-off-by: vidit-od <vidit894@gmail.com>
@vidit-od vidit-od force-pushed the Do-Signature-Traversal branch from c891a41 to 9344a71 Compare May 1, 2026 08:21
@vidit-od vidit-od requested review from fendor and jian-lin May 1, 2026 11:44
@vidit-od vidit-od force-pushed the Do-Signature-Traversal branch from 6c39a93 to 20e9d05 Compare May 1, 2026 11:49
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 <vidit894@gmail.com>
Comment thread plugins/hls-signature-help-plugin/src/Ide/Plugin/SignatureHelp.hs
@fendor

fendor commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

@jian-lin I think this is waiting on a re-review from you

@fendor fendor left a comment

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.

LGTM, thank you very much!

Comment on lines +300 to +303
let mTypeOfName = identType identifierDetails <|> do
nodeInfo <- generatedNodeInfo hieAst
details <- M.lookup identifier (nodeIdentifiers nodeInfo)
identType details

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?

@jian-lin

jian-lin commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the reminder. I can have a look later today or tomorrow.

@jian-lin jian-lin left a comment

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.

I need more time for further investigation, but I think I should post what I have now.


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

Comment on lines -302 to +316
Nothing -> typesOfNode
Nothing ->
case typesOfNode of
[] -> typesOfGeneratedNode
ts -> ts

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.

Comment on lines +304 to +308
-- 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

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.

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.

details <- M.lookup identifier (nodeIdentifiers nodeInfo)
identType details
-- types from the source NodeInfo
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.

@fendor fendor removed the status: needs review This PR is ready for review label Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Signature Help should provide signature in the do notation

3 participants