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

add support for demon/server mode #18

Open
prabirshrestha opened this issue Jan 21, 2020 · 0 comments
Open

add support for demon/server mode #18

prabirshrestha opened this issue Jan 21, 2020 · 0 comments

Comments

@prabirshrestha
Copy link
Contributor

This sort of is an continuation for mattn/vim-fz#4 to allow users to set or append items. In order to achieve this I need two way communication with gof similar to language server protocol.

Here is how quickpick.vim in pure vimscript.

NPM Picker

Colorscheme Picker

There is a few problem with this as in there is no fuzzy search and fuzzy match highlighting because it is very expensive to do in vimscript.

I would like to have a two way communication with gof similar to language server protocol. My thought was adding gof -s flag which starts gof in server mode and we can have two way communication with stdin and stdout.

function! s:on_change(id, event, data) abort
     " here is where the user would get a:data['word'] and perform actual search text
     let s:timer = timer_start(250, {-> fz#send(a:id, 'set', ['solarizeddark', 'solarizedlight']) })
endfunction

function! s:on_selection_change(id, event, data) abort
    if !empty(a:data['items'])
        execute 'colorscheme ' . a:data['items'][0]
    endif
endfunction

function! s:on_exit(id, event, data) abort
    if has('s:timer')
        call timer_stop(s:timer)
        unlet s:timer
    endif
endfunction

let l:id =  fz#run({
    \ 'type': 'manual',
    \ 'on_search_change: function('s:on_search_change'),
    \ 'on_selection_change: function('s:on_selection_change'),
    \ 'on_exit': function('s:on_exit'),
    \ })

My thought was to introduce just 2 new methods in vim-fz.

  1. fz#send(id, event_name, data)
  2. fz#on(id, event_name, callback). This might not be required if we mandate fz#run to pass it as above.

fz#send is to notify gof server. Here are the commands that server needs to understand at minimum.

call fz#send(id, 'items/set', ['item1', item2'])
call fz#send(id, 'items/set', [ {'text': 'item1', 'data': { 'id': 1}},  {'text': 'item2', 'data': { 'id': 2}}])
call fz#send(id, 'items/push', ['item3', item4'])
call fz#send(id, 'items/push', [ {'text': 'item5', 'data': { 'id': 5}},  {'text': 'item6', 'data': { 'id': 6}}])

call fz#send(id, 'search/set', <c-word>)

call fz#send(id, 'items/clear')

call fz#on(id, 'items/change', {id, event, data -> }

call fz#send(id, 'exit')

Why do we need the server mode? In vim-lsp I would like to support LspWorkspaceSymbol which requires communicating back and forth with language server and vim-lsp.

Having two way communication also allows to create interesting features such as the quickpick where as user changes the selection we can change the colorscheme or filetype to get immediate feedback. cancel or exit is required to reset the colorscheme back in case the user never accepts the value.

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

1 participant