VonHeikemen / lsp-zero.nvim

A starting point to setup some lsp related features in neovim.
https://lsp-zero.netlify.app/docs/
MIT License
3.84k stars 99 forks source link

Hi @VonHeikemen, came here after an year coz it was unmaintained, i grew up a lot in this time period, help me get back to `lsp-zero` #384

Closed daUnknownCoder closed 3 months ago

daUnknownCoder commented 7 months ago

Hi @VonHeikemen, I really liked this thing but around an year before, this plugin was unmaintained like a few months since the latest commit... so i migrated away from lsp-zero, how can i get back to this? I know every1 grew up with @theprimeagen's 0 to LSP but that was old too so i had to configure everything from scratch so how can i get back, i'll provide my config here:

lspconfig.lua

return {
  {
    "neovim/nvim-lspconfig",
    event = { "BufEnter", "BufNewFile" },
    lazy = true,
    dependencies = {
      {
        "hrsh7th/cmp-nvim-lsp",
        event = { "LspAttach" },
        lazy = true,
      },
      {
        "antosha417/nvim-lsp-file-operations",
        event = { "LspAttach" },
        lazy = true,
        config = true,
      },
      {
        "ray-x/lsp_signature.nvim",
        lazy = true,
        event = "InsertEnter",
      },
      {
        "zeioth/garbage-day.nvim",
        dependencies = "neovim/nvim-lspconfig",
        event = "VeryLazy",
        opts = {
          notifications = true,
        },
      },
      { "chrisgrieser/nvim-dr-lsp", lazy = true, event = "LspAttach" },
      {
        "soulis-1256/eagle.nvim",
        event = "VeryLazy",
        lazy = false,
        config = function()
          require("eagle").setup({
            border = "rounded",
          })
        end,
      },
      { "folke/neodev.nvim", lazy = true, event = "BufReadPost" },
    },
    config = function()
      local neodev_status_ok, neodev = pcall(require, "neodev")
      if not neodev_status_ok then
        print("neodev not found!")
      end
      neodev.setup({
        library = { plugins = { "nvim-dap-ui", "nvim-dap-virtual-text" }, types = true },
      })
      local lspconfig_status_ok, lspconfig = pcall(require, "lspconfig")
      if not lspconfig_status_ok then
        print("lspconfig not found!")
      end
      local cmp_nvim_lsp_status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
      if not cmp_nvim_lsp_status_ok then
        print("cmp_nvim_lsp not found!")
      end
      local icons_ok, icons = pcall(require, "NeutronVim.core.icons")
      if not icons_ok then
        print("Unable to import icons!")
      end
      local keymap = vim.keymap.set
      -- luacheck: ignore 212
      local on_attach = function(client, bufnr)
        if client then
          keymap(
            "n",
            "\\f",
            "<cmd>Lspsaga finder ref+def+imp+tyd<CR>",
            { noremap = true, silent = true, desc = "LSP Finder [Ref, Def, Imp, Tyd] " }
          )
          keymap(
            "n",
            "[d",
            "<cmd>lua vim.diagnostic.goto_prev()<CR>",
            { noremap = true, silent = true, desc = "Diagnostic Jump Prev" }
          )
          keymap(
            "n",
            "]d",
            "<cmd>lua vim.diagnostic.goto_next()<CR>",
            { noremap = true, silent = true, desc = "Diagnostic Jump Next" }
          )
          require("lsp_signature").on_attach({
            bind = true,
            debug = true,
            floating_window = true,
            floating_window_above_cur_line = true,
            hint_enable = true,
            fix_pos = false,
            -- floating_window_above_first = true,
            log_path = vim.fn.expand("$HOME") .. "/tmp/sig.log",
            padding = " ",
            handler_opts = {
              border = "rounded",
            },
          }, bufnr)
        end
      end
      local capabilities = cmp_nvim_lsp.default_capabilities()
      local signs = {
        Error = icons.diagnostics.Error,
        Warn = icons.diagnostics.Warning,
        Hint = icons.diagnostics.Hint,
        Info = icons.diagnostics.Info,
      }
      for type, icon in pairs(signs) do
        local hl = "DiagnosticSign" .. type
        vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
      end
      vim.diagnostic.config({
        virtual_text = false,
        virtual_lines = true,
        signs = { text = { "", "", "", "" } }, -- {"", "", ""}
        float = {
          show_header = true,
          border = "rounded",
          suffix = "",
          focusable = false,
          enabled = true,
          source = "always",
          header = { "  Diagnostics", "String" },
          prefix = function(_, _, _)
            return "  ", "String"
          end, -- icons:       
        },
        update_in_insert = false,
        underline = true,
        severity_sort = true,
      })
      lspconfig["rust_analyzer"].setup({
        capabilities = capabilities,
        on_attach = on_attach,
        cmd = {
          "rustup",
          "run",
          "stable",
          "rust-analyzer",
        },
      })
      lspconfig["html"].setup({
        capabilities = capabilities,
        on_attach = on_attach,
      })
      lspconfig["tsserver"].setup({
        capabilities = capabilities,
        on_attach = on_attach,
      })
      lspconfig["clangd"].setup({
        capabilities = capabilities,
        on_attach = on_attach,
      })
      lspconfig["eslint"].setup({
        capabilities = capabilities,
        on_attach = on_attach,
      })
      lspconfig["cmake"].setup({
        capabilities = capabilities,
        on_attach = on_attach,
      })
      lspconfig["bashls"].setup({
        capabilities = capabilities,
        on_attach = on_attach,
      })
      lspconfig["pyright"].setup({
        capabilities = capabilities,
        on_attach = on_attach,
      })
      lspconfig["cssls"].setup({
        capabilities = capabilities,
        on_attach = on_attach,
      })
      lspconfig["marksman"].setup({
        capabilities = capabilities,
        on_attach = on_attach,
      })
      lspconfig["lua_ls"].setup({
        capabilities = capabilities,
        on_attach = on_attach,
        settings = {
          Lua = {
            runtime = { version = "LuaJIT", path = vim.split(package.path, ";") },
            completion = { keywordSnippet = "Disable", callSnippet = "Replace" },
            diagnostics = {
              globals = { "vim", "describe", "it", "before_each", "after_each" },
            },
            workspace = {
              library = {
                [vim.fn.expand("$VIMRUNTIME/lua")] = true,
                [vim.fn.expand("$VIMRUNTIME/lua/vim/lsp")] = true,
                [vim.fn.stdpath("config") .. "/lua"] = true,
              },
            },
          },
        },
      })
    end,
  },
}

