# nvim-completion-manager **Repository Path**: romepeng/nvim-completion-manager ## Basic Information - **Project Name**: nvim-completion-manager - **Description**: :warning: PLEASE USE https://github.com/ncm2/ncm2 INSTEAD - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-05-02 - **Last Updated**: 2021-05-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # :warning: THIS REPO IS DEPRECATED. USE [NCM2](https://github.com/ncm2/ncm2) INSTEAD. --- :heart: for my favorite editor # A Completion Framework for Neovim This is a **fast, extensible, async completion framework** for [neovim](https://github.com/neovim/neovim). For more information about plugin implementation, please read the **[Why](#why) section**. Future updates, announcements, screenshots will be posted **[here](https://github.com/roxma/nvim-completion-manager/issues/12). Subscribe it if you are interested.** ![All in one screenshot](https://cloud.githubusercontent.com/assets/4538941/23752974/8fffbdda-0512-11e7-8466-8a30f480de21.gif) ## Table of Contents * [Features](#features) * [Scoping Sources:](#scoping-sources) * [Completion Sources](#completion-sources) * [How to extend this framework?](#how-to-extend-this-framework) * [Requirements](#requirements) * [Installation](#installation) * [Optional Configuration Tips](#optional-configuration-tips) * [Why?](#why) * [Async architecture](#async-architecture) * [Scoping](#scoping) * [Experimental hacking](#experimental-hacking) * [FAQ](#faq) * [Why Python?](#why-python) * [Trouble-shooting](#trouble-shooting) * [Related Projects](#related-projects) ## Features 1. Asynchronous completion support like deoplete. 2. Faster, all completions should run in parallel. 3. Smarter on files with different languages, for example, css/javascript completion in html style/script tag. 4. Extensible async vimscript API and python3 API. 5. Function parameter expansion via [Ultisnips](https://github.com/SirVer/ultisnips), [neosnippet.vim](https://github.com/Shougo/neosnippet.vim) or [vim-snipmate](https://github.com/garbas/vim-snipmate). ## Scoping Sources: - Language specific completion for markdown, reStructuredText - Javascript code completion in html script tag - Css code completion in html style tag ## Completion Sources | Language / Description | Repository | |--------------------------|----------------------------------------------------------------------------------------| | Word from current buffer | builtin | | Word from tmux session | builtin | | ctags completion | builtin | | Filepath completion | builtin | | Python | builtin, requires [jedi](https://github.com/davidhalter/jedi) | | Css | builtin, requires [csscomplete#CompleteCSS](https://github.com/othree/csscomplete.vim) | | Golang | builtin, requires [gocode](https://github.com/nsf/gocode) | | Ultisnips hint | builtin, requires [Ultisnips](https://github.com/SirVer/ultisnips) | | Snipmate hint | builtin, requires [vim-snipmate](https://github.com/garbas/vim-snipmate) | | neosnippet hint | builtin, requires [neosnippet.vim](https://github.com/Shougo/neosnippet.vim) | | Language Server Protocol | [autozimu/LanguageClient-neovim](https://github.com/autozimu/LanguageClient-neovim) | | C/C++ | [clang_complete](https://github.com/roxma/clang_complete) [DEPRECATED] | | C/C++ | [ncm-clang](https://github.com/roxma/ncm-clang) | | Javascript | [nvim-cm-tern](https://github.com/roxma/nvim-cm-tern) | | Javascript | [nvim-cm-flow](https://github.com/roxma/ncm-flow) | | elm | [ncm-elm-oracle](https://github.com/roxma/ncm-elm-oracle) | | Clojure | [clojure-async-clj-omni](https://github.com/clojure-vim/async-clj-omni) | | Rust | [nvim-cm-racer](https://github.com/roxma/nvim-cm-racer) | | Vimscript | [Shougo/neco-vim](https://github.com/Shougo/neco-vim) | | Ruby | [ncm-rct-complete](https://github.com/roxma/ncm-rct-complete) | | PHP | [LanguageServer-php-neovim](https://github.com/roxma/LanguageServer-php-neovim) | | PHP | [ncm-phpactor](https://github.com/roxma/ncm-phpactor) | | Swift | [dafufer/nvim-cm-swift-completer](https://github.com/dafufer/nvim-cm-swift-completer) | | gtags completion | [jsfaint/gen_tags.vim](https://github.com/jsfaint/gen_tags.vim) | | syntax completion | [Shougo/neco-syntax](https://github.com/Shougo/neco-syntax) | | include completion | [Shougo/neoinclude](https://github.com/Shougo/neoinclude.vim) | | github completion | [ncm-github](https://github.com/roxma/ncm-github) | | mutt mails | [#97 mutt-aliases.vim](https://github.com/roxma/nvim-completion-manager/issues/97) | | deoplete | [#50 deoplete](https://github.com/roxma/nvim-completion-manager/issues/50) | | css | [calebeby/ncm-css](https://github.com/calebeby/ncm-css) | | lbdb (addressbook) | [katsika/ncm-lbdb](https://github.com/katsika/ncm-lbdb) | | Java | [sassanh/nvim-cm-eclim](https://github.com/sassanh/nvim-cm-eclim) | | TypeScript | [mhartington/nvim-typescript](https://github.com/mhartington/nvim-typescript) | | Word from other buffers | [fgrsnau/ncm-otherbuf](https://github.com/fgrsnau/ncm-otherbuf) | R | [gaalcaras/ncm-R](https://github.com/gaalcaras/ncm-R) ## How to extend this framework? - `:help ncm-source-examples` for minimal examples - Some real, small examples: [github-emoji](https://github.com/roxma/ncm-github/blob/master/pythonx/cm_sources/github_emoji.py), [nvim-cm-racer](https://github.com/roxma/nvim-cm-racer) Please announce your new plugin [here](https://github.com/roxma/nvim-completion-manager/issues/12) after you've created the extension. ## Requirements - For Neovim: - `echo has("python3")` - For Vim 8: - [roxma/vim-hug-neovim-rpc](https://github.com/roxma/vim-hug-neovim-rpc) - `g:python3_host_prog` pointed to your python3 executable, or `echo exepath('python3')` is not empty. - [neovim python client](https://github.com/neovim/python-client) (`pip3 install neovim`) ## Installation - Assuming you're using [vim-plug](https://github.com/junegunn/vim-plug) ```vim " the framework Plug 'roxma/nvim-completion-manager' ``` - If you are **vim8 user**, you'll need [vim-hug-neovim-rpc](https://github.com/roxma/vim-hug-neovim-rpc). The vim8 support layer is still experimental, please 'upgrade' to [neovim](https://github.com/neovim/neovim) if it's possible. ```vim " Requires vim8 with has('python') or has('python3') " Requires the installation of msgpack-python. (pip install msgpack-python) if !has('nvim') Plug 'roxma/vim-hug-neovim-rpc' endif ``` - Install pip modules for your neovim python3: ```sh # neovim is the required pip module # jedi for python completion # psutil (optional) # setproctitle (optional) pip3 install --user neovim jedi psutil setproctitle ``` (Optional) It's easier to use [python-support.nvim](https://github.com/roxma/python-support.nvim) to help manage your pip modules for neovim: ## Optional Configuration Tips - Supress the annoying completion messages: ```vim " don't give |ins-completion-menu| messages. For example, " '-- XXX completion (YYY)', 'match 1 of 2', 'The only match', set shortmess+=c ``` - When the `` key is pressed while the popup menu is visible, it only hides the menu. Use this mapping to hide the menu and also start a new line. ```vim inoremap (pumvisible() ? "\\" : "\") ``` - Here is an example for expanding snippet in the popup menu with `` key. Suppose you use the `` key for expanding snippet. ```vim imap (pumvisible() ? "\\(expand_or_nl)" : "\") imap (expand_or_nl) (cm#completed_is_snippet() ? "\":"\") ``` - When using `CTRL-C` key to leave insert mode, it does not trigger the autocmd `InsertLeave`. You should use `CTRL-[`, or map the `` to ``. ```vim inoremap ``` - Use `` to select the popup menu: ```vim inoremap pumvisible() ? "\" : "\" inoremap pumvisible() ? "\" : "\" ``` - If 'omnifunc' is the only available option, you may register it as a source for NCM. ```vim " css completion via `csscomplete#CompleteCSS` " The `'cm_refresh_patterns'` is PCRE. " Be careful with `'scoping': 1` here, not all sources, especially omnifunc, " can handle this feature properly. au User CmSetup call cm#register_source({'name' : 'cm-css', \ 'priority': 9, \ 'scoping': 1, \ 'scopes': ['css','scss'], \ 'abbreviation': 'css', \ 'word_pattern': '[\w\-]+', \ 'cm_refresh_patterns':['[\w\-]+\s*:\s+'], \ 'cm_refresh': {'omnifunc': 'csscomplete#CompleteCSS'}, \ }) ``` **Warning:** `omnifunc` is implemented in a synchronouse style, and vim-vimscript is single threaded, it would potentially block the ui with the introduction of a heavy weight `omnifunc`, for example the builtin phpcomplete. If you get some time, please try implementing a source for NCM as a replacement for the old style omnifunc. - There's no guarantee that this plugin will be compatible with other completion plugin in the same buffer. Use `let g:cm_smart_enable=0` and `call cm#enable_for_buffer()` to use this plugin for specific buffer. - This example shows how to disable NCM's builtin tag completion. It's also possible to use `g:cm_sources_override` to override other default options of a completion source. ```vim let g:cm_sources_override = { \ 'cm-tags': {'enable':0} \ } ``` ## Why? This project was started just for fun, and it's working pleasingly for me now. However, it seems there's lots of differences between deoplete, YCM, and nvim-completion-manager, by implementation. I haven't read the source of YCM yet. So here I'm describing the basic implementation of NCM (short for nvim-completion-manager) and some of the differences between deoplete and this plugin. ### Async architecture Each completion source should be a thread or a standalone process, the manager notifies the completion source for any text changing, even when popup menu is visible. The completion source notifies the manager if there's any complete matches available. After some basic priority sorting between completion sources, and some simple filtering, the completion popup menu will be triggered with the `complete()` function by the completion manager. If some of the completion source is calculating matches for a long long time, the popup menu will still be shown quickly if other completion sources work properly. And if the user hasn't changed anything, the popup menu will be updated after the slow completion source finishes the work. As the time as of this plugin being created, the completion sources of deoplete are gathered with `gather_candidates()` of the `Source` object, inside a for loop, in deoplete's process. A slow completion source may defer the display of popup menu. Of course it will not block the ui. The good news is that deoplete has supported async `gather_candidates` now. But still, NCM is potentially faster because all completion sources run in parallel. ### Scoping I write markdown files with code blocks quite often, so I've also implemented language specific completion for markdown file. This is a framework feature, which is called scoping. It should work for any markdown code block whose language completion source is avaible to NCM. I've also added support for javascript completion in script tag of html files, and css completion in style tag. The idea was originated in [vim-syntax-compl-pop](https://github.com/roxma/vim-syntax-compl-pop). Since it's pure vimscript implementation, and there are some limitations currently with neovim's syntax api. It's very likely that vim-syntax-compl-pop doesn't work, for example, javascript completion in markdown or html script tag. So I use custom parser in NCM to implement the scoping features. ### Experimental hacking Note that there's some hacking done in NCM. It uses a per 30ms timer to detect changes even popup menu is visible, as well as using the `TextChangedI` event, which only triggers when no popup menu is visible. This is important for implementing the async architecture. I'm hoping one day neovim will offer better option rather than a timer or the limited `TextChangedI`. ## FAQ ### Why Python? YouCompleteMe has [good explanation](https://github.com/Valloric/YouCompleteMe#why-isnt-ycm-just-written-in-plain-vimscript-ffs). ## Trouble-shooting Moved to [wiki](https://github.com/roxma/nvim-completion-manager/wiki/Trouble-shooting) ## Related Projects [asyncomplete.vim](https://github.com/prabirshrestha/asyncomplete.vim)