Comments (20)
Just wanted to share my final solution without using any plugins:
formatting = {
format = function(entry, vim_item)
vim_item.menu = ({
nvim_lsp = '',
buffer = '',
})[entry.source.name]
vim_item.kind = ({
Text = '',
Method = '',
Function = '',
Constructor = '',
Field = '',
Variable = '',
Class = '',
Interface = 'ﰮ',
Module = '',
Property = '',
Unit = '',
Value = '',
Enum = '',
Keyword = '',
Snippet = '',
Color = '',
File = '',
Reference = '',
Folder = '',
EnumMember = '',
Constant = '',
Struct = '',
Event = '',
Operator = 'ﬦ',
TypeParameter = '',
})[vim_item.kind]
return vim_item
end
},
from nvim-cmp.
I say again. the changing vim.lsp.protocol.CompletionItemKind
is bad idea.
If some plugin checks vim.lsp.protocol.CompletionItemKind[item.kind] == 'Snippet'
, this will break with this customization.
from nvim-cmp.
Here's an example with codicons.nvim
:
local codicons = require "codicons"
local codiconsCIK = require("codicons.extensions.completion_item_kind").symbols
...
formatting = {
format = function(_, vim_item)
vim_item.kind = codicons.get(codiconsCIK[vim_item.kind].icon)
return vim_item
end,
},
from nvim-cmp.
Regarding https://github.com/microsoft/vscode-codicons, I found the ttf file does not work (at least on Linux). If you download the npm version npm i @vscode/codicons
that ttf
file version installs fine by double clicking it in Gnome. Once that is done, this solution works great with no plugins:
-- install .ttf file from npm i @vscode/codicons
local cmp_kinds = {
Text = " ",
Method = " ",
Function = " ",
Constructor = " ",
Field = " ",
Variable = " ",
Class = " ",
Interface = " ",
Module = " ",
Property = " ",
Unit = " ",
Value = " ",
Enum = " ",
Keyword = " ",
Snippet = " ",
Color = " ",
File = " ",
Reference = " ",
Folder = " ",
EnumMember = " ",
Constant = " ",
Struct = " ",
Event = " ",
Operator = " ",
TypeParameter = " ",
}
formatting = {
format = function(_, vim_item)
vim_item.kind = (cmp_kinds[vim_item.kind] or "") .. vim_item.kind
return vim_item
end,
},
Looking at the FAQ version, it is a little different, and does not define any entry.source.name
. I don't really understand the lua (copied it from reddit), is that a problem?
from nvim-cmp.
Also calling it completion-kind would be probably more correct than completion-menu.
from nvim-cmp.
I think it would be better if nvim-cmp would simply check for require('vim.lsp.protocol').CompletionItemKind
internally by itself. This is the official way to customize it and the only thing lspkind-nvim does is to set require('vim.lsp.protocol').CompletionItemKind
anyway. Making lspkind-nvim a dependency is really not necessary.
from nvim-cmp.
Putting
for index, value in ipairs(vim.lsp.protocol.CompletionItemKind) do
cmp.lsp.CompletionItemKind[index] = value
end
into my nvim-cmp configuration does the job nicely for me ...
from nvim-cmp.
Thanks. I think this should be the default. The use user should set it manually.
from nvim-cmp.
No... I think the changing defined value to customize is bad idea.
You should return your favorite kind icon via formatting.format
instead of modify cmp.lsp.CompletionItemKind
from nvim-cmp.
No... I think the changing defined value to customize is bad idea.
You should return your favorite kind icon via
formatting.format
instead of modify cmp.lsp.CompletionItemKind
Hmm I'm afraid I don't understand ...
I could not find any help to formatting.format
. Could you elaborate a bit more please?
from nvim-cmp.
@wimstefan There's an example here: https://github.com/hrsh7th/nvim-cmp#formattingformat-type-funentry-cmpentry-vim_item-vimcompleteditem-vimcompleteditem
from nvim-cmp.
@wimstefan There's an example here: https://github.com/hrsh7th/nvim-cmp#formattingformat-type-funentry-cmpentry-vim_item-vimcompleteditem-vimcompleteditem
Thanks a lot @ikalnytskyi 🙏
Unfortunately my skills are too lousy that I could get that working :/
from nvim-cmp.
@wimstefan You can take a peek at my configuration:
https://github.com/ikalnytskyi/dotfiles/blob/76e8528b9239a045075130f7c3c6437b19f6870f/nvim/.config/nvim/init.lua#L52-L78
https://github.com/ikalnytskyi/dotfiles/blob/76e8528b9239a045075130f7c3c6437b19f6870f/nvim/.config/nvim/init.lua#L254-L259
from nvim-cmp.
@ikalnytskyi this might work but I have two objections with this solution.
- Isn't
vim.lsp.protocol.CompletionItemKind
already builtin into neovim-lsp or do I get it wrong? If so than why shouldn't it be used by default by nvim-cmp instead of creating a custom solution for it. nvim-compe recognizesvim.lsp.protocol.CompletionItemKind
without any complicated interventions. - I find your solution too complicated to be honest and not intuitive at all. It should be as easy as setting a few variables. Just as it worked with
vim.lsp.protocol.CompletionItemKind
in nvim-compe.
from nvim-cmp.
@hrsh7th I did not realise implications setting vim.lsp.protocol.CompletionItemKind
up has. I was then interested to see what lspkind does and it seems like it also modifies it https://github.com/onsails/lspkind-nvim/blob/9cc326504e566f467407bae2669a98963c5404d2/lua/lspkind/init.lua#L100.
Perhaps it should be removed from README if it is such a bad idea and replaced with some safer way?
from nvim-cmp.
To be honest I still don't really understand why it's a bad thing to set CompletionItemKind. Maybe I just don't get what it purpose is if not defining completion-kind-icons but I trust @hrsh7th if he says so. I always assumed it to be correct because lspkind-nvim sets it internally and nvim-cmp recommends lspkind. Also nvim-compe seems to use CompletionItemKind for the icons. @hrsh7th you can close this issue if you want.
from nvim-cmp.
At least, In nvim-cmp, I prefer all menu customixation realises by formatting.format
. It's explicit way and super flexisible.
For example, you can change icon per source.
from nvim-cmp.
Anyway, Thank you for raising a question. It was a good point to me.
from nvim-cmp.
@hrsh7th @astier i check and the format function run everytime a completion item display
do we need to do that?
from nvim-cmp.
The formatting.format is always be cached.
from nvim-cmp.
Related Issues (20)
- 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?
- Suggestions disappearing
- [feature] Use in markdown code block. HOT 1
- Adding a file name `1` to the directory, causes any completion to fail.
- Slowdown with large files due to locality map HOT 3
- Error messages when inserting past null character
- Always slower than coc
- Wrong doc window position on multiple functions
- Doubt regarding capabilities HOT 5
- Lazy plugin manger does load cmp HOT 6
- [Discussion]: Map keys using vim.keymap.set() HOT 7
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.