Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use the case split key-binding? #152

Open
LeifW opened this issue Mar 5, 2020 · 4 comments
Open

How to use the case split key-binding? #152

LeifW opened this issue Mar 5, 2020 · 4 comments

Comments

@LeifW
Copy link

LeifW commented Mar 5, 2020

The readme suggests binding that to capitol 'C' - I bound it to lower-case 'c' as it seems challenging to me to also hit the shift key right after hitting ''.

I would expect that putting the cursor on the _ in

myCase :: Either String Int -> String
myCase _ = ?myCase

and typing \c' would split that _ for me. But what it says is E471: Argument required, and nothing happens.
If I run e.g. ":Pcase Either" at that position, it works. But I thought it'd be able to tell the type at that position - kind of wonder what's the point of the keybinding, otherwise.

Also, :Pcase Boolean or :Pcase Unit both tell me e.g. .e.g 'purs ide server: type 'Boolean' not found, or type 'Unit' not found`.

@kritzcreek
Copy link
Collaborator

The case splitting in purs ide (as implemented) does not type check the file, so it requires the user to tell it what type they'd like to case split.

kind of wonder what's the point of the keybinding, otherwise.

The primary reason was to save some typing at the time, and I didn't find myself using the feature enough to continue improving it.

Also, :Pcase Boolean or :Pcase Unit both tell me e.g. .e.g 'purs ide server: type 'Boolean' not found, or type 'Unit' not found`.

That's because neither of those are ADTs defined in PS. Boolean is defined in Prim and maps to JSs booleans, and Unit is defined via the FFI (I think for efficiency reasons? Not entirely sure)

@LeifW
Copy link
Author

LeifW commented Mar 5, 2020

Thanks!
Is there a way of supplying an argument to a keybinding? When I type \c, it it immediately responds with E471: Argument required (before I have a chance to type anything else).

@LeifW LeifW changed the title How to use case split command? How to use the case split key-binding? Mar 5, 2020
@kritzcreek
Copy link
Collaborator

Sorry, I don't know enough (anything really) about vim script, so I couldn't tell. Maybe someone else can help out.

@LeifW
Copy link
Author

LeifW commented Mar 5, 2020

I saw this StackOverflow answer, where they call input('Please supply a parameter: ') when calling a function from the keybinding. https://vi.stackexchange.com/a/4754

:Pcase is defined as com! -buffer -bang -nargs=1 Pcase call PSCIDEcaseSplit(<q-bang>, <q-args>) at https://github.com/FrigoEU/psc-ide-vim/blob/master/ftplugin/purescript_pscide.vim#L134-L136

In the definition of the PSCIDEcaseSplit function, it looks like the first thing it does is check if the varargs "splat" is non-empty, and it it's not, use the first element as the type, else get type from calling input("Please provide a type: ").
https://github.com/FrigoEU/psc-ide-vim/blob/master/ftplugin/purescript_pscide.vim#L583

For some reason it seems that branch is not getting triggered?
If I map to invoking the function:

nm <buffer> <silent> <leader>c :call PSCIDEcaseSplit(' ')<CR> 

with empty string as the bang argument, it works.
Maybe when it's being called with <q-args> in that position, it thinks it's being populated (from where? with what?), or <q-args> simply doesn't register as an empty array?

On vim 8.2.0343.

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

No branches or pull requests

2 participants