GithubHelp home page GithubHelp logo

prabirshrestha / asyncomplete.vim Goto Github PK

View Code? Open in Web Editor NEW
900.0 16.0 58.0 206 KB

async completion in pure vim script for vim8 and neovim

License: MIT License

Vim Script 100.00%
vim neovim ultisnips asyncomplete code-completion vim8

asyncomplete.vim's Introduction

asyncomplete.vim

Async autocompletion for Vim 8 and Neovim with |timers|.

This is inspired by nvim-complete-manager but written in pure Vim Script.

Installing

Plug 'prabirshrestha/asyncomplete.vim'

Tab completion

inoremap <expr> <Tab>   pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
inoremap <expr> <cr>    pumvisible() ? asyncomplete#close_popup() : "\<cr>"

If you prefer the enter key to always insert a new line (even if the popup menu is visible) then you can amend the above mapping as follows:

inoremap <expr> <cr> pumvisible() ? asyncomplete#close_popup() . "\<cr>" : "\<cr>"

Force refresh completion

imap <c-space> <Plug>(asyncomplete_force_refresh)
" For Vim 8 (<c-@> corresponds to <c-space>):
" imap <c-@> <Plug>(asyncomplete_force_refresh)

Auto popup

By default asyncomplete will automatically show the autocomplete popup menu as you start typing. If you would like to disable the default behavior set g:asyncomplete_auto_popup to 0.

let g:asyncomplete_auto_popup = 0

You can use the above <Plug>(asyncomplete_force_refresh) to show the popup or you can tab to show the autocomplete.

let g:asyncomplete_auto_popup = 0

function! s:check_back_space() abort
    let col = col('.') - 1
    return !col || getline('.')[col - 1]  =~ '\s'
endfunction

inoremap <silent><expr> <TAB>
  \ pumvisible() ? "\<C-n>" :
  \ <SID>check_back_space() ? "\<TAB>" :
  \ asyncomplete#force_refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"

Preview Window

To enable preview window:

" allow modifying the completeopt variable, or it will
" be overridden all the time
let g:asyncomplete_auto_completeopt = 0

set completeopt=menuone,noinsert,noselect,preview

To auto close preview window when completion is done.

autocmd! CompleteDone * if pumvisible() == 0 | pclose | endif

Sources

asyncomplete.vim deliberately does not contain any sources. Please use one of the following sources or create your own.

Language Server Protocol (LSP)

Language Server Protocol via vim-lsp and asyncomplete-lsp.vim

Please note that vim-lsp setup for neovim requires neovim v0.2.0 or higher, since it uses lambda setup.

Plug 'prabirshrestha/asyncomplete.vim'
Plug 'prabirshrestha/vim-lsp'
Plug 'prabirshrestha/asyncomplete-lsp.vim'

if executable('pyls')
    " pip install python-language-server
    au User lsp_setup call lsp#register_server({
        \ 'name': 'pyls',
        \ 'cmd': {server_info->['pyls']},
        \ 'allowlist': ['python'],
        \ })
endif

Refer to vim-lsp wiki for configuring other language servers. Besides auto-complete language server support other features such as go to definition, find references, renaming symbols, document symbols, find workspace symbols, formatting and so on.

in alphabetical order

Languages/FileType/Source Links
Ale asyncomplete-ale.vim
Buffer asyncomplete-buffer.vim
C/C++ asyncomplete-clang.vim
Clojure async-clj-omni
Common Lisp (vlime) vlime
Dictionary (look) asyncomplete-look
Emmet asyncomplete-emmet.vim
English asyncomplete-nextword.vim
Emoji asyncomplete-emoji.vim
Filenames / directories asyncomplete-file.vim
NeoInclude asyncomplete-neoinclude.vim
Go asyncomplete-gocode.vim
Git commit message asyncomplete-gitcommit
JavaScript (Flow) asyncomplete-flow.vim
Neosnippet asyncomplete-neosnippet.vim
Omni asyncomplete-omni.vim
PivotalTracker stories asyncomplete-pivotaltracker.vim
Rust (racer) asyncomplete-racer.vim
TabNine powered by AI asyncomplete-tabnine.vim
tmux complete tmux-complete.vim
Typescript asyncomplete-tscompletejob.vim
UltiSnips asyncomplete-ultisnips.vim
User (compl-function) asyncomplete-user.vim
Vim Syntax asyncomplete-necosyntax.vim
Vim tags asyncomplete-tags.vim
Vim asyncomplete-necovim.vim

can't find what you are looking for? write one instead an send a PR to be included here or search github topics tagged with asyncomplete at https://github.com/topics/asyncomplete.

Using existing vim plugin sources

Rather than writing your own completion source from scratch you could also suggests other plugin authors to provide a async completion api that works for asyncomplete.vim or any other async autocomplete libraries without taking a dependency on asyncomplete.vim. The plugin can provide a function that takes a callback which returns the list of candidates and the startcol from where it must show the popup. Candidates can be list of words or vim's complete-items.

function s:completor(opt, ctx)
  call mylanguage#get_async_completions({candidates, startcol -> asyncomplete#complete(a:opt['name'], a:ctx, startcol, candidates) })
endfunction

au User asyncomplete_setup call asyncomplete#register_source({
    \ 'name': 'mylanguage',
    \ 'allowlist': ['*'],
    \ 'completor': function('s:completor'),
    \ })

