GithubHelp home page GithubHelp logo

lspkind.nvim's Introduction

lspkind-nvim

This tiny plugin adds vscode-like pictograms to neovim built-in lsp:

Screenshot nvim-compe, vim-vsnip, vim-vsnip-integ, jellybeans-nvim

Requirements

Configuration

Option 1: vanilla Neovim LSP

Wherever you configure lsp put the following lua command:

require('lspkind').init({
    -- DEPRECATED (use mode instead): enables text annotations
    --
    -- default: true
    -- with_text = true,

    -- defines how annotations are shown
    -- default: symbol
    -- options: 'text', 'text_symbol', 'symbol_text', 'symbol'
    mode = 'symbol_text',

    -- default symbol map
    -- can be either 'default' (requires nerd-fonts font) or
    -- 'codicons' for codicon preset (requires vscode-codicons font)
    --
    -- default: 'default'
    preset = 'codicons',

    -- override preset symbols
    --
    -- default: {}
    symbol_map = {
      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 = "",
    },
})

Option 2: nvim-cmp

local lspkind = require('lspkind')
cmp.setup {
  formatting = {
    format = lspkind.cmp_format({
      mode = 'symbol', -- show only symbol annotations
      maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters)
                     -- can also be a function to dynamically calculate max width such as 
                     -- maxwidth = function() return math.floor(0.45 * vim.o.columns) end,
      ellipsis_char = '...', -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead (must define maxwidth first)
      show_labelDetails = true, -- show labelDetails in menu. Disabled by default

      -- The function below will be called before any actual modifications from lspkind
      -- so that you can provide more controls on popup customization. (See [#30](https://github.com/onsails/lspkind-nvim/pull/30))
      before = function (entry, vim_item)
        ...
        return vim_item
      end
    })
  }
}

Related LSP plugins

diaglist.nvim – live render workspace diagnostics in quickfix with current buf errors on top, buffer diagnostics in loclist

lspkind.nvim's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lspkind.nvim's Issues

Font Problem

Hi I am currently using fira code regular font and for some reason the variable icon is not working well. it tends to increase all icons, tilts, and cut it in half when displaying it. Just the variable one all the other icons work fine.
image
image
image

What font is this?

Sorry to make a new issue, I really loved this font. Can you let me know which nerd font this is?

Deprecated Error

Hey I get the following error. I tried a lot already but I can't fix it maybe someone has an idea?

used_by is deprecated, please use 'filetype_to_parsername'
Fehler beim Ausführen von "/Users/user/.config/nvim/after/plugin/lspkind.rc.lua":
E5113: Error while calling lua chunk: ...cal/share/nvim/plugged/lspkind-nvim/lua/lspkind/init.lua:123: Vim(echoerr):DEPRECATED replaced by mode option.
stack traceback:
        [C]: in function 'nvim_command'
        ...cal/share/nvim/plugged/lspkind-nvim/lua/lspkind/init.lua:123: in function 'init'
        /Users/user/.config/nvim/after/plugin/lspkind.rc.lua:4: in main chunk

I use these dot files: https://github.com/craftzdog/dotfiles-public

Thanks in advanced

clarify what you mean by adding to native lsp

I've figured out how to use this plugin with cmp but I don't understand exactly where to place the example code you have in the readme for integrating it directly with neovim lsp. was wondering if you might put that code into context in the readme, and add an image of what that style of integration is trying to accolmplish

Using the same icons as VS Code

Hello !

Following your post on Reddit (thanks for posting it by the way, quite useful !), I actually tried (and succeeded) to obtain the same icons in my terminal than the one used by VS Code. So this post is just to describe how I did it, in case you want to either add it as an option in the plugin, or just mention it as a solution somewhere.

This is done using Kitty, I don't know how to achieve it with an other terminal emulator. It should work for any font.

  1. Download the codicon font at https://github.com/microsoft/vscode-codicons/blob/master/dist/codicon.ttf and put it in your font folder (usually ~/.local/share/fonts), followed by a fc-cache.
  2. In your kitty.conf, add this line: symbol_map U+EA60-U+EBBC codicon.
  3. The kind symbols (with text) now looks like this. I've added two spaces each time between the symbol and the text because the symbols are displayed on two cells.
require('vim.lsp.protocol').CompletionItemKind = {
      '  Text';          -- = 1
      '  Function';      -- = 2;
      '  Method';        -- = 3;
      '  Constructor';   -- = 4;
      '  Field';         -- = 5;
      '  Variable';      -- = 6;
      '  Class';         -- = 7;
      '  Interface';     -- = 8;
      '  Module';        -- = 9;
      '  Property';      -- = 10;
      '  Unit';          -- = 11;
      '  Value';         -- = 12;
      '  Enum';          -- = 13;
      '  Keyword';       -- = 14;
      '  Snippet';       -- = 15;
      '  Color';         -- = 16;
      '  File';          -- = 17;
      '  Reference';     -- = 18;
      '  Folder';        -- = 19;
      '  EnumMember';    -- = 20;
      '  Constant';      -- = 21;
      '  Struct';        -- = 22;
      '  Event';         -- = 23;
      '  Operator';      -- = 24;
      '  TypeParameter'; -- = 25;
}

I've looked up the symbols on this webpage. This is the Product Icon Reference for Visual Studio. They are named symbol-text, symbol-function and so on.

The `codicons` are looking weird

System: macOS 12.0.1
Terminal: Kitty, iTerm2
Font Family: VictorMono Nerd

Description

No matter which terminal I was using (Kitty, iTerm2, or native terminal), and no matter which nerd font I was using, the codicons still didn't look good. Even when I copied the icons from github, they were still the same.

image

Fix codicon vertical alignment

Appreciate the work you've done on this plugin, really adds some nice UI touches to completions in nvim!

One thing that bothered me about the codicons preset is that the line height was off a bit causing the icons to be offset vertically and not centered properly with the text. It's not a bug with this plugin, more of a result of how the codeicons font is built.

I forked the codicons repo and modified the font generation to add some descent to the icons so that it would cause them to align properly. You can view my fork here: microsoft/vscode-codicons@main...mskelton:vscode-codicons:main.

I'm posting this issue more for others in the future if they want this improvement, as I don't see anything actionable unless you would like me to add some notes to the readme. Totally up to you.

Here is the result before and after (it's minor, but noticeable 🙂 )

Before

image

After

image

Work on COC

As the titles says. Can this work with coc?

Change color

How to change color for a kind of icons ?
For example, I would like function to be yellow and variable blue.

lsp-kind icons not working with nerd font.

I'm using lspkind (latest) and i'm using JetBrains Nerd Font, suddenly the icons that show on nvim-cmp stopped working, some icons work, some don't.

Here's what i'm getting:

image

Possible to override icons with nvim-cmp?

According to the README, I've gotten lspkind integrated with nvim-cmp nice and easy. However, I can't seem to override the symbol_map prop as before. Am I doing something wrong, or is it not possible anymore to override icons?

  formatting = {
    format = lspkind.cmp_format({
      with_text = true,
      maxwidth = 50,
      symbol_map = {
        File = '',
      }
    }),
  },

Does this support nvim-cmp

I just switched my config to use nvim-cmp as nvim-compe is now deprecated.

I have added this plugin and this line to my init.vim:

lua require 'lspkind'.init()

But the completion menu doesn't show the pictograms. I think that this plugin does not support nvim-cmp

Icons for missing kinds and suggestions for existing kinds

Problem

The following kinds are not defined:

  • Field
  • Reference
  • Event
  • Operator
  • TypeParameter

The following kinds are defined but could have better icons:

  • Method ƒ
  • Class

Solutions

I tried to find icons similar to the icons which are used by vscode. As a reference I used the official vscode-icon-reference. Search for symbol-class to find the icon for a class.

  • Field: Completely forgot to search for this one but since it is basically a variable I personally would use the same icon as the Variable-kind. I will leave it to somebody else to search for a better icon.
  • Reference: ⇲                  淚 漏 社 I think is nice and looks similar to vscode.
  • Event:       勞 異 𥉉 ﯓ ﯧ ﯦ ﱥ ﴞ  vscode has
  • Operator:  樂 洛 烈 ﲂ I hopped to find some kind of calculator icon like the vscode symbol where the four operations +-%= are shown but I couldn't find one. I picked for myself.
  • TypeParameter: T    﫳 My favorite is because generic types are usually put in such brackets.
  • Method
  • Class

I have no issues with the Keyword- and Text-kind but here are some alternatives:

  • Keyword:  
  • Text: this looks like the official vscode icon for text but is very small on my computer.

Related

#1
#5
#11

Document font requirements

Please forgive my ignorance but I'm probably missing something very obvious: The icons don't work at all for me.

image

What's weird is that I can not even see any icons in the browser (e.g. on the project's start page on github):

image

Could you maybe add some notes on which font is required to make this work?

OS: Linux Mint
Neovim 0.5.1

How to get source visible in the cmp menu?

I have passed following configuration to cmp. It shows the kind icons and text but not the source. What do I have to do to get the source shown in the menu similar to screenshot in the README.md such as [LSP]

formatting = {
        format = lspkind.cmp_format({
                mode = 'symbol_text',
                with_text = true,
                maxwidth = 50,
        }),
},

New class-icon

I find the current class- icon a little bit washed out and ambiguous. What about ?

bug: lspkind makes my language server crashing

Configuration

  • Neovim version: 0.5
  • OS: artix linux (a "fork" of arch linux)
  • language server: clangd 12.0.1
  • lspkind setup:
local lspkind = require('lspkind').init({symbol_map = {Enum = ''}})
--
lspconfig.clangd.setup{ on_attach=custom_attach, lspkind }

File: lsp.log

[ ERROR ] 2021-08-07T21:46:13+0200 ] /usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"clangd"	"stderr"	"I[21:46:13.904] ASTWorker building file /home/tony/files/Dev/C/libngi/src/caching.c version 78 with command \n[/home/tony/files/Dev/C/libngi]\n/usr/bin/cc -c -Og -g3 -fPIC -I include/ -o src/caching.o src/caching.c -fsyntax-only -resource-dir=/usr/lib/clang/12.0.1\n"
[ ERROR ] 2021-08-07T21:46:13+0200 ] /usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"clangd"	"stderr"	"I[21:46:13.923] --> textDocument/publishDiagnostics\n"
[ ERROR ] 2021-08-07T21:46:14+0200 ] /usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"clangd"	"stderr"	"I[21:46:14.031] <-- textDocument/didChange\n"
[ ERROR ] 2021-08-07T21:46:14+0200 ] /usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"clangd"	"stderr"	"I[21:46:14.067] <-- textDocument/completion(5)\n"
[ ERROR ] 2021-08-07T21:46:14+0200 ] /usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"clangd"	"stderr"	"I[21:46:14.073] Code complete: sema context ArrowMemberAccess, query scopes [] (AnyScope=true), expected type <none>\n"
[ ERROR ] 2021-08-07T21:46:14+0200 ] /usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"clangd"	"stderr"	"I[21:46:14.073] Code complete: 4 results from Sema, 0 from Index, 0 matched, 0 from identifiers, 4 returned.\n"
[ ERROR ] 2021-08-07T21:46:14+0200 ] /usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"clangd"	"stderr"	"I[21:46:14.073] --> reply:textDocument/completion(5) 6 ms\n"
[ ERROR ] 2021-08-07T21:46:14+0200 ] /usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"clangd"	"stderr"	"I[21:46:14.081] ASTWorker building file /home/tony/files/Dev/C/libngi/src/caching.c version 79 with command \n[/home/tony/files/Dev/C/libngi]\n/usr/bin/cc -c -Og -g3 -fPIC -I include/ -o src/caching.o src/caching.c -fsyntax-only -resource-dir=/usr/lib/clang/12.0.1\n"
[ ERROR ] 2021-08-07T21:46:14+0200 ] /usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"clangd"	"stderr"	"I[21:46:14.086] --> textDocument/publishDiagnostics\n"
[ ERROR ] 2021-08-07T21:46:14+0200 ] /usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]	"rpc"	"clangd"	"stderr"	"E[21:46:14.095] Transport error: Got signal, shutting down\nI[21:46:14.095] LSP finished, exiting with status 1\n"

