Skip to content

Explicit Records Plugin's (in some scenarios) codeAction doesn't work #3559

Open
@joyfulmantis

Description

@joyfulmantis

Your environment

Which OS do you use?
Fedora 38

Which version of GHC do you use, and how did you install it?
9.4.4 from GHCup

Which LSP client (editor/plugin) do you use?
VS Code 1.77.3+vscode-haskell

Which version of HLS do you use and how did you install it?
hls-1.10.0.0 from GHCup

Have you configured HLS in any way (especially: a hie.yaml file)?
no

Steps to reproduce

I can reproduce this bug in VS Code with the following code by clicking on the record wildcards and then following the code action to expand them.

{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedRecordDot #-}

data Happy = Happy {name :: String, age :: Int, happy :: Bool}

main :: IO ()
main = do 
    putStrLn test4

test1 Happy {..}= name

test4 = name man

man :: Happy
man = Happy {name = "Happy", age = 1, happy = True}

Expected behaviour

I expect the codeAction to modify the code.

Actual behaviour

However, nothing happens.

Debug information

I have traced the messages between the hls server and vscode, and the codeAction seems to be fine, but for some reason it won't execute.

Result: [
    {
        "edit": {
            "changes": {
                "file:///[retracted]/Test.hs": [
                    {
                        "newText": "Happy {name}",
                        "range": {
                            "end": {
                                "character": 16,
                                "line": 10
                            },
                            "start": {
                                "character": 6,
                                "line": 10
                            }
                        }
                    }
                ]
            }
        },
        "kind": "refactor.rewrite",
        "title": "Expand record wildcard"
    }
]

This is especially puzzling because small changes in the program cause it to work, just this specific code doesn't.
For example, slightly modifying it so that test1 and test4 switch places causes it to work.

{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedRecordDot #-}

data Happy = Happy {name :: String, age :: Int, happy :: Bool}

main :: IO ()
main = do 
    putStrLn test4

test4 = name man

test1 Happy {..} = name

man :: Happy
man = Happy {name = "Happy", age = 1, happy = True}

Looking at the codeAction that works, it is almost identical.

Result: [
    {
        "edit": {
            "changes": {
                "file://[retracted]/Test.hs": [
                    {
                        "newText": "Happy {name}",
                        "range": {
                            "end": {
                                "character": 16,
                                "line": 12
                            },
                            "start": {
                                "character": 6,
                                "line": 12
                            }
                        }
                    }
                ]
            }
        },
        "kind": "refactor.rewrite",
        "title": "Expand record wildcard"
    }
]

Metadata

Metadata

Assignees

Labels

component: hls-explicit-record-fields-pluginIssues related to the hls-explicit-record-fields-plugintype: bugSomething isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions