atom-haskell-archive / autocomplete-haskell

Atom autocomplete-plus provider for haskell
https://atom.io/packages/autocomplete-haskell
MIT License
23 stars 1 forks source link

Show data constructors in the autocomplete list when the user types `NameOfType.` #17

Closed LukaHorvat closed 7 years ago

LukaHorvat commented 7 years ago

I believe this would be a very nice feature to have. Not sure how easy it would be to implement.

So when I have a type like

data T = A | B | C

it's hard to remember what it's constructors are called. What I would like is to be able to type T. and have an autocomplete list with the constructors. Then when I select one and press enter the T. part would get replaced by the constructor.

If the constructors are a part of a qualified import then the T. part would be replaced with a qualified constructor name.

lierdakil commented 7 years ago

Sounds reasonable, and should be relatively straightforward to implement, although that would require ghc-mod-5.6.0.0 or higher (earlier versions don't output constructor-to-type associations)

I'm a bit concerned about using . as a separator though, since that's technically stealing syntax from module separator, and will end up being somewhat ambiguous. Maybe we could just show type constructors as a suggestions when type is autocompleted in non-type context (i.e. outside of type signature)?

LukaHorvat commented 7 years ago

Sounds good though it might make sense to have some kind of a separator that leaves only those constructors in the autocomplete list. Also, how do you imagine the constructors would be indicated in the list?

On Fri, Oct 14, 2016, 7:35 PM Nikolay Yakimov notifications@github.com wrote:

Sounds reasonable, and should be relatively straightforward to implement, although that would require ghc-mod-5.6.0.0 or higher (earlier versions don't output constructor-to-type associations)

I'm a bit concerned about using . as a separator though, since that's technically stealing syntax from module separator, and will end up being somewhat ambiguous. Maybe we could just show type constructors as a suggestions when type is autocompleted in non-type context (i.e. outside of type signature)?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/atom-haskell/autocomplete-haskell/issues/17#issuecomment-253869069, or mute the thread https://github.com/notifications/unsubscribe-auth/AAWnw7NMEzghx_sbP-3M_WWpItsxn55Kks5qz71dgaJpZM4KV5zo .

lierdakil commented 7 years ago

With my suggestion it would probably something like this (note: Prelude import is qualified and aliased as P here): image

LukaHorvat commented 7 years ago

Could be perhaps have a different marker for constructors?

On Fri, Oct 14, 2016 at 7:47 PM Nikolay Yakimov notifications@github.com wrote:

With my suggestion it would probably something like this (note: Prelude import is qualified and aliased as P here): [image: image] https://cloud.githubusercontent.com/assets/7275622/19397129/33d7c7a4-924f-11e6-8056-f73fb50b13d6.png

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/atom-haskell/autocomplete-haskell/issues/17#issuecomment-253871839, or mute the thread https://github.com/notifications/unsubscribe-auth/AAWnw7p8uKJvKyEbNdF0mtpo_KX2lsH0ks5qz8AcgaJpZM4KV5zo .

lierdakil commented 7 years ago

That would be a bit complicated, but I'll see what I can do about that.

LukaHorvat commented 7 years ago

Awesome man!

On Fri, Oct 14, 2016 at 8:03 PM Nikolay Yakimov notifications@github.com wrote:

That would be a bit complicated, but I'll see what I can do about that.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/atom-haskell/autocomplete-haskell/issues/17#issuecomment-253876610, or mute the thread https://github.com/notifications/unsubscribe-auth/AAWnw8GXpnnl8tIWBLZLsDY97y6TUuh7ks5qz8PUgaJpZM4KV5zo .

lierdakil commented 7 years ago

Okay, something to this effect should be available with haskell-ghc-mod v1.18.0. Note that you need ghc-mod 5.6 or above. Also 1.18.0 shows fully-qualified suggestions along with unqualified/alias-qualified ones and should work for aliased but unqualified imports as well (something that wasn't working before).

Constructors are shown as tags in completion panel -- it's a bit incorrect, possibly, but at least consistent with highlighting: image

There are probably some edge cases I missed where this will fail miserably, so feel free to report any bugs.