Description

When i am writing -> after a struct, neovim just crash closing my terminal window. I have disabled the plugin and my language server doesn't crash so the crash just occur when the plugin is enabled and initialized.

[Q] Possible to highlight text with treesitter?

I know this is not a feature of lspkind but,
Is it possible to highlight text with treesitter in the before function and then displaying it?
It would be really nice if this was possible!

Show icons first then menu item second

I was using lspkind with nvim-cmp and it is working fine.
One thing i would like to have as an option is that, is there a way to make the icons appear first and then the menu item second ?

Screenshot from 2022-08-06 13-59-18

Show Icons First then menu item second
Screenshot from 2022-08-06 13-59-46

color scheme

which color scheme are you using in the README? :)

Document highlights

I love this plugin and use it daily.

Any chance we can get highlights for the symbols?

`init` is now requiring to pass empty table

After 5cd692b, the below will no longer work:

local lspkind = require("lspkind")
lspkind.init()

and raise an error:

...
E5113: Error while calling lua chunk: ...site/pack/packer/start/lspkind-nvim/lua/lspkind/init.lua:122: attempt to index local 'opts' (a nil value)
stack traceback:
        ...site/pack/packer/start/lspkind-nvim/lua/lspkind/init.lua:122: in function 'init'
        $HOME/.config/nvim/after/plugin/cmp.lua:3: in main chunk

