Shougo / deoplete.nvim

:stars: Dark powered asynchronous completion framework for neovim/Vim8
Other
5.94k stars 295 forks source link

Completion support for R - nvim-r and/or language server #745

Closed dryya closed 6 years ago

dryya commented 6 years ago

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

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

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

dryya commented 6 years ago

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.

Shougo commented 6 years ago

(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.

Shougo commented 6 years ago

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*',
\})
petobens commented 6 years ago

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 ::, $?

Shougo commented 6 years ago

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*',
        \})
petobens commented 6 years ago

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?

rahil627 commented 2 years ago

thank goodness for this!

i was having trouble with the deoplete#custom#var, but this one seemed to work!:

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

..now to learn regex to make it work for haxe’s input patterns ;(

haha sorry, new to all this :)

i was sooo close to giving up and trying the new ddc stuff too! Google is amazing.

Shougo commented 2 years ago

ddc.vim is better than deoplete.

rahil627 commented 2 years ago

hmmm, yeah, i might try it next...

but my server was struggling so bad with deoplete, i switched to SuperTab, which is still quite slow, lol. Maybe if i had set it up to work only after the first character, it might be tolerable. 😜