Example

function! s:js_completor(opt, ctx) abort
    let l:col = a:ctx['col']
    let l:typed = a:ctx['typed']

    let l:kw = matchstr(l:typed, '\v\S+$')
    let l:kwlen = len(l:kw)

    let l:startcol = l:col - l:kwlen

    let l:matches = [
        \ "do", "if", "in", "for", "let", "new", "try", "var", "case", "else", "enum", "eval", "null", "this", "true",
        \ "void", "with", "await", "break", "catch", "class", "const", "false", "super", "throw", "while", "yield",
        \ "delete", "export", "import", "public", "return", "static", "switch", "typeof", "default", "extends",
        \ "finally", "package", "private", "continue", "debugger", "function", "arguments", "interface", "protected",
        \ "implements", "instanceof"
        \ ]

    call asyncomplete#complete(a:opt['name'], a:ctx, l:startcol, l:matches)
endfunction

au User asyncomplete_setup call asyncomplete#register_source({
    \ 'name': 'javascript',
    \ 'allowlist': ['javascript'],
    \ 'completor': function('s:js_completor'),
    \ })

The above sample shows synchronous completion. If you would like to make it async just call asyncomplete#complete whenever you have the results ready.

call timer_start(2000, {timer-> asyncomplete#complete(a:opt['name'], a:ctx, l:startcol, l:matches)})

If you are returning incomplete results and would like to trigger completion on the next keypress pass 1 as the fifth parameter to asyncomplete#complete which signifies the result is incomplete.

call asyncomplete#complete(a:opt['name'], a:ctx, l:startcol, l:matches, 1)

As a source author you do not have to worry about synchronization issues in case the server returns the async completion after the user has typed more characters. asyncomplete.vim uses partial caching as well as ignores if the context changes when calling asyncomplete#complete. This is one of the core reason why the original context must be passed when calling asyncomplete#complete.

Credits

All the credit goes to the following projects

Contributors

Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

asyncomplete.vim's People

Contributors

a5ob7r avatar acomagu avatar andreypopp avatar cvlmtg avatar dn1z avatar donniewest avatar equwal avatar hauleth avatar hhaoao avatar hokorobi avatar idbrii avatar ii41 avatar ilex avatar itchyny avatar jagua avatar jsit avatar keremc avatar kyouryuukunn avatar mattn avatar monkeywithacupcake avatar pdavydov108 avatar prabirshrestha avatar renovate[bot] avatar ryo7000 avatar tamy0612 avatar tomekw avatar vhakulinen avatar wellle avatar yaegassy avatar yami-beta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

asyncomplete.vim's Issues

Tags?

Any plans to import the NCP tag completion functionality?

Yes, I'm asking/begging because I'm not capable of doing it myself ^^

Vim not respond in middle of completion

System: gvim 8.1 - 116 / windows10

Runing with corei7/ssd pc, should not have any problem with os itself. Completion causes vim not respond as image below. I believe it happens randomly especially after install asyncomplete-tags.vim, I'll disable that plugin for a while and give feedback if this issue still occurs.

This issue happens sometime for me in recent couple of days, never happend before.

Plugins in suspection: ludovicchabant/vim-gutentags, prabirshrestha/asyncomplete-tags.vim

If you have any ways to troubleshoot this, please do let me know.

Image of Yaktocat

Error going to insert mode

I'm trying to install this plugin in windows (Babun) I get this error message when I go to insert mode. Am I missing any dependencies?

Error detected while processing function 59_change_tick_start:
line 6:
E117: Unknown function: timer_start
Press ENTER or type command to continue
Error detected while processing function 59_change_tick_start:
line 6:
E15: Invalid expression: timer_start(30, function('s:check_changes'), { 'repeat': -1 })

Make a bundle of common autocompletion sources?

Hi,

Is it possible to group a few sources together and make a asyncomplete plugin such as buffer, filename etc?

And let language server utilize omni_complete function?

I like the plugin at it does not require python binding.

Thanks

Using with FZF

Hi,

Just wondering if it is possible to use this plugin with FZF, so that rather than searching using the standard prefix search, the plugin just provides a list of possible words to FZF and FZF fuzzy matches them?

Add support for clang?

when using deoplete, I use deoplete-clang2 or deoplete-clang, will this plugin support clang sources?

completion menu issue on neovim

with the latest version of asyncomplete (which reintroduced TextChangedP) the completion is working ok, but there's a little issue: If I start typing a word the completion menu appears, but if for some reason I delete a letter (e.g. because I made a mistake) the menu disappear and it doesn't appear anymore unless I erase all the word except the first letter. It doesn't matter if I write another letter, press tab etc. If I want the menu back I have to erase the word up to the first letter. for example:

schermata 2018-03-16 alle 20 03 09

schermata 2018-03-16 alle 20 03 34

schermata 2018-03-16 alle 20 11 17

schermata 2018-03-16 alle 20 11 54

schermata 2018-03-16 alle 20 03 41

I'm using neovim:

NVIM v0.2.3-715-g1d5eec2c6
Build type: Release
LuaJIT 2.0.5
Compilation: /usr/local/Homebrew/Library/Homebrew/shims/super/clang -Wconversion -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -I/tmp/neovim-20180305-87677-1emzc9v/build/config -I/tmp/neovim-20180305-87677-1emzc9v/src -I/usr/local/include -I/usr/local/opt/gettext/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include -I/tmp/neovim-20180305-87677-1emzc9v/build/src/nvim/auto -I/tmp/neovim-20180305-87677-1emzc9v/build/include
Compilato da [email protected]

Features: +acl +iconv +jemalloc +tui 

this is my config:

let g:asyncomplete_remove_duplicates = 1
let g:lsp_async_completion = 1
let g:lsp_log_file = ''

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

call asyncomplete#register_source(asyncomplete#sources#omni#get_source_options({
      \ 'name': 'omni',
      \ 'whitelist': ['*'],
      \ 'blacklist': ['html', 'javascript', 'javascript.jsx'],
      \ 'completor': function('asyncomplete#sources#omni#completor')
      \  }))

call asyncomplete#register_source(asyncomplete#sources#file#get_source_options({
    \ 'name': 'file',
    \ 'priority': 10,
    \ 'whitelist': ['*'],
    \ 'completor': function('asyncomplete#sources#file#completor')
    \ }))

if executable('typescript-language-server')
  call lsp#register_server({
        \ 'name': 'typescript-language-server',
        \ 'priority': 9,
        \ 'cmd': { server_info->[&shell, &shellcmdflag, 'typescript-language-server --stdio']},
        \ 'root_uri': { server_info->lsp#utils#path_to_uri(lsp#utils#find_nearest_parent_directory(lsp#utils#get_buffer_path(), '.git/..'))},
        \ 'whitelist': ['typescript', 'javascript', 'javascript.jsx']
        \ })
endif

inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
imap <expr> <Space> pumvisible() ? "\<C-y>\<Space>" : "\<Space>"

Completion menu doesn't close upon <Cr> with smart completion enabled

First of all, thank you for an amazing completion plugin, it's truly awesome!

I have a small issue after upgrading and enabling smart completion. Without smart completion enabled, when completion menu popups, you don't select any item and press <Cr> - it would close the completion menu. However, with smart completion enabled, after you press <Cr> it just reopens completion menu, so you need to manually close it some other way (e.g. press <Esc>).

My vimrc:

Plug 'prabirshrestha/async.vim'
Plug 'prabirshrestha/asyncomplete.vim'
Plug 'prabirshrestha/asyncomplete-buffer.vim'
Plug 'prabirshrestha/asyncomplete-file.vim'
Plug 'prabirshrestha/asyncomplete-lsp.vim' " depends: vim-lsp
Plug 'prabirshrestha/vim-lsp' " depends: async.vim

let g:asyncomplete_remove_duplicates = 1
let g:asyncomplete_smart_completion = 1

function! asyncomplete_sources() abort
  call asyncomplete#register_source(asyncomplete#sources#buffer#get_source_options({
        \ 'name': 'buffer',
        \ 'whitelist': ['*'],
        \ 'completor': function('asyncomplete#sources#buffer#completor'),
        \ }))
  call asyncomplete#register_source(asyncomplete#sources#file#get_source_options({
        \ 'name': 'file',
        \ 'whitelist': ['*'],
        \ 'completor': function('asyncomplete#sources#file#completor')
        \ }))
endfunction

autocmd User asyncomplete_setup call asyncomplete_sources()

inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"

Candidates disappear on backspace

System: gvim 8.1 - 1-116 / windows10

I'm tesing this plugin with python file, when type p you have a list of candidates, then type print --> using backspace to delete nt, now we have no candidates.

No popup appearing

Hi,
I saw your posts on reddit and I'm really interesting in trying out your plugin. It seems the setup is different from what I'm used to or I am missing something?
No popup is showing when I type...

I'm using neovim on ubuntu:

Config
`Plug 'prabirshrestha/asyncomplete.vim'
Plug 'prabirshrestha/asyncomplete-tags.vim'
let g:asyncomplete_auto_popup = 1

inoremap pumvisible() ? "<C-n>" : "<Tab>"
inoremap pumvisible() ? "<C-p>" : "<S-Tab>"
inoremap pumvisible() ? "<C-y>" : "<cr>"
let g:asyncomplete_log_file = expand('~/asyncomplete.log')
imap (asyncomplete_force_refresh)

au User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#tags#get_source_options({
\ 'name': 'tags',
\ 'whitelist': ['c'],
\ 'completor': function('asyncomplete#sources#tags#completor'),
\ 'config': {
\ 'max_file_size': 50000000,
\ },
\ }))
`
Log:
["core","python_cm_insert_enter"]
["core","python_cm_insert_enter"]
["core","python_cm_insert_enter"]
["core","python_cm_insert_enter"]
["core","python_cm_insert_enter"]
["core", "python_cm_insert_enter"]
["core", "python_cm_insert_enter"]
["core", "python_cm_insert_enter"]
["core", "python_cm_insert_enter"]
["core", "python_cm_insert_enter"]
["core", "python_cm_insert_enter"]
["core", "python_cm_insert_enter"]
["core", "python_cm_insert_enter"]
["core", "python_cm_insert_enter"]
["core", "python_cm_insert_enter"]
["core", "python_cm_insert_enter"]

Problems between lsp_async_completion and asyncomplete-ultisnips

When I set vim-lsp's lsp_async_completion=1, my Ultisnips completion just flashes for a short amount of time and is then gone again, if I force refresh, it doesn't show any Ultisnips completion results.