The fix is to change the code to below - but ideally users are not forced to do this:

local lspkind = require("lspkind")
lspkind.init({})

Text type suggestion is off to the left by one.

image
Here is how it looks like.
I want all kinds to align perfectly. Is this a bug or is it because I have a messed up config.
Here is my nvim-cmp config:

	formatting = {
		format = lspkind.cmp_format({
			maxwidth = 50,
			ellipsis_char = "...",
		}),
	},

Formatting disappears upon navigating into the menu

While typing, the formatting shows up:

Screen Shot 2022-04-18 at 2 28 46 PM

But as soon as I press <C-n> to choose something, the formatting disappears (along with some options):

Screen Shot 2022-04-18 at 2 30 35 PM

This is my entire nvim-cmp configuration:

local cmp = require'cmp'

cmp.setup({
  snippet = {
    -- REQUIRED - you must specify a snippet engine
    expand = function(args)
      require('luasnip').lsp_expand(args.body)
    end,
  },
  mapping = {
    ['<C-d>']     = cmp.mapping.scroll_docs(-4),
    ['<C-f>']     = cmp.mapping.scroll_docs(4),
    ['<C-e>']     = cmp.mapping({
      i           = cmp.mapping.abort(),
      c           = cmp.mapping.close()
    }),
    ["<c-y>"]     = cmp.mapping.confirm({
        behavior  = cmp.ConfirmBehavior.Replace,
        select    = true,
    })
  },
  sources = {
    { name = 'nvim_lsp' },
    { name = 'luasnip' },
    { name = 'orgmode' },
    { name = 'nvim_lua' },
    { name = 'path' },
    { name = 'buffer', keyword_length = 5 },
  },
  experimental = {
    native_menu = false,
    ghost_text = true,
  },
  formatting = {
    format = require'lspkind'.cmp_format({
      with_text = true,
      menu = ({
        buffer = "[Buffer]",
        nvim_lsp = "[LSP]",
        nvim_lua = "[Lua]",
        path = "[Path]"
      })
    }),
  },
})

