Deoplete.nvim: Completion support for R - nvim-r and/or language server

Created on 29 Apr 2018  路  6Comments  路  Source: Shougo/deoplete.nvim

Problems

I would like to get completion working in R.

Option 1: nvim-r

I have tried using nvim-r, which populates vim omnifunc. I tried adding
let g:deoplete#sources.r = ['omni', 'ultisnips']
with a couple options:

call deoplete#custom#source('omni', 'input_patterns', {
    \ 'r': '[^. *\t]\.\w*',
\})

(suggested at https://github.com/Shougo/deoplete.nvim/blob/master/doc/deoplete.txt#L1551 - is this a typo? I was under the impression input patterns should be a var, not a source)

call deoplete#custom#var('omni', 'input_patterns', {
    \ 'r': '[^. *\t]\.\w*',
\})

(suggested at https://github.com/Shougo/deoplete.nvim/blob/master/doc/deoplete.txt#L555)

call deoplete#custom#source('omni_patterns', {
    \ 'r': '[^. *\t]\.\w*',
\})

(suggested at https://github.com/Shougo/deoplete.nvim/blob/master/doc/deoplete.txt#L189)

However, all I see in deoplete completion is ultisnips snippets. Manually calling <C-x><C-o> will bring up nvim-r's function completions. Do you have any suggestions?

Vimrc:

source $HOME/.config/nvim/general.vim
call plug#begin('$HOME/.dotfiles/nvim/plugged')
Plug 'autozimu/LanguageClient-neovim', {'branch': 'next', 'do': './install.sh'}
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
Plug 'SirVer/ultisnips'
Plug 'honza/vim-snippets'
Plug 'jalvesaq/nvim-r'
""" Deoplete config
" automatically start{{{
let g:deoplete#enable_at_startup = 1
let g:deoplete#enable_smart_case = 1
let g:deoplete#sources = {}
let g:deoplete#sources._ = ['file', 'buffer']
let g:deoplete#sources.python = ['LanguageClient', 'jedi', 'ultisnips']
let g:deoplete#sources.python3 = ['LanguageClient', 'jedi', 'ultisnips']
let g:deoplete#sources.rust = ['LanguageClient', 'ultisnips']
let g:deoplete#sources.tex = ['ultisnips', 'omni']
let g:deoplete#sources.vim = ['vim', 'ultisnips']
let g:deoplete#sources.r = ['omni', 'ultisnips']
"let g:deoplete#sources.r = ['LanguageClient', 'ultisnips']

""" Disable the candidates in Comment/String syntaxes.
call deoplete#custom#source('_',
            \ 'disabled_syntaxes', ['Comment', 'String'])

""" deoplete-racer config
let g:deoplete#sources#rust#racer_binary='/usr/local/bin/racer'
let g:deoplete#sources#rust#rust_source_path='$HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src'

" put snippets at the top of completion menu
"call deoplete#custom#source('ultisnips', 'rank', 1000)

call deoplete#custom#var('omni', 'input_patterns', {
    \ 'r': '[^. *\t]\.\w*',
\})
""" Deoplete and vimtex config
call deoplete#custom#var('omni', 'input_patterns', {
      \ 'tex' : g:vimtex#re#deoplete,
\})

Option 2: LanguageClient

I have tried using LanguageClient-neovim with the R language server to get completion.
I set let g:deoplete#sources.r = ['LanguageClient'] and configure with

let g:LanguageClient_autoStart = 1
let g:LanguageClient_serverCommands = {}
let g:LanguageClient_serverCommands.r = ['R', '--quiet', '--slave', '-e', 'languageserver::run()']

When working in python for example, setting LanguageClient as a deoplete source will populate completion. But with the same configuration for R it does not work.

