Is there a way to get better type hints by PureScript IDE?

Hi,
I am currently using neovim with coc.nvim to get coding assist via PureScript language server.

I often wish, type hints would be a bit more verbose and dynamic. Just an example from PureScript Ebook chapter 11 (type definitions at bottom for quick glance):

cheat :: Game Unit  
cheat = do  
  GameState state <- get   
  tell          
    $ foldl (\acc x -> ("You now have the " <> show x) : acc) L.Nil 
    $ S.unions state.items
  let newInventory = foldl S.union state.inventory state.items  
  put $ GameState state { items = M.empty, inventory = newInventory } 

1. If hovering for example over tell, foldl, S.unions and pressing K, I only get type hints for the generic type constructors

foldl :: ∀ (f ∷ Type -> Type) (a ∷ Type) (b ∷ Type). 
Foldable f ⇒ (b → a → b) → b → f a → b

Is it possible to hint something like

  • f a = Set GameItem
  • b = List String

inside foldl, i.e. where type parameters have been instantiated?

2. Some symbols don’t show anything at all, like when inspecting acc, state.items or state.inventory, giving hint a status hint at bottom:

[coc.nvim] hover not found

Can these type hints be improved? This really would make the barrier lower for newcomers like me.

Also expressive type hints (and concise error messages) are those features, I am missing most from TypeScript language.

Thanks.


Type defintions

import Data.List as L
import Data.Map as M
import Data.Set as S
data GameItem = Candle | Matches
newtype GameEnvironment = GameEnvironment
  { playerName    :: PlayerName
  , debugMode     :: Boolean
  }
type Log = L.List String
type Game = RWS GameEnvironment Log GameState
newtype GameState = GameState
  { items       :: M.Map Coords (S.Set GameItem)
  , player      :: Coords
  , inventory   :: S.Set GameItem
  }
2 Likes

No idea about the the first suggestion, but this:

Some symbols don’t show anything at all, like when inspecting acc , state.items or state.inventory , giving hint a status hint at bottom:

is because type hints are currently only supported for toplevel declarations. That excludes any local variables or record members (e.g. foo.bar). purs ide: type information by range (like :GhcModType does) · Issue #3670 · purescript/purescript · GitHub tracks this, but I’m not sure if it would allow showing type hints for record accesses.

2 Likes

Thanks @mhmdanas,
your mentioned issue is a good starting point.

There doesn’t seem to be any movement since years though, which awakes the impression, this feature is not needed by the majority of users (?).

1 Like

Hmm, no, I think it is a pretty oft-requested feature. I’ve even requested it myself, before I knew of the issue I mentioned: No info on hover for non-toplevel symbols · Issue #109 · nwolverson/purescript-language-server · GitHub

2 Likes

That’s a sore spot for me too. The workaround I use is a “typed hole”. So if I have

f = a + b
  where
  a = ...
  b = ...

and I want to see what type a is, I can’t just mouse over a, but I can use a “typed hole” and change it to

f = a + b
  where
  a :: ?_
  a = ...
  b = ...

(the underscore doesn’t matter, just anything starting with a question mark will be a typed hole). Then I can mouse over ?_ and the popup will tell me the type it infers for a.

I’m realizing if you click into the GitHub issue, garyb recommends that already, but maybe it’s good to have it duplicated here in case somebody lands on this page without clicking into the GitHub issue.

6 Likes

This also works if you don’t want to start a newline:

foo = 1
  where
  (bar :: ?_) = ""
4 Likes