Skip to content

"Add to import list" fails to add constructor import to type import when they're named the same.Β #1768

Closed
@zmrocze

Description

@zmrocze

Steps to reproduce

Minimum working example:

module A where
newtype Foo = Foo Int
module B where
import A (Foo)
f :: Foo
f = Foo 1

Expected behaviour

Data constructor Foo in f = Foo 1 is correctly underlined with red as 'Foo' constructor is not in scope. Clicking ctrl+. opens code actions tab. I would expect to find there action "Add Foo(Foo) to the import list of A." that would append to type import also constructor import.

Actual behaviour

Only available code action is "Add Foo to the import list of A.". This action doesn't change the import.
If the constructor name is different from the type name the code action shows properly and works as expected (that is action "Add Foo(MakeFoo) to the import list of A" shows up and works).
The problem also exist if we use data instead of newtype.

Include debug information

LSP logs:

Logs when I click ctrl+. showing code actions tab/menu.

2021-04-23 17:55:10.6277188 [ThreadId 2176] INFO hls:	finish: Pragmas.GetParsedModule (took 0.00s)
2021-04-23 17:55:10.6282292 [ThreadId 2180] INFO hls:	finish: importLens (took 0.00s)
2021-04-23 17:55:10.6282205 [ThreadId 2178] INFO hls:	finish: HaddockComments.GetAnnotatedParsedSource (took 0.00s)
2021-04-23 17:55:10.6284327 [ThreadId 2182] INFO hls:	finish: tactic (took 0.00s)
2021-04-23 17:55:10.6285299 [ThreadId 2183] INFO hls:	finish: splice.codeAction.GitHieAst (took 0.00s)
2021-04-23 17:55:10.6286178 [ThreadId 2184] INFO hls:	finish: CodeAction (took 0.00s)
2021-04-23 17:55:10.6286843 [ThreadId 2186] INFO hls:	finish: retrie (took 0.00s)
2021-04-23 17:55:10.6290103 [ThreadId 2188] INFO hls:	finish: tactic (took 0.00s)
2021-04-23 17:55:10.6291867 [ThreadId 2190] INFO hls:	finish: tactic (took 0.00s)
2021-04-23 17:55:10.629348 [ThreadId 2192] INFO hls:	finish: tactic (took 0.00s)

And then choose option Add "Foo" to the import list of A.

2021-04-23 17:55:32.0173757 [ThreadId 2208] INFO hls:	finish: importLens (took 0.00s)
2021-04-23 17:55:32.017329 [ThreadId 2207] INFO hls:	finish: HaddockComments.GetAnnotatedParsedSource (took 0.00s)
2021-04-23 17:55:32.0174298 [ThreadId 2209] INFO hls:	finish: Pragmas.GetParsedModule (took 0.00s)
2021-04-23 17:55:32.0174404 [ThreadId 2210] INFO hls:	finish: splice.codeAction.GitHieAst (took 0.00s)
2021-04-23 17:55:32.0175202 [ThreadId 2208] INFO hls:	finish: tactic (took 0.00s)
2021-04-23 17:55:32.0175677 [ThreadId 2209] INFO hls:	finish: retrie (took 0.00s)
2021-04-23 17:55:32.0178464 [ThreadId 2211] INFO hls:	finish: tactic (took 0.00s)
2021-04-23 17:55:32.0178972 [ThreadId 2213] INFO hls:	finish: tactic (took 0.00s)
2021-04-23 17:55:32.0179331 [ThreadId 2210] INFO hls:	finish: CodeAction (took 0.00s)
2021-04-23 17:55:32.0180024 [ThreadId 2214] INFO hls:	finish: tactic (took 0.00s)

Your environment

I am sorry but I can't find haskell-language-server executable to tell its version. It's not in the path; not in $HOME in .vscode-server, .cabal, .stack, .local; not on Windows in %APPDATA%\Code\User\globalStorage.
I can only say that I expect it to be recent as VSCode updated hls around a week or two ago.

Which OS do you use:
Windows Subsystem for Linux with Ubuntu 20.04.
Which lsp-client do you use:
VS Code
Describe your project (alternative: link to the project):
stack project

Metadata

Metadata

Assignees

No one assigned

    Labels

    component: ghcidetype: 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