Codicons used in screenshot

Was wondering if it would be possible to have a list of the codicons you have in the README's screenshot alongside with the font necessary for them.

Icons are not displaying

There are no icons displaying when doing autocompletion (currently using nvim-compe). I don't know if my config is wrong, so here is a minimal config

-- Use and fetch plugins
require('packer').startup(function()
  use 'wbthomason/packer.nvim'
  
  use 'neovim/nvim-lspconfig'
  use 'hrsh7th/nvim-compe'
  
  use 'onsails/lspkind-nvim'
end)

-- Global options
vim.o.completeopt = 'menuone,noselect'

-- Compe settings
require'compe'.setup {
  enabled = true;
  autocomplete = true;
  debug = false;
  min_length = 1;
  preselect = 'enable';
  throttle_time = 80;
  source_timeout = 200;
  incomplete_delay = 400;
  max_abbr_width = 100;
  max_kind_width = 100;
  max_menu_width = 100;
  documentation = true;

  source = {
    path = true;
    buffer = true;
    calc = true;
    nvim_lsp = true;
    nvim_lua = true;
    vsnip = false;
  };
}

require('lspkind').init({})

Snippet symbol for UltiSnips

Could it be possible to add the snippet symbol also for UltiSnips or other snippet engines? I've checked the code, but I don't really know that much about Lua, so I don't know if the solution is trivial or would require some work.
It would be a nice addition, though.