cmp.lua

return {
  {
    "L3MON4D3/LuaSnip",
    dependencies = {
      {
        "rafamadriz/friendly-snippets",
        lazy = true,
        event = "InsertCharPre",
      },
    },
    opts = {
      history = true,
      enable_autosnippets = true,
      updateevents = "TextChanged,TextChangedI",
      delete_check_events = "TextChanged",
      region_check_events = "CursorMoved",
    },
    config = function(_, opts)
      local luasnip_status_ok, luasnip = pcall(require, "luasnip")
      if not luasnip_status_ok then
        print("Luasnip not found!")
      end
      if opts then
        luasnip.config.setup(opts)
      end
      vim.tbl_map(function(type)
        require("luasnip.loaders.from_" .. type).lazy_load()
      end, { "vscode", "snipmate", "lua" })
      require("luasnip.loaders.from_lua").lazy_load({
        paths = { "lua/NeutronVim/snippets/" },
      })
    end,
    lazy = true,
    event = { "InsertEnter", "CmdlineEnter" },
  },
  {
    "hrsh7th/nvim-cmp",
    dependencies = {
      { "saadparwaiz1/cmp_luasnip", lazy = true },
      { "hrsh7th/cmp-buffer", lazy = true },
      { "FelipeLema/cmp-async-path", lazy = true },
      { "hrsh7th/cmp-cmdline", lazy = true },
      { "dmitmel/cmp-cmdline-history", lazy = true },
      { "petertriho/cmp-git", lazy = true },
      { "hrsh7th/cmp-emoji", lazy = true },
      { "hrsh7th/cmp-calc", lazy = true },
      { "ray-x/cmp-treesitter", lazy = true },
      { "hrsh7th/cmp-nvim-lsp-signature-help", lazy = true },
      { "rcarriga/cmp-dap", lazy = true },
      { "hrsh7th/cmp-nvim-lua", lazy = true },
      { "lukas-reineke/cmp-rg", lazy = true },
      {
        "Exafunction/codeium.vim",
        lazy = true,
        event = "BufEnter",
      },
      lazy = true,
    },
    event = { "InsertEnter", "CmdlineEnter" },
    config = function()
      local cmp_status_ok, cmp = pcall(require, "cmp")
      if not cmp_status_ok then
        print("CMP not found!")
      end
      local snip_status_ok, luasnip = pcall(require, "luasnip")
      if not snip_status_ok then
        print("Luasnip not found!")
      end
      local git_status_ok, cmp_git = pcall(require, "cmp_git")
      if not git_status_ok then
        print("cmp_git not found!")
      end
      cmp_git.setup()
      local icons_ok, icons = pcall(require, "NeutronVim.core.icons")
      if not icons_ok then
        print("Unable to import icons!")
      end
      vim.g.codeium_disable_bindings = 1
      vim.keymap.set("i", "<C-a>", function()
        return vim.fn["codeium#Accept"]()
      end, { expr = true, silent = true })
      vim.keymap.set("i", "<c-,>", function()
        return vim.fn["codeium#CycleCompletions"](1)
      end, { expr = true, silent = true })
      vim.keymap.set("i", "<c-;>", function()
        return vim.fn["codeium#CycleCompletions"](-1)
      end, { expr = true, silent = true })
      local kind_icons = icons.kind
      local feedkey = function(key, mode)
        vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
      end
      local function has_words_before()
        local line, col = (unpack or table.unpack)(vim.api.nvim_win_get_cursor(0))
        return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
      end
      local check_back_space = function()
        local col = vim.fn.col(".") - 1
        if col == 0 or vim.fn.getline("."):sub(col, col):match("%s") then
          return true
        else
          return false
        end
      end
      vim.api.nvim_set_hl(0, "NeutronCmpNormal", { fg = "silver", bg = "NONE" })
      vim.api.nvim_set_hl(0, "NeutronCmpBorder", { fg = "lightblue", bg = "NONE" })
      vim.api.nvim_set_hl(0, "CmpItemAbbr", { fg = "silver", bg = "NONE" })
      vim.api.nvim_set_hl(0, "CmpItemAbbrMatch", { fg = "lime", bg = "NONE" })
      vim.api.nvim_set_hl(0, "CmpItemAbbrMatchFuzzy", { fg = "#ff3e00", bg = "NONE" })
      vim.api.nvim_set_hl(0, "CmpItemKindVariable", { bg = "NONE", fg = "salmon" })
      vim.api.nvim_set_hl(0, "CmpItemKindFunction", { bg = "NONE", fg = "deepskyblue" })
      vim.api.nvim_set_hl(0, "CmpItemKindSnippet", { fg = "pink", bg = "NONE" })
      vim.api.nvim_set_hl(0, "CmpItemKindText", { fg = "yellow", bg = "NONE" })
      vim.api.nvim_set_hl(0, "CmpItemKindFile", { fg = "lightgreen", bg = "NONE" })
      vim.api.nvim_set_hl(0, "CmpItemKindKeyword", { bg = "NONE", fg = "orange" })
      vim.api.nvim_set_hl(0, "CmpItemKindProperty", { link = "CmpItemKindKeyword" })
      vim.api.nvim_set_hl(0, "CmpItemKindUnit", { link = "CmpItemKindKeyword" })
      vim.api.nvim_set_hl(0, "CmpItemKindFolder", { fg = "#D4A959", bg = "NONE" })
      vim.api.nvim_set_hl(0, "CmpItemAbbrDeprecated", { bg = "NONE", strikethrough = true, fg = "#808080" })
      local border_opts = {
        border = "rounded",
        winhighlight = "Normal:NeutronCmpNormal,FloatBorder:NeutronCmpBorder,CursorLine:PmenuSel,Search:CmpItemAbbrMatchFuzzy",
      }
      ---@diagnostic disable-next-line: missing-fields, redundant-parameter
      cmp.setup({
        preselect = cmp.PreselectMode.None,
        ---@diagnostic disable-next-line: missing-fields
        formatting = {
          fields = { "kind", "abbr", "menu" },
          format = function(entry, item)
            item.kind = string.format("%s %s", kind_icons[item.kind], item.kind .. " " or "🚀 ")
            item.menu = "➥ "
              .. (
                ({
                  nvim_lsp = "「LSP」",
                  gh_issues = "「Issues」",
                  nvim_lua = "「API」",
                  buffer = "「Buffer」",
                  luasnip = "「Snip」",
                  treesitter = "「Treesitter」",
                  calc = "「Calc」",
                  emoji = "「Emoji」",
                  rg = "「rg」",
                  dap = "「DAP」",
                  async_path = "「Path」",
                  nvim_lsp_signature_help = "「Signature」",
                  cmdline = "「Cmd」",
                  cmdline_history = "「History」",
                })[entry.source.name] or "🚀 "
              )
            return item
          end,
        },
        snippet = {
          expand = function(args)
            luasnip.lsp_expand(args.body)
          end,
        },
        duplicates = {
          nvim_lsp = 1,
          luasnip = 1,
          cmp_tabnine = 1,
          buffer = 1,
          path = 1,
        },
        confirm_opts = {
          behavior = cmp.ConfirmBehavior.Replace,
          select = false,
        },
        window = {
          completion = cmp.config.window.bordered(border_opts),
          documentation = cmp.config.window.bordered(border_opts),
        },
        ---@diagnostic disable-next-line: missing-fields
        matching = {
          disallow_fuzzy_matching = false,
          disallow_fullfuzzy_matching = false,
          disallow_partial_fuzzy_matching = false,
          disallow_partial_matching = false,
        },
        mapping = {
          ["<Up>"] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }),
          ["<Down>"] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }),
          ["<C-b>"] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }),
          ["<C-f>"] = cmp.mapping(cmp.mapping.scroll_docs(4), { "i", "c" }),
          ["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }),
          ["<C-e>"] = cmp.mapping({ i = cmp.mapping.abort(), c = cmp.mapping.close() }),
          ["<CR>"] = cmp.mapping.confirm({ select = false }),
          ["<Tab>"] = cmp.mapping(function(_)
            if cmp.visible() then
              cmp.select_next_item()
            elseif luasnip.expand_or_jumpable() then
              luasnip.expand_or_jump()
            elseif check_back_space() then
              feedkey("  ", "i")
            elseif has_words_before() then
              cmp.complete()
            else
              feedkey("  ", "i")
            end
          end, { "i", "s" }),
          ["<S-Tab>"] = cmp.mapping(function(_)
            if cmp.visible() then
              cmp.select_prev_item()
            elseif luasnip.jumpable(-1) then
              luasnip.jump(-1)
            elseif check_back_space() then
              feedkey("  ", "i")
            else
              feedkey("  ", "i")
            end
          end, { "i", "s" }),
        },
        sources = cmp.config.sources({
          { name = "calc", priority_weight = 10 },
          {
            name = "nvim_lsp",
            max_item_count = 20,
            priority_weight = 1000,
          },
          { name = "luasnip", priority_weight = 750 },
          { name = "treesitter", priority_weight = 750 },
          { name = "nvim_lsp_signature_help", priority_weight = 500 },
          { name = "dap", priority_weight = 110 },
          { name = "git", priority_weight = 110 },
          {
            name = "rg",
            keyword_length = 5,
            max_item_count = 5,
            priority_weight = 60,
            option = {
              additional_arguments = "--smart-case --hidden",
            },
            entry_filter = function(entry)
              return not entry.exact
            end,
          },
          {
            name = "buffer",
            max_item_count = 5,
            priority_weight = 50,
            entry_filter = function(entry)
              return not entry.exact
            end,
          },
          { name = "nvim_lua", priority_weight = 500 },
          { name = "codeium", priority_weight = 500 },
          { name = "async_path", priority_weight = 250 },
          { name = "emoji", priority_weight = 200 },
        }),
      })
      ---@diagnostic disable-next-line: missing-fields, undefined-field
      cmp.setup.filetype("gitcommit", {
        sources = cmp.config.sources({
          { name = "git" },
          { name = "buffer" },
        }),
      })
      ---@diagnostic disable-next-line: missing-fields, undefined-field
      cmp.setup.cmdline({ "/", "?" }, {
        mapping = cmp.mapping.preset.cmdline(),
        sources = {
          { name = "buffer" },
          { name = "cmdline_history" },
        },
      })
      ---@diagnostic disable-next-line: missing-fields, undefined-field
      cmp.setup.cmdline(":", {
        mapping = cmp.mapping.preset.cmdline(),
        sources = cmp.config.sources({
          { name = "async_path" },
          { name = "cmdline" },
          { name = "cmdline_history" },
          { name = "buffer" },
        }),
        enabled = function()
          local disabled = {
            IncRename = true,
          }
          local cmd = vim.fn.getcmdline():match("%S+")
          return not disabled[cmd] or cmp.close()
        end,
      })
    end,
  },
}

