haskell / haskell-ide-engine

The engine for haskell ide-integration. Not an IDE
BSD 3-Clause "New" or "Revised" License
2.38k stars 211 forks source link

Snippet support dosen't respect client declining the feature. #822

Closed meck closed 6 years ago

meck commented 6 years ago

When using HIE with neovim, which unfortunately docent support snippets in a good way, I tried deregistering: The LSP spec has a snippetSupport option in TextDocumentClientCapabilities and it seems that isn't respected by HIE.

I saw that there is global config to turn it of but it seems more logical to do it on a client basis according to the spec

lorenzo commented 6 years ago

@meck I'm also using neovim and was about to permanently disable this feature for me, but I made it work and and definitely loving it. This is my setup:

  1. Install deoplete or ncm2
  2. Install ultisnips
  3. Add this "hack" to your init.vim
let g:UltiSnipsExpandTrigger="<NUL>"
let g:UltiSnipsListSnippets="<NUL>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
function! CompleteSnippet()
  if empty(v:completed_item)
    return
  endif

  call UltiSnips#ExpandSnippet()
  if g:ulti_expand_res > 0
    return
  endif

  let l:complete = type(v:completed_item) == v:t_dict ? v:completed_item.word : v:completed_item
  let l:comp_len = len(l:complete)

  let l:cur_col = mode() == 'i' ? col('.') - 2 : col('.') - 1
  let l:cur_line = getline('.')

  let l:start = l:comp_len <= l:cur_col ? l:cur_line[:l:cur_col - l:comp_len] : ''
  let l:end = l:cur_col < len(l:cur_line) ? l:cur_line[l:cur_col + 1 :] : ''

  call setline('.', l:start . l:end)
  call cursor('.', l:cur_col - l:comp_len + 2)

  call UltiSnips#Anon(l:complete)
endfunction

autocmd CompleteDone * call CompleteSnippet()

It will automatically insert the placeholder as text after a completion, and you can use <tab> and `s- to go back and forth between them.

Obviously, this does not mean you have to love the feature like I do. We should anyway investigate why it is not possible to disable it :)

I leave a screencast of how the feature works:

asciicast

meck commented 6 years ago

Thats a really good solution! Thanks! I still need to tinker with it a bit as i've overloaded tab and cr to both navigate the completion menu and snippet, and that breaks slightly.

The issue should be looked into thou.