Closed maitra closed 8 months ago
Your code seems to be correct, but lazy.nvim
calls the setup()
function of plugins automatically. You could try to call the setup of R.nvim
and cmp-r
manually:
:lua << EOF
require("cmp").setup({ sources = {{ name = "cmp_r" }}})
require("cmp_r").setup()
require("r").setup()
EOF
Sorry, but the errors are still there. Pretty much the same errors:
Error detected while processing /home/maitra/.config/nvim/init.vim[5]:
line 45:
E5108: Error executing lua [string ":lua"]:1: module 'cmp' not found:
no field package.preload['cmp']
no file './cmp.lua'
no file '/usr/share/luajit-2.1/cmp.lua'
no file '/usr/local/share/lua/5.1/cmp.lua'
no file '/usr/local/share/lua/5.1/cmp/init.lua'
no file '/usr/share/lua/5.1/cmp.lua'
no file '/usr/share/lua/5.1/cmp/init.lua'
no file './cmp.so'
no file '/usr/local/lib/lua/5.1/cmp.so'
no file '/usr/lib64/lua/5.1/cmp.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
[C]: in function 'require'
[string ":lua"]:1: in main chunk
Error detected while processing BufNewFile Autocommands for "*":
Error executing lua callback: /usr/share/nvim/runtime/filetype.lua:24: Error executing lua: /usr/share/nvim/runtime/filetype.lua:25: BufNewFile Autocommands for "*"..FileType Autocommands for "*"..function <SNR>1_LoadFTPlugin[19]..script /home/maitra/.vim/plugged/R.nvim/ftplugin/r_rnvim.lua: Vim(runtime):E5113: Error while calling lua chunk: /usr/share/nvim/runtime/lua/vim/treesitter/language.lua:93: no parser for 'r' language, see :help treesitter-parsers
stack traceback:
[C]: in function 'error'
/usr/share/nvim/runtime/lua/vim/treesitter/language.lua:93: in function 'add'
/usr/share/nvim/runtime/lua/vim/treesitter/query.lua:252: in function 'parse'
/home/maitra/.vim/plugged/R.nvim/lua/r/send.lua:642: in main chunk
[C]: in function 'require'
/home/maitra/.vim/plugged/R.nvim/lua/r/run.lua:7: in main chunk
[C]: in function 'require'
/home/maitra/.vim/plugged/R.nvim/lua/r/config.lua:739: in function 'global_setup'
/home/maitra/.vim/plugged/R.nvim/lua/r/config.lua:803: in function 'real_setup'
/home/maitra/.vim/plugged/R.nvim/ftplugin/r_rnvim.lua:12: in main chunk
[C]: in function 'nvim_cmd'
/usr/share/nvim/runtime/filetype.lua:25: in function </usr/share/nvim/runtime/filetype.lua:24>
[C]: in function 'nvim_buf_call'
/usr/share/nvim/runtime/filetype.lua:24: in function </usr/share/nvim/runtime/filetype.lua:10>
stack traceback:
[C]: in function 'nvim_cmd'
/usr/share/nvim/runtime/filetype.lua:25: in function </usr/share/nvim/runtime/filetype.lua:24>
[C]: in function 'nvim_buf_call'
/usr/share/nvim/runtime/filetype.lua:24: in function </usr/share/nvim/runtime/filetype.lua:10>
stack traceback:
[C]: in function 'nvim_buf_call'
/usr/share/nvim/runtime/filetype.lua:24: in function </usr/share/nvim/runtime/filetype.lua:10>
Maybe the chunk :lua << EOF ... EOF
should be after call plug#end()
.
I updated the "minimal" example of https://github.com/R-nvim/R.nvim/wiki/Configuration
Then, trying to adapt it to your init.vim
:
:lua << EOF
require("nvim-treesitter.configs").setup({
sync_install = true,
ensure_installed = {
"r",
"markdown",
"markdown_inline",
"rnoweb",
},
})
local cmp = require("cmp")
cmp.setup({
sources = {{ name = "cmp_r" }},
mapping = cmp.mapping.preset.insert({
['<CR>'] = cmp.mapping.confirm({ select = false }),
-- During auto-completion, press <Tab> to select the next item.
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item({ behavior = cmp.SelectBehavior.Insert })
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item({ behavior = cmp.SelectBehavior.Insert })
else
fallback()
end
end, { 'i', 's' }),
}),
})
require("cmp_r").setup({ })
EOF
Thank you for looking into this! I now get a different error:
Error executing vim.schedule lua callback: /home/maitra/.vim/plugged/R.nvim/lua/r/server.lua:73: att
empt to concatenate upvalue 'libd' (a nil value)
stack traceback:
/home/maitra/.vim/plugged/R.nvim/lua/r/server.lua:73: in function </home/maitra/.vim/plugged
/R.nvim/lua/r/server.lua:71>
This is a bug in R.nvim
in a part of the code that has not been tested yet. Did you install R and don't have any package installed yet? R.nvim
is trying to create the directory where R packages will be installed. If you open R in the terminal and install any package manually, you should avoid this error.
Thanks! My R is installed on my Fedora 39 system. Packages have all been installed earlier. I just did nvim code.R
(where code.R
was a new file. How do I get around this error while editing R's script? Thanks very much again!
(Also R works as it should from the terminal.)
I'm trying to fix it...
Is the directory where nvimcom
is supposed to be installed writable?
So, my plugin installations are in ~/vimfiles/plugged
and that is writable. Am I answering your question here? Thanks!
No. The directory where nvimcom is going to be installed is something like ~/R/x86_64-pc-linux-gnu-library/4.3
or, more precisely, the output of Sys.getenv("R_LIBS_USER")
.
Oh, I see, sorry. Yes, it is writable: however, I usually install systemwide using sudo R
when needed (but that is not relevant to your question).
> Sys.getenv("R_LIBS_USER")
[1] "/home/maitra/R/x86_64-redhat-linux-gnu-library/4.3"
Is there a way to skip this local installation step?
I should add that the directory /home/maitra/R/
exists and is writable, however, there is nothing in there. Perhaps that is an issue?
It's incomplete. The "x86.../4.3" is missing
It's incomplete. The "x86.../4.3" is missing
I see. So, I create the directory, and the error goes away! However, the assignment does not work.
x_2
does not switch to x <- 2
in the edit/insert mode of nvim
.
Also, can I install nvimcom
systemwide using devtools
and use that? I don't really want or need to have local R packages installed.
I have to go out now...
Did you set assign_map?
I have to go out now... Did you set assign_map?
No worries, thanks for all your help! Oh, is that not set by default?
The default has changed.
Where you have:
require("cmp_r").setup({ })
you need:
require("cmp_r").setup({ })
require("r").setup({ assign_map = "_" })
I see. So, I create the directory, and the error goes away!
I have fixed the bug that was preventing R.nvim
from creating the directory. Could you, please, manually delete the directory ~/R/x86_64-redhat-linux-gnu-library/4.3
to confirm that R.nvim
now succeeds when trying to create it?
I see. So, I create the directory, and the error goes away!
I have fixed the bug that was preventing
R.nvim
from creating the directory. Could you, please, manually delete the directory~/R/x86_64-redhat-linux-gnu-library/4.3
to confirm thatR.nvim
now succeeds when trying to create it?
Yes, this works! Btw, is it possible to install nvimcom systemwide (and not have this directory at all), or is it needed for nvim-R to function?
Thanks for testing it!
Btw, is it possible to install nvimcom systemwide
I have never installed it systemwide, but, yes: https://github.com/jalvesaq/Nvim-R/issues/735
Where you have:
require("cmp_r").setup({ })
you need:
require("cmp_r").setup({ }) require("r").setup({ assign_map = "_" })
So, I tried this, and I was expecting that when I did
x_5
then it would automatically become x <- 5
in my R source code as happens in the case of ESS. However, that is not happening and it says x_5
in my R script.
Btw, I still have the error when I hit 'tab' in my R script file.
E5108: Error executing lua: [string ":lua"]:20: attempt to call global 'has_words_before' (a nil val
ue)
stack traceback:
[string ":lua"]:20: in function 'on_keymap'
/home/maitra/.vim/plugged/nvim-cmp/lua/cmp/core.lua:145: in function 'callback'
/home/maitra/.vim/plugged/nvim-cmp/lua/cmp/utils/keymap.lua:133: in function </home/maitra/.
vim/plugged/nvim-cmp/lua/cmp/utils/keymap.lua:127>
Where does this come from?
I have the following in my
.config/nvim/init.vim
file:However, when I load a file (say code.R), I get the following errors:
What is causing the error? How do I get around this? I am on Fedora 39 and neovim 0.9.5. Thanks!