mason.lua

return {
  "williamboman/mason.nvim",
  event = { "BufReadPre", "BufNewFile" },
  lazy = true,
  dependencies = {
    { "williamboman/mason-lspconfig.nvim", cmd = { "LspInstall", "LspUninstall" } },
    { "WhoIsSethDaniel/mason-tool-installer.nvim" },
  },
  config = function()
    local icons_ok, icons = pcall(require, "NeutronVim.core.icons")
    if not icons_ok then
      print("Unable to import icons!")
    end
    local mason_status_ok, mason = pcall(require, "mason")
    if not mason_status_ok then
      print("mason not found!")
    end
    local mason_lspconfig_status_ok, mason_lspconfig = pcall(require, "mason-lspconfig")
    if not mason_lspconfig_status_ok then
      print("mason-lspconfig not found!")
    end
    local mason_tool_installer_status_ok, mason_tool_installer = pcall(require, "mason-tool-installer")
    if not mason_tool_installer_status_ok then
      print("mason-tool-installer not found!")
    end
    mason.setup({
      ui = {
        icons = {
          package_installed = icons.ui.Check,
          package_uninstalled = icons.ui.Uncheck,
          package_pending = icons.ui.Electric,
        },
        border = "rounded",
      },
    })
    mason_lspconfig.setup({
      ensure_installed = {
        "tsserver",
        "html",
        "cssls",
        "lua_ls",
        "pyright",
        "marksman",
        "eslint",
        "clangd",
        "cmake",
        "bashls",
      },
      automatic_installation = true,
    })
    mason_tool_installer.setup({
      ensure_installed = {
        "prettierd",
        "eslint_d",
        "stylua",
        "black",
        "isort",
        "pylint",
        "luacheck",
        "ruff",
        "rustfmt",
        "clang-format",
        "cmakelang",
        "codespell",
        "shfmt",
      },
      auto_update = true,
      run_on_start = true,
      start_delay = 5000,
    })
  end,
}

and many more lsp plugins...

Thanks...

VonHeikemen commented 7 months ago

Is there a specific feature of lsp-zero that you want to use?

AmadeusK525 commented 7 months ago

Oh boy 😛

daUnknownCoder commented 7 months ago

Is there a specific feature of lsp-zero that you want to use?

Umm so maybe better LSP server thing? Like it's difficult to setup the native lspconfig thing, like it's integration with cmp-nvim-lsp and things is tough I still haven't figured out how to setup pyright like the you tubers watched many of em' but I don't get what I see... And better on_attach server mappings would also be good for me...