Comments (29)
@ccshao nvim-cmp respects sources
order. and the cmp-buffer source avoid duplicated items by default.
So you can use the following config for the problem.
cmp.setup {
mapping = {
['<C-p>'] = cmp.mapping.prev_item(),
['<C-n>'] = cmp.mapping.next_item(),
['<C-d>'] = cmp.mapping.scroll(-4),
['<C-f>'] = cmp.mapping.scroll(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = true,
})
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'path' },
{ name = 'buffer' },
},
documentation = false,
}
from nvim-cmp.
Note: nvim-lsp source set dup=1
by default.
from nvim-cmp.
Yes. It is understandable to me.
Your expected behavior can be realized with the following config maybe.
sources = {
{ name = 'buffer',
opts = {
get_bufnrs = function()
local bufs = {}
for _, win in ipairs(vim.api.nvim_list_wins()) do
bufs[vim.api.nvim_win_get_buf(win)] = true
end
return vim.tbl_keys(bufs)
end
}
},
{ name = 'nvim_lsp' },
{ name = 'path' },
},
formatting = {
format = function(entry, vim_item)
vim_item.menu = ({
nvim_lsp = '[L]',
emoji = '[E]',
path = '[F]',
calc = '[C]',
vsnip = '[S]',
buffer = '[B]',
})[entry.source.name]
vim_item.dup = ({
buffer = 1,
path = 1,
nvim_lsp = 0,
})[entry.source.name] or 0
return vim_item
end
},
from nvim-cmp.
I've fixed the bug! f3a5491
Now, You can fully customizable vim' completion item (See :help complete-items
)
from nvim-cmp.
@ccshao nvim-cmp respects
sources
order. and the cmp-buffer source avoid duplicated items by default.So you can use the following config for the problem.
cmp.setup { mapping = { ['<C-p>'] = cmp.mapping.prev_item(), ['<C-n>'] = cmp.mapping.next_item(), ['<C-d>'] = cmp.mapping.scroll(-4), ['<C-f>'] = cmp.mapping.scroll(4), ['<C-Space>'] = cmp.mapping.complete(), ['<C-e>'] = cmp.mapping.close(), ['<CR>'] = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true, }) }, sources = { { name = 'nvim_lsp' }, { name = 'path' }, { name = 'buffer' }, }, documentation = false, }
This looks like there is no difference
from nvim-cmp.
No. The sources
order is changed.
from nvim-cmp.
Inddeed swapping the order works.
I just found something interesting, that buffer
could find other candidates in other buffers.
In the example bellow, I have a few words in 1.R
, and split 2.R
in the same window. When I type libr
, there are no candidates from 1.R
, namely, libre
, librart
, but only from lsp
. The order of buffer
does not matter.
What do I need to add to the config to let nvim-cmp see other buffers?
from nvim-cmp.
It is a source-related customization. See https://github.com/hrsh7th/cmp-buffer
cmp.setup {
mapping = {
['<C-p>'] = cmp.mapping.prev_item(),
['<C-n>'] = cmp.mapping.next_item(),
['<C-d>'] = cmp.mapping.scroll(-4),
['<C-f>'] = cmp.mapping.scroll(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = true,
})
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'path' },
{
name = 'buffer',
opts = {
get_bufnrs = function()
local bufs = {}
for _, win in ipairs(vim.api.nvim_list_wins()) do
bufs[vim.api.nvim_win_get_buf(win)] = true
end
return vim.tbl_keys(bufs)
end
}
},
},
}
from nvim-cmp.
No. The
sources
order is changed.
Big shock, it's time to adjust my configuration again
from nvim-cmp.
Sorry for confusion. I thoughts it is intuitive way.... TT
from nvim-cmp.
Thanks!
May I bother you with another small issue? The reason I put buffer
ahead of lsp
is buffer
candidates are usually more relevant.
Now the lsp
are top candidates, how could I give more weights to buffer
candiates? I think it is related to priority_weight
but I don't know how to tweak it.
from nvim-cmp.
@ccshao It is not supported as suitable way but nvim-cmp provides fully customizable vim's completion item by the user.
cmp.setup {
formatting = {
format = function(entry, vim_item)
if entry.source.name == 'nvim_lsp' then
vim_item.dup = 0
end
return vim_item
end
}
}
from nvim-cmp.
Thanks for the suggestions, sorry I don't know much about vimscript/lua. The above formating
codes seems not put the lsp
candidates behind all buffer
candidates.
In the example, I would like to get TEXT
candidates in front of Function/Module/Feld
from lsp
.
lua << EOF
local cmp = require'cmp'
cmp.setup {
mapping = {
['<C-p>'] = cmp.mapping.prev_item(),
['<C-n>'] = cmp.mapping.next_item(),
['<C-d>'] = cmp.mapping.scroll(-4),
['<C-f>'] = cmp.mapping.scroll(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = true,
})
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'path' },
{ name = 'buffer',
opts = {
get_bufnrs = function()
local bufs = {}
for _, win in ipairs(vim.api.nvim_list_wins()) do
bufs[vim.api.nvim_win_get_buf(win)] = true
end
return vim.tbl_keys(bufs)
end
}
},
},
formatting = {
format = function(entry, vim_item)
if entry.source.name == 'nvim_lsp' then
vim_item.dup = 0
end
return vim_item
end
},
documentation = false,
}
require('cmp_nvim_lsp').setup {}
EOF
from nvim-cmp.
-
Prefer buffer source than nvim-lsp source
You should change thesources
option order. The first item will be show to the top. -
nvim-lsp source should hide if the buffer source's same word item exists.
You can specify the aboveformatting.format
option
from nvim-cmp.
I might get the logic, so the buffer
is ahead of lsp
in the source setting, and add the formation
options.
sources = {
{ name = 'buffer',
opts = {
get_bufnrs = function()
local bufs = {}
for _, win in ipairs(vim.api.nvim_list_wins()) do
bufs[vim.api.nvim_win_get_buf(win)] = true
end
return vim.tbl_keys(bufs)
end
}
},
{ name = 'path' },
{ name = 'nvim_lsp' },
},
formatting = {
format = function(entry, vim_item)
if entry.source.name == 'nvim_lsp' then
vim_item.dup = 0
end
return vim_item
end
},
However, now I get duplicated candidates from buffer
...
from nvim-cmp.
However, now I get duplicated candidates from
buffer
...
If you don't want to have dup items you can delete formatting section. The cmp will hide dup items by default.
from nvim-cmp.
Strangely I still see the duplicated candidates, with a miminum setting:
lua << EOF
local cmp = require'cmp'
cmp.setup {
mapping = {
['<C-p>'] = cmp.mapping.prev_item(),
['<C-n>'] = cmp.mapping.next_item(),
['<C-d>'] = cmp.mapping.scroll(-4),
['<C-f>'] = cmp.mapping.scroll(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = true,
})
},
sources = {
{ name = 'buffer' },
{ name = 'path' },
{ name = 'nvim_lsp' },
},
documentation = false,
}
require('cmp_nvim_lsp').setup {}
EOF
To get ride of duplicates, I have to put { name = 'nvim_lsp' },
ahead of { name = 'buffer' },
.
from nvim-cmp.
I think nvim_lsp
candidates set dup
, so you need to set dup=0
if don't like the dup.
from nvim-cmp.
Hm... Could you share your environment to testing?
Language Server
File content
etc
from nvim-cmp.
It's may be a bug. I will investigate it.
from nvim-cmp.
I am bit of lost in the settings, so here is the summary, with nvim 0.5.0, all latest plugins, and R language server.
setting 1. Works great, no redundant candidates from buffer and lsp.
sources = {
{ name = 'nvim_lsp' },
{ name = 'path' },
{ name = 'buffer',
opts = {
get_bufnrs = function()
local bufs = {}
for _, win in ipairs(vim.api.nvim_list_wins()) do
bufs[vim.api.nvim_win_get_buf(win)] = true
end
return vim.tbl_keys(bufs)
end
}
},
},
setting 2. Duplicated items from buffer (indicated by "Text" in the popup)
sources = {
{ name = 'buffer' },
{ name = 'path' },
{ name = 'nvim_lsp' },
},
" or with buffer config
sources = {
{ name = 'buffer',
opts = {
get_bufnrs = function()
local bufs = {}
for _, win in ipairs(vim.api.nvim_list_wins()) do
bufs[vim.api.nvim_win_get_buf(win)] = true
end
return vim.tbl_keys(bufs)
end
}
},
{ name = 'nvim_lsp' },
{ name = 'path' },
},
from nvim-cmp.
Thank you for your information.
I guess the R language server returns items that contain the same duplicated Text entries.
I will provide debuggable configuration for it. Please wait.
from nvim-cmp.
formatting = {
format = function(entry, vim_item)
vim_item.kind = lspkind.presets.default[vim_item.kind]
vim_item.menu = ({
nvim_lsp = '[L]',
emoji = '[E]',
path = '[F]',
calc = '[C]',
vsnip = '[S]',
buffer = '[B]',
})[entry.source.name]
return vim_item
end
}
@ccshao Could you test with this config?
It can be used to detect which source returned the item.
from nvim-cmp.
Then can you try this?
formatting = {
format = function(entry, vim_item)
vim_item.menu = ({
nvim_lsp = '[L]',
emoji = '[E]',
path = '[F]',
calc = '[C]',
vsnip = '[S]',
buffer = '[B]',
})[entry.source.name]
return vim_item
end
from nvim-cmp.
Seems the duplilcated from both lsp
and buffer
.
sources = {
{ name = 'buffer',
opts = {
get_bufnrs = function()
local bufs = {}
for _, win in ipairs(vim.api.nvim_list_wins()) do
bufs[vim.api.nvim_win_get_buf(win)] = true
end
return vim.tbl_keys(bufs)
end
}
},
{ name = 'nvim_lsp' },
{ name = 'path' },
},
formatting = {
format = function(entry, vim_item)
vim_item.menu = ({
nvim_lsp = '[L]',
emoji = '[E]',
path = '[F]',
calc = '[C]',
vsnip = '[S]',
buffer = '[B]',
})[entry.source.name]
return vim_item
end
},
If I put the buffer
at the end of source, then all comes from lsp
.
from nvim-cmp.
I still get the duplicated candidates from both lsp and buffer with exactly the above settings ...
from nvim-cmp.
Thsnk you and Sorry for annoying.
I think the above config dhould work so I will investigate it.
from nvim-cmp.
I just try with a python script with pylsp
, again duplicated candidates. So might not be an issue from lsp.
from nvim-cmp.
Thank you very much for bing patience on this small issue!
from nvim-cmp.
Related Issues (20)
- suggestion: add "type checking" for sources
- Extra TS text appearing when doing cmp.mapping.select_next_item() HOT 4
- There's some extra `${}` text inserted when selecting first item HOT 1
- Mapping Enter or Shift-Enter does not work as expected
- cmdline completion runs git commands resulting in many passphrase popups
- Selection cursor doesn't appear at the top of the autocompletion list for gopls HOT 3
- Please consider not using global variables HOT 4
- Documentation window obstructs suggestions window when suggestions window is too wide. HOT 1
- Fallback actions in `c` mode might be bugged for `Esc` HOT 2
- Goto next group_index ? HOT 1
- Main suggestion gets stuck in buffer, after changing focus to another window
- Speed / lag is hard to troubleshoot ? HOT 1
- Text completion does not include words with UTF-8 characters that take up more that a single byte HOT 1
- Tailwind CSS autocompletion isn't working
- TailwindCSS performance issues HOT 11
- [Deprecation] Neovim 0.10 warns with `vim.lsp.util.parse_snippet() is deprecated. :help deprecated` HOT 5
- some cmp items in a bundle of same items from different source are lost , with keyword become more HOT 1
- Crash plugin while navigate in menu snippets LuaSnip (nvim-cmp/lua/cmp/utils/str.lua:81: bad argument #1 to byte (string expected, got table) HOT 3
- Unable to set custom key mappings for command mode autocompletion
- How to disable text suggestion related to language?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nvim-cmp.