When I set lsp_async_completion=0, I get duplicate results (even though I have that flag for duplicate results enabled, it's not filtering them out)

Let me know if I should repost this issue in another repository!

Support for LSP Snippets

There are a couple issues floating around GitHub for the different LSP clients for vim/nvim, their completion engines, and various snippet integration engines.

An issue does not seem to be filed with asyncomplete.vim yet for this support (correct me and close this if I'm wrong!) so I wanted to start that thread.

For any that are unaware, it appears that clangd broadcasts support for c++ snippets and those broadcasts appropriately show up in the omni popup menu.

I can navigate through those "completion" options that are sourced as "snippets" from clangd, but I can't invoke the snippet.

Now, maybe this isn't a job for the completion engine? Should this fall onto a snippet engine instead? If that's the case, I feel it may be time to write a vim-lsp-snippet project for that very reason, as LSP snippets (I don't think) don't belong in the hands of something like UltiSnips/neosnippet/etc. Or at least, if they do, this vim-lsp/asyncomplete.vim/etc. toolset would be best not to rely on them for fear of "getting more than you bargained for". But I am not familiar with snippet engines in general so I could be very wrong about this.

Nonetheless, there's my two cents. Is expanding LSP snippets something the asyncomplete project feels it should handle? Should that fall into the hands of something like UltiSnips? Should another tool for this vim-lsp chain be added explicitly for LSP snippet expansion?

P.S. I apologize for this being mildly incoherent. I'm up way past my bedtime and far too tired to be very coherent ATM ๐Ÿ˜†

How to use LanguageClient-neovim as an omni source

I'm aware of prabirshrestha/vim-lsp & prabirshrestha/asyncomplete-lsp.vim, but I'm happy with LanguageClient-neovim & trying to migrate from nvim-completion-manager without too many changes right now. So if I can get this to work with asyncomplete it will be great! Maybe in the future I'll look into prabirshrestha/vim-lsp & prabirshrestha/asyncomplete-lsp.vim or even hopefully this will land in neovim neovim/neovim#6856

So my question is since LanguageClient-neovim has an omni function LanguageClient#complete, how can I use it with asyncomplete?

Hang / Errors with the double star operator

Observed Behavior:

I have noticed that the double splat operator '**' will cause asyncomplete to hang or emit error messages across several different file types. In python files it tends to hang very briefly then emit messages similar to below. With a Makefile I recently edited it froze vim indefinitely and I ended up having to stop vim with kill -9.

Expected Result

I would not normally expect vim to auto complete these types of special characters / operators.

Workarounds

This looked like it might have a workaround by editing the matching regex, I will respond here if I find anything.

Notes:

:messages output from the error while editing a python file.

Error detected while processing function <SNR>32_on_vim_job_event[12]..<SNR>32_on_exec_events[8]..<SNR>32_complete[3]..asyncomplete#complete[11]..<SNR>28_python_cm_complete[19]
..<SNR>28_python_refresh_completions[49]..<SNR>28_filter_completion_items:
line    3:
E871: (NFA regexp) Can't have a multi follow a multi !
E61: Nested *
Error detected while processing function <SNR>32_on_vim_job_event[12]..<SNR>32_on_exec_events[8]..<SNR>32_complete[3]..asyncomplete#complete[11]..<SNR>28_python_cm_complete[19]
..<SNR>28_python_refresh_completions:
line   49:
E734: Wrong variable type for +=

Vim version:

VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Apr 30 2018 08:01:13)
Included patches: 1-1608
Compiled by ryan@fanai
Huge version with GTK2 GUI.  Features included (+) or not (-):
+acl               +cmdline_hist      +eval              +job               +mouse             +num64             +scrollbind        +termresponse      +windows
+arabic            +cmdline_info      +ex_extra          +jumplist          +mouseshape        +packages          +signs             +textobjects       +writebackup
+autocmd           +comments          +extra_search      +keymap            +mouse_dec         +path_extra        +smartindent       +timers            +X11
-autoservername    +conceal           +farsi             +lambda            -mouse_gpm         +perl              +startuptime       +title             -xfontset
+balloon_eval      +cryptv            +file_in_path      +langmap           -mouse_jsbterm     +persistent_undo   +statusline        +toolbar           +xim
+balloon_eval_term +cscope            +find_in_path      +libcall           +mouse_netterm     +postscript        -sun_workshop      +user_commands     +xpm
+browse            +cursorbind        +float             +linebreak         +mouse_sgr         +printer           +syntax            +vertsplit         +xsmp_interact
++builtin_terms    +cursorshape       +folding           +lispindent        -mouse_sysmouse    +profile           +tag_binary        +virtualedit       +xterm_clipboard
+byte_offset       +dialog_con_gui    -footer            +listcmds          +mouse_urxvt       -python            +tag_old_static    +visual            -xterm_save
+channel           +diff              +fork()            +localmap          +mouse_xterm       +python3           -tag_any_white     +visualextra
+cindent           +digraphs          +gettext           +lua               +multi_byte        +quickfix          -tcl               +viminfo
+clientserver      +dnd               -hangul_input      +menu              +multi_lang        +reltime           +termguicolors     +vreplace
+clipboard         -ebcdic            +iconv             +mksession         -mzscheme          +rightleft         +terminal          +wildignore
+cmdline_compl     +emacs_tags        +insert_expand     +modify_fname      +netbeans_intg     +ruby              +terminfo          +wildmenu
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/usr/local/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK  -pthread -I/usr/include/gtk-2.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/gio-unix-2.0/ -I/usr/
include/cairo -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng16 -I/usr/include/
pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/freetype2 -I/usr/include/libpng16
 -I/usr/include/freetype2 -I/usr/include/libpng16   -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc   -L. -L/home/ryan/.rbenv/versions/2.5.0/lib  -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,-E   -L/usr/local/lib -Wl,--as-needed -o vim   -lgtk-x11-2.0 -lgd
k-x11-2.0 -lpangocairo-1.0 -latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lfontconfig -lfreetype -lSM -lICE -lXpm -lXt -lX11
-lXdmcp -lSM -lICE  -lm -ltinfo -lnsl  -lselinux  -ldl  -L/usr/lib -llua5.1 -Wl,-E  -fstack-protector-strong -L/usr/local/lib  -L/usr/lib/x86_64-linux-gnu/perl/5.26/CORE -lperl
 -ldl -lm -lpthread -lcrypt  -L/usr/lib/python3.5/config -lpython3.6m  -Wl,-rpath,/home/ryan/.rbenv/versions/2.5.0/lib -L/home/ryan/.rbenv/versions/2.5.0/lib -lruby-static -lpt
hread -lgmp -ldl -lcrypt -lm  -L/home/ryan/.rbenv/versions/2.5.0/lib

Tags

asterisk, star, splat, hang, freeze, operator

Deduplicate completion items

Currently when more than a single sources is enabled for a buffer it is possible to get duplicates in the completion menu. For example, for JS I use both buffer and flow (this is needed as buffer is more robust โ€” even when syntax is not valid it can do its job while flow is more "correct").

I think asyncomplete can do dedup. That would probably require to provide some priority order for sources though โ€” for example flow should be prioritised over buffer as its completions are more "correct" (based on semantic source code knowledge).

Delay to display language's function candidate

In a python file, type print in a fast way, for the first time no candidate appears at all, I have to force refresh, but it doesn't happen with snips that come up with its own supported plugin asyncomplete-ultisnips, so I guess there's something with update completion on change of context.

Cursor jumps unexpectedly when omni completion has failed.

cast

It seems asyncomplete-omni.vim issue but hitting any character in insert mode at | move cursor at 1,1.
It occurs when the filename is test.vue but test.html.
Btw, No message is produced.

<template>
  <div>
    <span class="|">
  </div>
</template>

minimal vimrc

" vim -u ~/.vim/vimrc.min
if has('vim_starting')
  set nocompatible
  execute 'set runtimepath^=~/.cache/dein/repos/github.com/prabirshrestha/async.vim'
  execute 'set runtimepath^=~/.cache/dein/repos/github.com/prabirshrestha/asyncomplete.vim'
  execute 'set runtimepath^=~/.cache/dein/repos/github.com/prabirshrestha/asyncomplete-omni.vim'
endif

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

filetype plugin indent on
syntax on

Limiting results/completions

Hi,
First off, I'm genuinely impressed by how snappy your plugin ecosystem works, much appreciated ๐Ÿ‘

I couldn't find anything, so I was wondering if there is any way to limit the number of results a plugin returns (for example, at most n snippets) and/or the total number of results (e.g. at most 10 completions)?

This plugin sets completeopt?

Firstly, this plugin works really well and is quite lightweight. Thank you for your work on it! I am using it with g:asyncomplete_auto_popup = 0 and manually invoking it with <tab> as described in the readme.

I am wondering why it is necessary to set completeopt in s:core_complete? Are these settings (menuone,noselect/noinsert) considered mandatory for the plugin to work? Why are they set at every invocation instead of once during initialization? Why aren't the user's initial settings restored?

I was initially surprised when my completeopt settings were being changed after pressing <tab>. This functionality/limitation unfortunately does not seem to be addressed in either the readme or doc.

Some candidates are ignored?

I've been attempting to wrap LanguageClient-neovim to provide completions for asyncomplete, which has mostly worked, but I've noticed that some of the candidates passed into asyncomplete#complete() appear to be ignored by it -- they don't show up in the popup menu, and I don't get an error message displayed or logged.

I'm unfamiliar with vimscript, so this could definitely be some error on my part, but the behaviour is pretty odd, and I can't figure out what could be causing it.

Examples (pyls via LanguageClient-neovim providing completions)

Image of completion for json.
This first one looks about right...
Image of completion for json.l
Where'd json.loads go?
Image of completion for json.d
json.dumps has vanished but this otherwise is what I'd expect
Image of completion for json.de
Still good...
Image of completion for json.c
wat.

minimal (tested) init.vim

call plug#begin("~/.config/nvim/plugged")
  Plug 'autozimu/LanguageClient-neovim', { 'branch': 'next', 'do': 'bash install.sh' }
  Plug 'prabirshrestha/async.vim' | Plug 'prabirshrestha/asyncomplete.vim'
call plug#end()

let g:LanguageClient_serverCommands = {}
if executable('pyls')
  let g:LanguageClient_serverCommands.python = ['pyls']
endif

" LanguageClient-neovim / asyncomplete integration wrapper, must be after LC server registrations
function! s:LanguageClient_handle_asyncomplete_callback(name, ctx, startcol, matches)
  let l:result = get(a:matches, 'result')
  let l:result = l:result is v:null ? [] : l:result

  call asyncomplete#log('LanguageClient-nvim', 'handle_asyncomplete_callback', a:matches)
  call asyncomplete#complete(a:name, a:ctx, a:startcol, l:result)
endfunction
function! s:LanguageClient_asyncompletor(opt, ctx) abort
  let l:col = a:ctx['col']
  let l:typed = a:ctx['typed']
  let l:kw = matchstr(l:typed, '\w\+$')
  let l:kwlen = len(l:kw)
  let l:startcol = l:col - l:kwlen
  " Have LC generate the completion matches and pass it a callback partial into asyncomplete
  " LanguageClient's Rust code uses 0-based column indexing instead of 1-based, AFAICT
  call LanguageClient#omniComplete(
    \ {
    \   'complete_position': (l:startcol - 1),
    \   'character': (l:col - 1),
    \ },
    \ function('s:LanguageClient_handle_asyncomplete_callback', [a:opt['name'], a:ctx, l:startcol]))
endfunction

let s:lc_languages = keys(get(g:, 'LanguageClient_serverCommands', {}))
au User asyncomplete_setup call asyncomplete#register_source({
  \ 'name': 'LanguageClient-neovim',
  \ 'whitelist': s:lc_languages,
  \ 'priority': 5,
  \ 'completor': function('s:LanguageClient_asyncompletor'),
  \ })