Environment Information

  • deoplete version: 57d3f0c3cdfcfc1d91901a6d59d08f9008abd166

  • OS: Arch Linux on 4.16.5-1 kernel

    • nvim version:
      ```NVIM v0.2.2
      Build type: Release
      LuaJIT 2.0.5
      Compilation: /usr/bin/cc -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -Wconversion -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -O2 -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 -D_GNU_SOURCE -I/build/neovim/src/build/config -I/build/neovim/src/neovim-0.2.2/src -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/build/neovim/src/build/src/nvim/auto -I/build/neovim/src/build/include
      Compiled by builduser

Features: +acl +iconv +jemalloc +tui
See ":help feature-compile"

system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/usr/share/nvim"

  • :checkhealth or :CheckHealth result(neovim only): all OK
    ```

    • I appreciate any suggestions you have. Thank you.

Most helpful comment

Thanks @Shougo. Indeed adding the following seems to work:

    \ 'omni_patterns':  {
        \ 'r': ['[^. *\t]\.\w*', '\h\w*::\w*', '\h\w*\$\w*'],
    \},

@jalvesaq @gaalcaras any chance of improving nvim-r/deoplete interaction?

All 6 comments

I tried updating my sources to the new format:

call deoplete#custom#option('sources', {
    \ '_': ['file', 'buffer'],
    \ 'python': ['LanguageClient', 'ultisnips'],
    \ 'python3': ['LanguageClient', 'ultisnips'],
    \ 'rust': ['LanguageClient', 'ultisnips'],
    \ 'tex': ['ultisnips', 'omni'],
    \ 'r': ['LanguageClient', 'omni', 'ultisnips']
\})

but am still running into issues specifically with R.

(suggested at https://github.com/Shougo/deoplete.nvim/blob/master/doc/deoplete.txt#L1551 - is this a typo? I was under the impression input patterns should be a var, not a source)

Yes. It is typo.
call deoplete#custom#var() is correct.

call deoplete#custom#var('omni', 'input_patterns', {
    \ 'r': '[^. *\t]\.\w*',
\})
""" Deoplete and vimtex config
call deoplete#custom#var('omni', 'input_patterns', {
      \ 'tex' : g:vimtex#re#deoplete,
\})

It overwrites the previous configuration.

This is the correct pattern.

""" Deoplete and vimtex config
call deoplete#custom#var('omni', 'input_patterns', {
      \ 'tex' : g:vimtex#re#deoplete,
    \ 'r': '[^. *\t]\.\w*',
\})

Hi @Shougo, I'm trying to make deoplete work with nvim-r omnicompletion. I want to able to (auto)complete whenever I type .. However when I use the following minimal vimrc:

set nocompatible

let $DOTVIM = expand('$HOME/.vim')

set runtimepath+=$DOTVIM/bundle/repos/github.com/Shougo/deoplete.nvim
set runtimepath+=$DOTVIM/bundle/repos/github.com/jalvesaq/Nvim-R
filetype plugin indent on

let g:deoplete#enable_at_startup = 1
call deoplete#custom#var('omni', 'input_patterns', {
        \ 'r': '[^. *\t]\.\w*',
    \ }
\)

and in a empty foo.R file type data. the cursor jumps back just period the period. This can be seen in the following GIF:
may-01-2018 23-02-28

On the other hand I remove/comment the input_patterns lines and type C-X C-O after data. then the manual omnicompletion works just fine:
may-01-2018 23-01-16

Also how can I modify the regex to also autocomplete immediately after the following symbols ::, $?

I think nvim-r plugin does not support omni source.
You should use deoplete#custom#option() instead.

        call deoplete#custom#option('omni_patterns', {
        \ 'r': '[^. *\t]\.\w*',
        \})

Thanks @Shougo. Indeed adding the following seems to work:

    \ 'omni_patterns':  {
        \ 'r': ['[^. *\t]\.\w*', '\h\w*::\w*', '\h\w*\$\w*'],
    \},

@jalvesaq @gaalcaras any chance of improving nvim-r/deoplete interaction?

Was this page helpful?
5 / 5 - 1 ratings

Related issues

shibumi picture shibumi  路  4Comments

tchia04 picture tchia04  路  3Comments

callmekohei picture callmekohei  路  5Comments

ChristianChiarulli picture ChristianChiarulli  路  5Comments

iscekic picture iscekic  路  6Comments