DEPRECATED replaced by mode option.

Hi,

I changed my config to:

cmp.setup({
    ...
    formatting = {
        format = require("lspkind").cmp_format({
            mode = "symbol_text",
            maxwidth = 50,
        }),
    },
    ...
})

but still getting "DEPRECATED replaced by mode option" message on each attempt to autocomplete. I had to disable lsp-kind because it made cmp unusable.

deprecated error in lspkind

neovim 0.6

Error detected while processing /home/kgn/src/private/neovim/init.lua:
E5113: Error while calling lua chunk: ...site/pack/packer/start/lspkind-nvim/lua/lspkind/init.lua:123: Vim(echoerr):DEPRECATED replaced by mode option.
stack traceback:
[C]: in function 'nvim_command'
...site/pack/packer/start/lspkind-nvim/lua/lspkind/init.lua:123: in function 'init'
...site/pack/packer/start/lspkind-nvim/lua/lspkind/init.lua:163: in function 'cmp_format'
/home/kgn/.config/nvim/lua/config/cmp.lua:47: in main chunk
[C]: in function 'require'
/home/kgn/.config/nvim/init.lua:7: in main chunk

just updated

Feat: `symbol_text` but shortened text

Snippet -> snip or snp

Function -> func, fun, fn

etc

I've actually just been nerdsniped into thinking if its possible to algorithmically generate good unique abbreviations of a specified length from a list of words

Add option to show only text (no symbols)

I use neovim on multiple OSes and multiple PCs and I don't feel inclined to download and install a font on every machine. This means that all the symbols are usually broken.

I would suggest adding a text_only option rather than having a configuration that sets all the symbol_map fields to an empty string ""

Configuration would look like this:

-- nvim-cmp setting:
    formatting = {
        format = lspkind.cmp_format({
            text_only = true,
            menu = ({
                buffer = "[buff]",
                nvim_lsp = "[lsp]",
                luasnip = "[snip]",
                path = "[path]"
            })
        })
    }

-- default lsp config

require('lspkind').init({
    text_only = false,
    -- [... snip other config stuff ...]
})

Note that when text_only is set it would override the with_text setting since we can't have with_text = false when showing only text.

The popup would look like this:

popup example

You can find a working example in this fork.

color issues for sources

when I add source text it show this blue annoying color in every colorscheme
image
image

I can't find anything in doc (I could not found any doc for lspkind in vim) any idea to change this annoying color

lsp-status breakage

With latest commit lsp-status current function functionality has been broken when cmp_format been used. That happened due to, I guess, unintended modification of vim.lsp_protocol.SymbolKind in setup function.

Inconsistent symbol sizing

Hi there, first off, thank you for this wonderful plugin! It's really incredible how good a TUI can look these days and it's the polish like this plugin provides which really elevates the experience.

One thing I've noticed is that some of the codeicons are displayed of differing sizes and are clipped. I can't discern a pattern to this behavior: for instance, it might make sense if the width were varying between lines (see the screenshot below) but that isn't visibly the case.

Here's the environment I'm using:

  • macOS 12.6
  • kitty 0.25.2
  • tmux 3.2a
  • neovim 0.7

I've installed the VS Code codeicons (as you can hopefully see below) and am using a NerdFont-patched version of FiraCode.

Screen Shot 2022-09-21 at 8 01 16 AM

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.