Skip to content

Wingman: Using the completion system for case analysis #2437

Closed
@kalhauge

Description

@kalhauge

Is your feature request related to a problem? Please describe.

When I write code I often write it like this:

foldMaybe :: Monoid m => Maybe m -> m
foldMaybe m = case m of 
   -- hmm.. what was the cases for Maybe again...

Right now I have to,

  1. stop what I'm doing,
  2. click on the code lens hint,
  3. and apply the change,
  4. navigate to the first _ and start writing.

Describe the solution you'd like

It would be really nice if we could somehow "TAB" (pun intended) into the lsp completion/snippet system,
and when I have written the of I can tap complete and be presented with a case expansion,
(and possibly a 'hylo'-morphic case expansion and a monadic case expansion):

foldMaybe :: Monoid m => Maybe m -> m
foldMaybe m = case m of<TAB>(choose case)
   Just a -> _
   Nothing -> _

mapMaybe :: (a -> b) -> Maybe a -> Maybe b
mapMaybe  fn m  = case m of<TAB>(choose hylo)
   Just a -> Just _
   Nothing -> Nothing

mapMaybeM :: Monad m => (a -> m b) -> Maybe a -> m (Maybe b)
mapMaybeM m = case m of<TAB>(choose "do" hylo)
   Just a -> do 
    pure $ Just _
   Nothing -> do 
    pure $ Nothing

This suggestion is only for the case analysis part, it might however also work for refinements. If you
are on a "_" and press tab, it could suggest a refined solution if it finds one in less than 0.x seconds, suggest it, otherwise it might suggest one of the other transformations.

Describe alternatives you've considered

Wingman works great as is, but this would really be a "killer" feature.

Additional context

There seem to be some kind of support for snippets in the LSP protocol, but I don't know how well it is integrated in the different editors (and in the haskell-language-server).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions