Giter Club home page Giter Club logo

Comments (2)

VonHeikemen avatar VonHeikemen commented on September 24, 2024 1

Change the name of your sources. Like this.

  sources = {
    {name = 'nvim_lsp'},
    {name = 'path'},
    {name = 'buffer'},
    {name = 'luasnip'},
  },

You need to make sure you have all these plugins installed:

And add the luasnip loader in your config.

require('luasnip.loaders.from_vscode').lazy_load()

from lsp-zero.nvim.

alitokur avatar alitokur commented on September 24, 2024 1

The plugin is working perfectly now, and I'm back to coding smoothly.
Thanks again for your fantastic work!

I'm attaching my configuration files related to the lsp-zero plugin. I hope they can be useful for other users facing similar issues.

packer.lua:

     use {
        'VonHeikemen/lsp-zero.nvim',
        branch = 'v2.x',
        requires = {
            -- LSP Support
            {'neovim/nvim-lspconfig'},             -- Required
            {                                      -- Optional
            'williamboman/mason.nvim',
            run = function()
                pcall(vim.api.nvim_command, 'MasonUpdate')
            end,
        },
        {'williamboman/mason-lspconfig.nvim'}, -- Optional

        -- Autocompletion
        {'hrsh7th/nvim-cmp'},     -- Required
        {'hrsh7th/cmp-nvim-lsp'}, -- Required
        {'L3MON4D3/LuaSnip'},     -- Required
        {"rafamadriz/friendly-snippets"},
        {"saadparwaiz1/cmp_luasnip"},
        {"hrsh7th/cmp-buffer"},

        --lspkind
        {"onsails/lspkind-nvim"},
    }
}

lsp.lua

local lsp = require('lsp-zero').preset({"recommended"})

-- Fix Undefined global 'vim'
lsp.configure('lua_ls', {
    settings = {
        Lua = {
            diagnostics = {
                globals = { 'vim' }
            }
        }
    }
})

lsp.on_attach(function(client, bufnr)
    -- see :help lsp-zero-keybindings
    -- to learn the available actions
    lsp.default_keymaps({buffer = bufnr})

    -- Neovim LSP Pickers
    -- https://github.com/nvim-telescope/telescope.nvim#neovim-lsp-pickers
    vim.keymap.set('n', 'gr', '<cmd>Telescope lsp_references<cr>', {buffer = true})
    vim.keymap.set('n', 'gs', '<cmd>Telescope lsp_document_symbols<cr>', {buffer = true})
    vim.keymap.set('n', 'gD', '<cmd>Telescope lsp_implementations<cr>', {buffer = true})
    vim.keymap.set('n', 'gd', '<cmd>Telescope lsp_definitions<cr>', {buffer = true})
end)

-- list: https://github.com/williamboman/mason-lspconfig.nvim
lsp.ensure_installed({
    "clangd",
    "lua_ls",
    "marksman",
    "pyre",
    "rust_analyzer",
    "cmake",
    "bashls",
    "lemminx",
    "ltex",
    "jsonls",
    "docker_compose_language_service",
})

lsp.set_sign_icons({
    error = '✘',
    warn = '▲',
    hint = '⚑',
    info = ''
})

--formatter
--cf is using 2 space as a tab :(
-- FIXME: modify clang formatter
-- lsp.format_on_save({
--     format_opts = {
--         async = false,
--         timeout_ms = 10000,
--     },
--     servers = {
--         ['clangd'] = {'cpp'},
--     }
-- })

-- keybinding

lsp.setup()

-- ####### CMP ######## --
local cmp = require('cmp')
local cmp_action = require('lsp-zero').cmp_action()
cmp.setup({
    -- sources
    select_behavior = 'insert',
    sources = {
        {name = 'nvim_lsp'},
        {name = 'path'},
        {name = 'buffer'},
        {name = 'luasnip'},
    },
    -- key-mapping
    mapping = {
        ["<Tab>"] = cmp_action.luasnip_supertab(),
        ["<S-Tab>"] = cmp_action.luasnip_shift_supertab(),
        -- `Enter` key to confirm completion
        ['<CR>'] = cmp.mapping.confirm({select = false}),
        -- Ctrl+Space to trigger completion menu
        ['<C-Space>'] = cmp.mapping.complete(),
        -- Navigate between snippet placeholder
        ['<C-f>'] = cmp_action.luasnip_jump_forward(),
        ['<C-b>'] = cmp_action.luasnip_jump_backward(),
        ['<C-e>'] = cmp.mapping.abort(),
        ['<C-u>'] = cmp.mapping.scroll_docs(-4),
        ['<C-d>'] = cmp.mapping.scroll_docs(4),
    },
    --snippets
  snippet = {
    expand = function(args)
      require('luasnip').lsp_expand(args.body)
    end,
  },
  --windows
  window = {
      completion = cmp.config.window.bordered(),
      documentation = cmp.config.window.bordered(),
  },
  --formating
  formatting = {
      fields = {'abbr', 'kind', 'menu'},
      format = require('lspkind').cmp_format({
          mode = 'symbol_text', -- show only symbol annotations
          maxwidth = 50, -- prevent the popup from showing more than provided characters
          ellipsis_char = '...', -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead
      })
  },
})

require('luasnip.loaders.from_vscode').lazy_load()



from lsp-zero.nvim.

Related Issues (20)

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.