ncm-R icon indicating copy to clipboard operation
ncm-R copied to clipboard

ncm-R not working consistently

Open marskar opened this issue 6 years ago • 22 comments

I can't get ncm-R to work consistently. I see autosuggestions only sometimes. I would like the plugin to work like in your video.

I'm on a Mac OS High Sierra (10.13.2 (17C205)) using brew installed neovim.

NVIM v0.2.2
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 -DNDEB
UG -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-20180209-92407-udkzoo/neovim-0.2.2/build/config -I/tmp/neovim-20180209-92407-udkzoo/neovim-0.2.2/src -I/usr/local/include -I/usr/loc

I tried both brew installed python3 with pip3 neovim installed and conda install python 3 and neovim client. Do you have any suggestions of how to figure this out?

marskar avatar Feb 14 '18 22:02 marskar

Thanks for your feedback!

First, you should check whether the bug comes from NCM or ncm-R. Python completion is a built-in feature of NCM so that's a good place to start.

If NCM's Python completion works reliably 100% of the time, then there's probably something wrong with ncm-R. You should then try to find out if there's a pattern in the failures. Reading the logs in real time while trying to trigger the autocompletion is your best best. See this part of the README for instructions on how to debug this.

I'm sorry I'm unable to help you here, as I don't use macOS and I'm not able to reproduce your issue myself. Any contribution from your part is more than welcome :)

gaalcaras avatar Feb 22 '18 15:02 gaalcaras

I confirmed that NCM Python completion is working but still having problems with ncm-R. Sometimes ncm-R works perfectly, but most of the time it only suggests packages to put inside of my library() and require() calls. I will look at the logs and let you know.

marskar avatar Feb 25 '18 20:02 marskar

I had the same problem on my macOS Sierra (10.12.6). Rolling back NVIM-R to the commit 41459c1 (tag v0.9.11) worked for me. I would love to know why though. I'm using neovim (v0.2.2) installed with homebrew and python client to neovim (0.2.1) with pip3.

kohyamat avatar Feb 26 '18 02:02 kohyamat

Rolling back NVIM-R to the commit 41459c1 (tag v0.9.11) worked for me. I would love to know why though.

