Skip to content

Allow import all constructors#2782

Merged
pepeiborra merged 4 commits into
haskell:masterfrom
July541:all-constructors-import
Mar 19, 2022
Merged

Allow import all constructors#2782
pepeiborra merged 4 commits into
haskell:masterfrom
July541:all-constructors-import

Conversation

@July541

@July541 July541 commented Mar 15, 2022

Copy link
Copy Markdown
Collaborator

This is for #2734

Brief intro:

With

Module A where
data Foo = Foo | Bar

it will suggest import Foo(..) now, like import A(Foo(..)) and Add Foo(..) to the import list of A.


Note:
Support Now!
This doesn't work for record fields, ideally, we should support this.

Example:

data Foo = Bar {a :: Int}

if we have f = a, we should also have import A(Foo(..)). Maybe we can extend

data IdentInfo = IdentInfo
{ name :: !OccName
, rendered :: Text
, parent :: !(Maybe Text)
, isDatacon :: !Bool
, moduleNameText :: !Text
}

with a field to indicate a's data type if a is a record field.

@July541
July541 requested a review from pepeiborra as a code owner March 15, 2022 15:58
@July541

July541 commented Mar 15, 2022

Copy link
Copy Markdown
Collaborator Author

With data A = B | C,

import A (A(B))
f = C

it will cause import A (A(B, ..) if we import all constructors. I'll check it later.

@pepeiborra

Copy link
Copy Markdown
Collaborator

This is a good idea, thanks for working on it!

@pepeiborra

Copy link
Copy Markdown
Collaborator

if we have f = a, we should also have import A(Foo(..)). Maybe we can extend

data IdentInfo = IdentInfo
{ name :: !OccName
, rendered :: Text
, parent :: !(Maybe Text)
, isDatacon :: !Bool
, moduleNameText :: !Text
}

with a field to indicate a's data type if a is a record field.

Did you consider checking if isJust parent ?

@July541
July541 force-pushed the all-constructors-import branch from 1c9c1b1 to 77def21 Compare March 19, 2022 06:00

@pepeiborra pepeiborra 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.

Fantastic work, thank you @July541 !

@pepeiborra
pepeiborra merged commit 2221371 into haskell:master Mar 19, 2022
@July541
July541 deleted the all-constructors-import branch March 19, 2022 11:43
July541 added a commit to July541/haskell-language-server that referenced this pull request Mar 30, 2022
* Import all constructors

* Rewrite the test

* Exact print wildcard

* Rerun circleci
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.

2 participants