let g:asyncomplete_log_file = expand('~/.local/share/nvim/asyncomplete.log')

asyncomplete log

Here's the log. As per the given init.vim, I added a log statement in my callback handler to capture the callback result from LanguageClient#omniComplete(), and from what I can see it does contain a list of valid complete-items in the return attribute. I pass that list into asyncomplete#complete(), but then only some of the items actually end up listed in the pop-up?

Source for filesystem path completion

It would nice to have a source which completes filesystem paths.

It's even better if such source could complete paths relative to the current buffer rather then cwd (this is how Vim's built-in fs path completion works I believe).

Complete only on tab keypress

It looks like asyncomplete tries to complete on any buffer change by default. Is it possible to only try to complete when user explicitly asks for it โ€” on Tab keypress, for example?

Disable 'pattern not found' messages

Hello @prabirshrestha, sometimes on completion I get annoying messages such as Pattern not found or match 1 of <number>. This messages are completely useless. Maybe it's better to disable them? After some digging I found this thread. This patch was merged in vim 7.4.something, so as long as this plugin relies on vim 8 features, this feature is available. It allows to set set shortmess+=c in order to disable such messages. Also, youcompleteme sets this flag here, discussion.

Duplicate "$" completion for PHP and JavaScript file. :(

Problems summary

(I'm sorry for my poor English.)

Hi, prabirshrestha

First of all, I appreciate vim-lsp, asyncomplete and related great plugins.

Duplicate "$" completion for PHP file. :(

Screenshot

list

1_asyncomplete_list

[NG]done

$$variable2 :(

2_asyncomplete_done

Minimal vimrc (minimal.vimrc)

" plugin (use vim-plug) {{{
call plug#begin('~/.vim/plugged')

Plug 'prabirshrestha/async.vim'
Plug 'prabirshrestha/asyncomplete.vim'
Plug 'prabirshrestha/vim-lsp'
Plug 'prabirshrestha/asyncomplete-lsp.vim'

call plug#end()
" }}}

" log
let g:asyncomplete_log_file = expand('/tmp/asyncomplete.log')

" [LSP] php-language-server
"
" @see
" https://github.com/prabirshrestha/vim-lsp/wiki/Servers-PHP
augroup LspPHP
  au!
  au User lsp_setup call lsp#register_server({
       \ 'name': 'php-language-server',
       \ 'cmd': {server_info->['php', expand('~/.composer/vendor/felixfbecker/language-server/bin/php-language-server.php')]},
       \ 'whitelist': ['php'],
       \ })
augroup end

example.php

vim -N -u minimal.vimrc example.php

| is cursor.

<?php

$variable1 = "test";
$variable2 = "test";

echo $|

Log (asyncomplete.log)

["core","s:clear_active_sources",1]
["core","remote_insert_enter"]
["core","computing get_active_sources_for_buffer",1]
["core","s:remote_refresh","asyncomplete_lsp_php-language-server",["",-1,-1],{"lnum":5,"bufnr":1,"col":1,"changedtick":4,"typed":"","filetype":"php","curpos":[0,5,1,0,1],"filepath":"/Users/maamo888/_Dev/php/example.php"}]
["core","s:remote_refresh","asyncomplete_lsp_php-language-server",["",-1,-1],{"lnum":6,"bufnr":1,"col":1,"changedtick":5,"typed":"","filetype":"php","curpos":[0,6,1,0,1],"filepath":"/Users/maamo888/_Dev/php/example.php"}]
["core","s:remote_refresh","asyncomplete_lsp_php-language-server",["e",0,1],{"lnum":6,"bufnr":1,"col":2,"changedtick":6,"typed":"e","filetype":"php","curpos":[0,6,2,0,2],"filepath":"/Users/maamo888/_Dev/php/example.php"}]
["core","completor()","asyncomplete_lsp_php-language-server",{"lnum":6,"bufnr":1,"col":2,"changedtick":6,"typed":"e","filetype":"php","curpos":[0,6,2,0,2],"filepath":"/Users/maamo888/_Dev/php/example.php"}]
["core","s:remote_refresh","asyncomplete_lsp_php-language-server",["ec",0,2],{"lnum":6,"bufnr":1,"col":3,"changedtick":7,"typed":"ec","filetype":"php","curpos":[0,6,3,0,3],"filepath":"/Users/maamo888/_Dev/php/example.php"}]
["core","s:remote_refresh","asyncomplete_lsp_php-language-server",["ech",0,3],{"lnum":6,"bufnr":1,"col":4,"changedtick":8,"typed":"ech","filetype":"php","curpos":[0,6,4,0,4],"filepath":"/Users/maamo888/_Dev/php/example.php"}]
["core","s:remote_refresh","asyncomplete_lsp_php-language-server",["echo",0,4],{"lnum":6,"bufnr":1,"col":5,"changedtick":9,"typed":"echo","filetype":"php","curpos":[0,6,5,0,5],"filepath":"/Users/maamo888/_Dev/php/example.php"}]
["core","s:remote_refresh","asyncomplete_lsp_php-language-server",["",-1,-1],{"lnum":6,"bufnr":1,"col":6,"changedtick":10,"typed":"echo ","filetype":"php","curpos":[0,6,6,0,6],"filepath":"/Users/maamo888/_Dev/php/example.php"}]
["core","s:remote_refresh","asyncomplete_lsp_php-language-server",["",-1,-1],{"lnum":6,"bufnr":1,"col":7,"changedtick":11,"typed":"echo $","filetype":"php","curpos":[0,6,7,0,7],"filepath":"/Users/maamo888/_Dev/php/example.php"}]
["core","s:remote_refresh","asyncomplete_lsp_php-language-server",["v",6,7],{"lnum":6,"bufnr":1,"col":8,"changedtick":12,"typed":"echo $v","filetype":"php","curpos":[0,6,8,0,8],"filepath":"/Users/maamo888/_Dev/php/example.php"}]
["core","completor()","asyncomplete_lsp_php-language-server",{"lnum":6,"bufnr":1,"col":8,"changedtick":12,"typed":"echo $v","filetype":"php","curpos":[0,6,8,0,8],"filepath":"/Users/maamo888/_Dev/php/example.php"}]
["core","s:python_cm_complete","asyncomplete_lsp_php-language-server",{"lnum":6,"bufnr":1,"col":8,"changedtick":12,"typed":"echo $v","filetype":"php","curpos":[0,6,8,0,8],"filepath":"/Users/maamo888/_Dev/php/example.php"},7,true,0]
["core","s:core_complete"]
["core","s:remote_refresh","asyncomplete_lsp_php-language-server",["va",6,8],{"lnum":6,"bufnr":1,"col":9,"changedtick":17,"typed":"echo $va","filetype":"php","curpos":[0,6,9,0,9],"filepath":"/Users/maamo888/_Dev/php/example.php"}]
["core","completor()","asyncomplete_lsp_php-language-server",{"lnum":6,"bufnr":1,"col":9,"changedtick":17,"typed":"echo $va","filetype":"php","curpos":[0,6,9,0,9],"filepath":"/Users/maamo888/_Dev/php/example.php"}]
["core","s:python_cm_complete","asyncomplete_lsp_php-language-server",{"lnum":6,"bufnr":1,"col":9,"changedtick":17,"typed":"echo $va","filetype":"php","curpos":[0,6,9,0,9],"filepath":"/Users/maamo888/_Dev/php/example.php"},7,true,0]
["core","s:core_complete"]
["core","s:remote_refresh","asyncomplete_lsp_php-language-server",["",-1,-1],{"lnum":6,"bufnr":1,"col":18,"changedtick":30,"typed":"echo $$variable2;","filetype":"php","curpos":[0,6,18,0,18],"filepath":"/Users/maamo888/_Dev/php/example.php"}]
["core","completor()","asyncomplete_lsp_php-language-server",{"lnum":6,"bufnr":1,"col":18,"changedtick":30,"typed":"echo $$variable2;","filetype":"php","curpos":[0,6,18,0,18],"filepath":"/Users/maamo888/_Dev/php/example.php"}]
["core","s:python_cm_complete","asyncomplete_lsp_php-language-server",{"lnum":6,"bufnr":1,"col":18,"changedtick":30,"typed":"echo $$variable2;","filetype":"php","curpos":[0,6,18,0,18],"filepath":"/Users/maamo888/_Dev/php/example.php"},18,true,0]
["core","remote_insert_leave"]

Keyword completion as source

Awesome plugin!

Do you have a suggestion of how to include regular keyword completions as a source?

When writing a regular text document it's nice to be able to set complete+=kspell and get dictionary word suggestions from pressing <C-n> or <C-p>.

Feature request(s)

Great addon, thanks a lot for creating it! I'm currently use it together with
asyncomplete-buffer.vim. Fuzzy-matching capabilities and it's really a lightweight one!

Some feature requests (if you don't mind...):

  1. Please add an option to show the completion window on a minimum of written characters

E.g. (default value): let g:asyncomplete_popup_on_minimum_characters = 0

I for myself would set that option to 3 so you'd need to type 3 characters before the autocomplete popup appears

  1. Keep the popup open after invoking it (with or ctrl+space) when let g:asyncomplete_auto_popup = 0 is used
    Atm the popup closes automatically if you type more to narrow down the result list

  2. If there is only one possible match, don't show the popup first (with that single entry) but automatically autocomplete the item immediately

Ofc as an option, e.g.: let g:asyncomplete_complete_on_single_match = 1

  1. Would it be possible to make the entries of the popup more context aware?
    Atm all entries are "only" alphabetically sorted. But if an entry is near the current typing position it should
    have a higher priority than one that would fit what you currently typed but is farther away (position wise)

Preserve default behaviour of C-n and C-p when possible

I've already opened similar issue on deoplete and Shougo was kind enough to implement it after I've made a pull request.
The behaviour I want to preserve is when there is not popupmenu (because there's no completion yet because you haven't entered enough characters to trigger it) C-n and C-p should insert closest next/previous word. It's actually pretty useful in some cases. Consider in python
Some = namedtuple('| pressing C-p here twice would insert Some. Or when passing keyword arguments in python context=context instead of retyping one could simply press C-p. Also there is a recipe that uses this behaviour to create a mapping to autoclose xml tags.

g:asyncomplete_remove_duplicates doesn't work

Same candidates are shown even if g:asyncomplete_remove_duplicates is 1.

For below example, Test2 and test2 were shown in both of prabirshrestha/asyncomplete-buffer.vim and prabirshrestha/asyncomplete-lsp.vim.
I used latest version asyncomplete.vim, async.vim two sources in 2018/9/17
double

Pressing enter without anything selected should make popup disapear

When I type

class A

a popup helpfully appears offering me completions for A. If I just want to make a new class without choosing any selections, I have to press Esc which also takes me out of insert mode. In other popups that I'm used it by pressing <Enter> after the A the popup goes away and I am left with just the A I typed. Can I configure you do to that? I didn't see anything obvious in the docs.

completion no longer working?

It seems one of the latest commit broke the plugin. no matter what I type, the complete menu opens with the same list of completions. even when I'm typing spaces (see images below)

schermata 2018-03-09 alle 18 59 07

schermata 2018-03-09 alle 18 59 13

I'm using neovim compiled with brew install --HEAD nvim

NVIM v0.2.3-715-g1d5eec2c6
Build type: Release
LuaJIT 2.0.5
Compilation: /usr/local/Homebrew/Library/Homebrew/shims/super/clang -Wconversion -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -I/tmp/neovim-20180305-87677-1emzc9v/build/config -I/tmp/neovim-20180305-87677-1emzc9v/src -I/usr/local/include -I/usr/local/opt/gettext/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include -I/tmp/neovim-20180305-87677-1emzc9v/build/src/nvim/auto -I/tmp/neovim-20180305-87677-1emzc9v/build/include
Compilato da [email protected]

Features: +acl +iconv +jemalloc +tui

Autocompletion won't work with rust

System: gvim 8.1 1-116 / windows 10

Relevant vimrc config:

if executable('rls')
    au User lsp_setup call lsp#register_server({
        \ 'name': 'rls',
        \ 'cmd': {server_info->['rustup', 'run', 'nightly', 'rls']},
        \ 'whitelist': ['rust'],
        \ })
endif

Rust on windows10 packages:

> rustup component list
cargo-x86_64-pc-windows-msvc (default)
rls-preview-x86_64-pc-windows-msvc (installed)
rustc-x86_64-pc-windows-msvc (default)

I can't trigger asyncomplete to work with .rs file under cargo project (cargo new _test --bin), but autocompletion for Ultisnips work well on them, I can choose snips candidates from pop-up menu.

`README.md` should note minimum NeoVim version

It appears that the server_info->[... syntax used for the RLS and clangd servers is not valid in NeoVim 0.1.7 (the current Debian stable version). The syntax error is hidden from the user except via the :messages command.

Updating to NeoVim 0.2.0, from Debian testing fixed the issue and made RLS integration work properly.

I do not see any mention of the NeoVim version requirements in the README.md.

Autocompletion won't work automatically

Hi All,

I'm trying to check out asyncomplete and there's a mismatch between my expectations and results. My expectation is that as I type, I should see suggestions start popping up. But in reality, after I type something (while still in Insert mode), I press and I see a list pop up where I can tab through some results. This is in the context of a simple C++ project. I'm using vim8.1 in Windows and I'm using Pathogen to handle all the extra additions listed here:

asyncomplete.vim
async.vim
vim-lsp

I've verified that I've downloaded the LLVM binaries and I've registered with the clangd LSP. Here's a snippet from my .vimrc.

" Registering clangd LSP with asyncomplete
if executable('clangd')
    au User lsp_setup call lsp#register_server({
        \ 'name': 'clangd',
        \ 'cmd': {server_info->['clangd']},
        \ 'whitelist': ['c', 'cpp', 'objc', 'objcpp'],
        \ })
endif

" Asyncomplete tab completion
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<CR>"
let g:asyncomplete_remove_duplicates = 1
let g:asyncomplete_smart_completion = 1

Any ideas on the disconnect between my expectation and my current result??

Asyncomplete won't work with neovim and RLS (Rust Language Server)

I have a small test project from LanguageClient-neovim. This seems to work. I get autocompletion.

With my project, it does not work (~70000 loc). I do not get completion.

Is it possible to disable dumb auto completion and only use lang server results?

Hi,

Thanks for awesome plugins by the way. Your plugins are the best lang server integration I've seen. I'm getting great relevant langserver completion results but there are also "dumb" results with keywords from the current file (See rad in image below).
image

Is it possible to only use the results from the lang server?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.