jalvesaq / cmp-nvim-r

GNU General Public License v3.0
18 stars 1 forks source link

How can I automatically trigger completion after <space>, #8

Closed statquant closed 1 year ago

statquant commented 1 year ago

Hello, I am migrating from vim to neovim and I am trying to setup the auto-completion. I cannot find out how to setup completion while completing R function arguments.

For instance if I do data.table::fread(<tab> everything works perfectly and I'll see all the options. I chose <tab> for completion so I can complete say input but for the next argument it only completes after comma data.table::fread(input = my_file,<tab> this will work perfectly. But if I do data.table::fread(input = my_file, <tab> (note the space before the tab) this won't work (unless I ask for completion explicitly with <ctrl><space> (that I have set).

This still annoys me because I abide by the usual RStudio coding style which requires function(arg = val1, arg2 = val2) which requires <space> after commas.

I realize that this is merely a nvim-comp setting and not really a cmp-nvim-r but because you usually give useful tips in the docs and this is likely to be useful to many people I dare to ask.

jalvesaq commented 1 year ago

Completion with cmp-nvim-r is not triggered by <Space>, but I created a branch for this: https://github.com/jalvesaq/cmp-nvim-r/tree/space Can you try it, please? If it does not have any undesired side effects, I will add <Space> to the list of triggering characters in the main branch.

statquant commented 1 year ago

Hello @jalvesaq, sorry for the delay in the answer. I tested your branch and it works perfectly. Thank you very much for this.

I have a follow up question, when selecting from argument selection say

data.table::fread(file = "toto", <here>)

any selection will insert choice =<cursor here> is there a way to parametrize this so I get choice = <cursor here> (an additional space between = and ) I would be much slicker and would not trigger completion another time while the user just intend to enter the value for the argument.

jalvesaq commented 1 year ago

The space is already added:

https://github.com/jalvesaq/cmp-nvim-r/blob/46e250700f53aabecd9726f09055a01f74bd90bd/lua/cmp_nvim_r/init.lua#L341

But it seems that cmp-nvim removes it:

https://github.com/hrsh7th/nvim-cmp/blob/5dce1b778b85c717f6614e3f4da45e9f19f54435/lua/cmp/entry.lua#L116