美文网首页
NVIM COC + lspkind-nvim

NVIM COC + lspkind-nvim

作者: 夙小叶 | 来源:发表于2021-09-04 22:09 被阅读0次
    截屏2021-09-04 21.52.43.png

    就是给片段引擎加上个类似 VSCode 的类型图标,反正就是好看。颜值就是动力

    截屏2021-09-04 21.50.39.png

    coc-settings.json 中添加下面的代码(确保使用修补后的字体: 类似 Nerd Font)

    {
        "suggest.completionItemKindLabels": {
            "keyword":       "\uf1de",
            "variable":      "\ue79b",
            "value":         "\uf89f",
            "operator":      "\u03a8",
            "function":      "\u0192",
            "reference":     "\ufa46",
            "constant":      "\uf8fe",
            "method":        "\uf09a",
            "struct":        "\ufb44",
            "class":         "\uf0e8",
            "interface":     "\uf417",
            "text":          "\ue612",
            "enum":          "\uf435",
            "enumMember":    "\uf02b",
            "module":        "\uf40d",
            "color":         "\ue22b",
            "property":      "\ue624",
            "field":         "\uf9be",
            "unit":          "\uf475",
            "event":         "\ufacd",
            "file":          "\uf723",
            "folder":        "\uf114",
            "snippet":       "\ue60b",
            "typeParameter": "\uf728",
            "default":       "\uf29c"
        }
    }
    

    neovim 的内置 LSP 也可以配合使用。配合在 nvim-cmp 上,不需要安装插件的

    -- filename: lspkind.lua
    
    -- 不使用 lspkind 插件,只使用他它的图标
    
    local M = {}
    
    M.symbol_icons = {
        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 = ""
    }
    
    return M
    
    -- filename: nvimcmp.lua
    
    local present, cmp = pcall(require, "cmp")
    
    if not present then
        return
    end
    
    cmp.setup {
        snippet = {
            expand = function(args)
                -- 使用 luasnip 片段引擎
                require("luasnip").lsp_expand(args.body)
            end
        },
        -- 设置如何显示项目类型和来源的名称
        formatting = {
            format = function(entry, vim_item)
                -- fancy icons and a name of kind
                vim_item.kind = string.format("%s %s", require("plugins.config.lspkind").symbol_icons[vim_item.kind], vim_item.kind)
                -- set a name for each source
                vim_item.menu = ({
                    buffer   = "[BUF]",
                    nvim_lsp = "[LSP]",
                    luasnip  = "[LS]",
                    nvim_lua = "[Lua]"
                })[entry.source.name]
                return vim_item
            end
        },
    
    -- code
    -- ...
    
    }
    

    相关文章

      网友评论

          本文标题:NVIM COC + lspkind-nvim

          本文链接:https://www.haomeiwen.com/subject/jlldwltx.html