Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ncm-R not working consistently #9

Open
marskar opened this issue Feb 14, 2018 · 22 comments
Open

ncm-R not working consistently #9

marskar opened this issue Feb 14, 2018 · 22 comments

Comments

@marskar
Copy link

marskar commented Feb 14, 2018

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?

@gaalcaras
Copy link
Owner

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 :)

@marskar
Copy link
Author

marskar commented Feb 25, 2018

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.

@kohyamat
Copy link

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.

@gaalcaras
Copy link
Owner

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 jalvesaq/Nvim-R#276 and #8). jalvesaq solved it with jalvesaq/Nvim-R@311e585, then he changed the way Nvim-R detects local charsets : jalvesaq/Nvim-R@5de878a then jalvesaq/Nvim-R@5bfb647. Maybe these changes impacted macOS users somehow?

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

@jalvesaq what do you think?

@marskar
Copy link
Author

marskar commented Feb 28, 2018

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?

@jalvesaq
Copy link

The Python log has the following:

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

The issue was caused by jalvesaq/Nvim-R@2dc4962

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
Copy link

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.

@gaalcaras
Copy link
Owner

gaalcaras commented Feb 28, 2018

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
Copy link
Owner

431cf47 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.

@marskar
Copy link
Author

marskar commented Mar 12, 2018

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 marskar closed this as completed Mar 12, 2018
@kohyamat
Copy link

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

@gaalcaras
Copy link
Owner

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

@fifdick
Copy link

fifdick commented Mar 18, 2019

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.

@AlfredSAM
Copy link

@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

@jalvesaq
Copy link

jalvesaq commented Aug 2, 2020

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: jalvesaq/Nvim-R@dd27290

@marskar marskar reopened this Aug 2, 2020
@marskar
Copy link
Author

marskar commented Aug 2, 2020

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.

@xllvrr
Copy link

xllvrr commented Sep 17, 2020

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!

@statquant
Copy link

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

@marskar
Copy link
Author

marskar commented Sep 24, 2020

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

@AlfredSAM
Copy link

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

@statquant
Copy link

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

@mskar
Copy link

mskar commented Oct 17, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants