Baishun's Space

My Nvim Configuration - LSP

By Baishun on May 14, 2024
nvim power

let’s continue our configuration.

Install LSP

LSP stands for language server protocol, which is started by microsoft, so we can do code auto-complete and check errors when write our code.

I use Mason and Mason-lspconfig + Nvim-lspconfig to do this.

/mason is auto installed within when you clone the configurations of lazy./

so create a file in plugins fold, maybe call it lsp-config.

talk is cheap, let me show you the code:

return {
  {
    "williamboman/mason.nvim",
    config = function()
      require("mason").setup({})
    end,
  },
  {
    "williamboman/mason-lspconfig.nvim",
    config = function()
      require("mason-lspconfig").setup({
        ensure_installed = { "lua_ls", "tsserver", "jsonls", "vale_ls", "tailwindcss" },
      })
    end,
  },
  {
    "neovim/nvim-lspconfig",
    config = function(_, opts)
      local lspconfig = require("lspconfig")
      lspconfig.dartls.setup({
        cmd = { "dart", "language-server", "--protocol=lsp" },
      })
      lspconfig.tsserver.setup({})
      lspconfig.lua_ls.setup({})
      lspconfig.tailwindcss.setup({})
      lspconfig.prismals.setup({})
      lspconfig.vale_ls.setup({}) -- for markdown
      lspconfig.jsonls.setup({})

      vim.keymap.set('n', 'K', vim.lsp.buf.hover, {})
      vim.keymap.set('n', 'gd', vim.lsp.buf.definition, {})
      vim.keymap.set('n', '<leader>ca', vim.lsp.buf.code_action, {})
      vim.keymap.set('n', '<leader>ce', vim.diagnostic.open_float, {})
    end
  },
}

the code mainly does the things below:

  1. set up mason
  2. set ensure_installed lsp use mason-lspconfig
  3. config lsp with nvim-lspconfig
  4. set some shortcut for lsp

I will continue in the next article

For business cooperation or you have any questions, please send email to : lecy.cc.app@gmail.com
© Copyright 2024 by Baishun Space. Built with ♥ by Lecy. Origin theme of this blog is from ixartz. Social Icons are copied from astro-social-share