Interesting. Most of the changes after 41459c1 relate to the encoding of completion data generated by Nvim-R, which some ncm-R Windows users had problems with (see https://github.com/jalvesaq/Nvim-R/issues/276 and https://github.com/gaalcaras/ncm-R/issues/8). jalvesaq solved it with https://github.com/jalvesaq/Nvim-R/commit/311e585fa77326099ea08e3cb731fef8697e9298, then he changed the way Nvim-R detects local charsets : https://github.com/jalvesaq/Nvim-R/commit/5de878a5bcfe990458493ba46c88bdcb28b0e10e then https://github.com/jalvesaq/Nvim-R/commit/5bfb64703c3513beb3244ed0e2e0dfa7494deca7. Maybe these changes impacted macOS users somehow?

@marskar could you try to rollback Nvim-R to 41459c1 as well?

@jalvesaq what do you think?

gaalcaras avatar Feb 28 '18 09:02 gaalcaras

Wow, it is working now! Thanks @t2ok ! I never would have thought to try this. @gaalcaras, @jalvesaq, is there anything I can do to help figure this out?

marskar avatar Feb 28 '18 15:02 marskar

The Python log has the following:

FileNotFoundError: [Errno 2] No such file or directory: '/tmp/Nvim-R-aquino/GlobalEnvList_'

The issue was caused by https://github.com/jalvesaq/Nvim-R/commit/2dc4962e6a1962487ad8de08e17b411bb39ef750

Because Nvim-R no longer uses Python to generate random numbers, the environment variables NVIMR_ID and NVIMR_SECRET are defined only when starting the nclientserver job. Consequently, the file /GlobalEnvList_$NVIMR_ID is created only after starting R. So, @gaalcaras, could you, please, check if the file exists before trying to read it, and consider the list empty if the file does not exist yet?

jalvesaq avatar Feb 28 '18 15:02 jalvesaq

We still may have problems with encoding. I could test R running within Cygwin on Windows and discovered that localeToCharset() returns "UTF-8" but, in fact, R cannot handle UTF-8 properly. The issue can be tested trying to complete as.matrix.noquote which has single quotes in its description.

jalvesaq avatar Feb 28 '18 16:02 jalvesaq

So, @gaalcaras, could you, please, check if the file exists before trying to read it, and consider the list empty if the file does not exist yet?

Sure, I'll keep all of you posted. Thanks for your input, I wasn't aware of this change.

We still may have problems with encoding.

Well, don't we always? Anyways, someone using Windows is welcome to test this out.

gaalcaras avatar Feb 28 '18 18:02 gaalcaras

https://github.com/gaalcaras/ncm-R/commit/431cf473bdac0722f4ab8e81074d3cdb55eecc29 now checks for the file existence first. @t2ok @marskar can you tell me if this makes ncm-R work better with Nvim-R? You'll have to checkout branch globenv-fix.

gaalcaras avatar Mar 12 '18 12:03 gaalcaras

Awesome! It works flawlessly now. Thank you @gaalcaras and @jalvesaq for ncm-R and Nvim-R (amazing tools that I use every day) and for resolving this issue. Thank you @t2ok for your help in figuring this out. I'm going to close this issue now because 431cf47 solves the problem for me completely.

marskar avatar Mar 12 '18 13:03 marskar

Great! It works perfectly on my machine too. Thank you for your kind support.

kohyamat avatar Mar 13 '18 01:03 kohyamat

Great! I've merged it to master, please use that to benefit from future updates.

gaalcaras avatar Mar 14 '18 08:03 gaalcaras

I have the same problem of inconsistently working ncm-r since a few weeks. I get completion suggestions that are labeled "key" and also when Im inside and open quote writing file names I get all correct completion suggestions for the file directory structure. Nothing else works, no function recognition not objects that are loaded, etc. I tried to use the solution of using tag 431cf47 with vim-plug in neovim ( Plug 'gaalcaras/ncm-R', { 'commit': '41459c1' }) But it didnt work as the reference is invalid : fatal: invalid reference: 41459c1 It worked for about a year and suddenly stopped working. Im using it with R version 3.5.3 (2019-03-11) and nvim

NVIM v0.3.0-1074-g009ccfe17
Build type: RelWithDebInfo
LuaJIT 2.0.5

Id be glad for help and im sorry if I didnt provide all necessary information to help debugging. Please let me know which further information you need.

fifdick avatar Mar 18 '19 08:03 fifdick

@fifdick Hello! I also has similar problems when using nvim-R and ncm-R. That is, when editing the *.R file, I can only get the suggestions about the existing packages for library() and require() functions. However, I cannot get other suggestions, like what they illustrate in the website: " Objects from the global R environment Variables of a dataframe when selecting columns inside brackets (dataframe[,]) or after a $ Functions from loaded packages or from specific package with package:: " Referring to the suggestions above, I find the following can make the above functions work.

Plug 'jalvesaq/Nvim-R', { 'tag': 'v0.9.11' }
Plug 'gaalcaras/ncm-R'

Even though I tried 431cf47 for ncm-R, it did not work. In order to enhance the completion function, I also use

" ncm completion source for general purpose
Plug 'ncm2/ncm2-bufword'
Plug 'ncm2/ncm2-path'
" Optional: for snippet support
Plug 'Shougo/neosnippet.vim'
Plug 'ncm2/ncm2-neosnippet'

Here is my sessionInfo() for your reference:

R version 4.0.2 (2020-06-22) Platform: x86_64-apple-darwin17.0 (64-bit) Running under: macOS Catalina 10.15.6

Matrix products: default BLAS: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages: [1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached): [1] compiler_4.0.2

NVIM v0.4.3 Build type: Release LuaJIT 2.0.5

AlfredSAM avatar Aug 02 '20 02:08 AlfredSAM

A couple of months ago, I introduced some incompatible changes in the omnils_ files used by ncm-R, and only now I have described the new fields: https://github.com/jalvesaq/Nvim-R/commit/dd27290e8fa51c37b75d6a1f9452b6b038773ee5

jalvesaq avatar Aug 02 '20 11:08 jalvesaq

Given the new comments by @fifdick, @AlfredSAM, and @jalvesaq, I reopened this issue. I think making ncm-R compatible with the changes @jalvesaq made to the omnils_ files should resolve the problems experienced by @fifdick and @AlfredSAM.

marskar avatar Aug 02 '20 12:08 marskar

I am also experiencing the same difficulties as @AlfredSAM and @fifdick ; this issue also only cropped up recently, so I'm assuming it's because of the changes that Jalvesaq made. Thanks for opening the issue!

xllvrr avatar Sep 17 '20 02:09 xllvrr

That’s probably a good time to switch to r-lsp unfortunately i cannot fond any clear setup instructions

statquant avatar Sep 17 '20 17:09 statquant

@statquant, I agree. I gave r-lsp a try via a coc plugin called coc-r-lsp. I am running it in vimr (no relation to Nvim-R), so I can send code with command enter (like in RStudio on MacOS). I installed coc via vim-plug and the languageserver R package install.packages("languageserver"), then ran :CocInstall coc-r-lsp, and everything is working OK so far.

marskar avatar Sep 24 '20 01:09 marskar

@marskar @statquant Yes. I also try coc-r-lsp with nvim-R in nvim, and it seems to work well. I also use ALE to help format the codes automatically.

AlfredSAM avatar Sep 24 '20 14:09 AlfredSAM

@marskar and @AlfredSAM while coc-r works I have difficulties getting a lot from it. Somehow I fail to find documentation on how to setup all the features. Would you mind sharing what you have ? maybe we could create a gist with it and get a little bit more out of it.

statquant avatar Oct 17 '20 15:10 statquant

@statquant, I don't think there are any coc-r-lsp features to set up. Diagnostics (with lintr) are enabled by default.

There are however many awesome features available in the coc ecosystem of extensions. I highly recommend setting up snippets:

  1. Enable snippet support in ~/.Rprofile:
options(
    languageserver.server_capabilities = list(
        snippetSupport = TRUE
    )
)
  1. Install the vim-snippets plugin via ~/.vimrc and/or ~/.config/nvim/init.vim
  2. Install the coc-snippets extension via ~/.vimrc and/or ~/.config/nvim/init.vim
  3. Set your snippet bindings:
let g:coc_snippet_next = '<tab>'
let g:coc_snippet_prev = '<s-tab>'
  1. Modify autocompletion settings via coc-settings.json, .vimrc, and/or ~/.config/nvim/init.vim if you don't like the default behavior.
  2. Put custom R snippets in~/.config/coc/ultisnips/r.snippets. I don't have any custom R snippets yet, but you can use my all.snippets file as an example.

Other than coc-snippets, I also recommend installing the coc-yank and coc-pairs extensions via ~/.vimrc and/or init.vim.

mskar avatar Oct 17 '20 16:10 mskar