From 698c3c4bf50b6f7304142e0b0299281d97ac4842 Mon Sep 17 00:00:00 2001 From: uga-rosa <82267684+uga-rosa@users.noreply.github.com> Date: Thu, 26 Aug 2021 14:25:30 +0900 Subject: [PATCH] Add FAQ for formatting.format (#79) * Add mapping example to README * move to FAQ section * add FAQ for formatting.format Update README.md Update README.md --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index 000c8c8..9f01d65 100644 --- a/README.md +++ b/README.md @@ -235,6 +235,8 @@ The return value is defined by vim. See `:help complete-items`. You can display the fancy icons to completion-menu with [lspkind-nvim](https://github.com/onsails/lspkind-nvim). +Please see [FAQ](#how-to-show-name-of-item-kind-and-source-like-compe) if you would like to show symbol-text (e.g. function) and source (e.g. LSP) like compe. + ```lua local lspkind = require('lspkind') cmp.setup { @@ -379,6 +381,28 @@ mapping = { } ``` +#### How to show name of item kind and source (like compe)? + +```lua +formatting = { + format = function(entry, vim_item) + -- fancy icons and a name of kind + vim_item.kind = require("lspkind").presets.default[vim_item.kind] + .. " " + .. vim_item.kind + -- set a name for each source + vim_item.menu = ({ + buffer = "[Buffer]", + nvim_lsp = "[LSP]", + luasnip = "[LuaSnip]", + nvim_lua = "[Lua]", + latex_symbols = "[Latex]", + })[entry.source.name] + return vim_item + end, +}, +``` + Source creation ====================