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

Cursor jumps around with completions #4

Closed
casr opened this issue Oct 21, 2017 · 5 comments
Closed

Cursor jumps around with completions #4

casr opened this issue Oct 21, 2017 · 5 comments

Comments

@casr
Copy link
Contributor

casr commented Oct 21, 2017

I have noticed an issue when using HTML where the cursor jumps away from where it should be. It also seems to corrupt the undo history making the change hard to undo. The issue is present in Vim and Neovim.

Here is a bare minimum vimrc to make testing easier:

" Saved as ~/minimalrc
set nocompatible

let install_cmd = []
call add(install_cmd, 'rm -rf /tmp/asyncomplete-test')
call add(install_cmd, 'mkdir -p /tmp/asyncomplete-test')
call add(install_cmd, 'git clone --depth 1 https://github.com/prabirshrestha/asyncomplete.vim.git /tmp/asyncomplete-test/asyncomplete.vim')
call add(install_cmd, 'git clone --depth 1 https://github.com/yami-beta/asyncomplete-omni.vim.git /tmp/asyncomplete-test/asyncomplete-omni.vim')
execute 'silent !/bin/sh -xc "' . join(install_cmd, ' && ') . '"'

let &runtimepath.=','.escape('/tmp/asyncomplete-test/asyncomplete.vim', '\,')
let &runtimepath.=','.escape('/tmp/asyncomplete-test/asyncomplete-omni.vim', '\,')

filetype plugin indent on

autocmd User asyncomplete_setup call asyncomplete#register_source(
  \ asyncomplete#sources#omni#get_source_options({
    \ 'name': 'omni',
    \ 'whitelist': ['*'],
    \ 'completor': function('asyncomplete#sources#omni#completor')
    \  })
  \ )

Use the command: vim -u ~/minimalrc a.html and then go into insert mode and type:

<div id="a

You should notice that after typing 'a' the cursor jumps to the beginning of the line.

@yami-beta
Copy link
Owner

I think htmlcomplete change cursor position.
https://github.com/vim/vim/blob/master/runtime/autoload/htmlcomplete.vim#L97

@casr
Copy link
Contributor Author

casr commented Oct 22, 2017

Interesting. I take from your response that it is not a great idea for a complete function to do that but I am not too familiar with them. Do you think I should look for a different complete function or that the problem should be handled by asyncomplete.vim/asyncomplete-omni.vim? /cc @prabirshrestha

I searched the Vim source for call cursor and it comes up in phpcomplete.vim, rubycomplete.vim and sqlcomplete.vim so there may be potential problems there too.

@prabirshrestha
Copy link
Contributor

It can't be fixed by in asyncomplete. The omni-func needs to be fixed. One temporary option would be to do this.

Plug 'Shougo/neco-syntax'
Plug 'prabirshrestha/asyncomplete.vim'
Plug 'prabirshrestha/asyncomplete-necosyntax.vim'

call asyncomplete#register_source(asyncomplete#sources#omni#get_source_options({
\ 'name': 'omni',
\ 'whitelist': ['*'],
\ 'blacklist': ['html'],
\ 'completor': function('asyncomplete#sources#omni#completor')
\  }))
au User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#necosyntax#get_source_options({
    \ 'name': 'necosyntax',
    \ 'whitelist': ['*'],
    \ 'completor': function('asyncomplete#sources#necosyntax#completor'),
    \ }))

https://github.com/prabirshrestha/asyncomplete-necosyntax.vim

I usually don't spend time in html much since I use react with typescript language server. There is a LSP for html but I haven't tried it yet. https://www.npmjs.com/package/vscode-html-languageservice

For php I reocmmend using LSP. https://github.com/prabirshrestha/vim-lsp/wiki/Servers-PHP. LSP adds support for things like go to def, rename, find symbols, linting, code completion and much more.

here is how my vimrc looks like. https://gist.github.com/prabirshrestha/279d8b179d9353fe8694/7a291666de64748efe32c24b13c9263198a4fe1c#file-vimrc-L178-L248.

@prabirshrestha
Copy link
Contributor

@casr might be good to start the discussion on https://github.com/vim/vim about call cursor

@casr
Copy link
Contributor Author

casr commented Oct 23, 2017

Thank you both very much for your responses and suggestions. I think as the problem is isolated to a few filetypes I am quite happy to disable them for now.

I could not get the vscode-html-languageservice package to work. I think it might need a wrapper around it to launch a more LSP-y server.

@prabirshrestha thanks for a sharing your vimrc. Lots of useful things in there!

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

3 participants