Advertisement
Bubu-Droid

Untitled

May 24th, 2025
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.62 KB | None | 0 0
  1. return {
  2.   "neovim/nvim-lspconfig",
  3.   event = { "BufReadPre", "BufNewFile" },
  4.   dependencies = {
  5.     "hrsh7th/cmp-nvim-lsp",
  6.     "mason-lspconfig.nvim",
  7.     { "antosha417/nvim-lsp-file-operations", config = true },
  8.     { "folke/neodev.nvim", opts = {} },
  9.   },
  10.   config = function()
  11.     -- import lspconfig plugin
  12.     local lspconfig = require("lspconfig")
  13.  
  14.     -- import mason_lspconfig plugin
  15.     local mason_lspconfig = require("mason-lspconfig")
  16.  
  17.     -- import cmp-nvim-lsp plugin
  18.     local cmp_nvim_lsp = require("cmp_nvim_lsp")
  19.  
  20.     local keymap = vim.keymap -- for conciseness
  21.  
  22.     vim.api.nvim_create_autocmd("LspAttach", {
  23.       group = vim.api.nvim_create_augroup("UserLspConfig", {}),
  24.       callback = function(ev)
  25.         -- Buffer local mappings.
  26.         -- See `:help vim.lsp.*` for documentation on any of the below functions
  27.         local opts = { buffer = ev.buf, silent = true }
  28.  
  29.         -- set keybinds
  30.         -- we do not use debuggers :3
  31.         opts.desc = "See available code actions"
  32.         keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, opts) -- see available code actions, in visual mode will apply to selection
  33.  
  34.         opts.desc = "Smart rename"
  35.         keymap.set("n", "<leader>rn", vim.lsp.buf.rename, opts) -- smart rename
  36.  
  37.         opts.desc = "Show buffer diagnostics"
  38.         keymap.set("n", "<leader>D", "<cmd>Telescope diagnostics bufnr=0<CR>", opts) -- show  diagnostics for file
  39.  
  40.         opts.desc = "Show line diagnostics"
  41.         keymap.set("n", "<leader>d", vim.diagnostic.open_float, opts) -- show diagnostics for line
  42.  
  43.         opts.desc = "Show documentation for what is under cursor"
  44.         keymap.set("n", "K", vim.lsp.buf.hover, opts) -- show documentation for what is under cursor
  45.  
  46.         opts.desc = "Restart LSP"
  47.         keymap.set("n", "<leader>rs", ":LspRestart<CR>", opts) -- mapping to restart lsp if necessary
  48.       end,
  49.     })
  50.  
  51.     -- used to enable autocompletion (assign to every lsp server config)
  52.     local capabilities = cmp_nvim_lsp.default_capabilities()
  53.  
  54.     -- Change the Diagnostic symbols in the sign column (gutter)
  55.     -- (not in youtube nvim video)
  56.     local signs = {
  57.       Error = " ",
  58.       Warn = " ",
  59.       Hint = "󰠠 ",
  60.       Info = " ",
  61.     }
  62.     -- Convert severity names to diagnostic severities
  63.     local sign_text = {}
  64.     for type, icon in pairs(signs) do
  65.       local severity = vim.diagnostic.severity[string.upper(type)]
  66.       sign_text[severity] = icon
  67.     end
  68.  
  69.     vim.diagnostic.config({
  70.       signs = { text = sign_text },
  71.     })
  72.  
  73.     mason_lspconfig.setup({
  74.       handlers = {
  75.         -- default handler for installed servers
  76.         function(server_name)
  77.           lspconfig[server_name].setup({
  78.             capabilities = capabilities,
  79.           })
  80.         end,
  81.         ["emmet_ls"] = function()
  82.           -- configure emmet language server
  83.           lspconfig["emmet_ls"].setup({
  84.             capabilities = capabilities,
  85.             filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" },
  86.           })
  87.         end,
  88.         ["lua_ls"] = function()
  89.           -- configure lua server (with special settings)
  90.           lspconfig["lua_ls"].setup({
  91.             capabilities = capabilities,
  92.             settings = {
  93.               Lua = {
  94.                 -- make the language server recognize "vim" global
  95.                 diagnostics = {
  96.                   globals = { "vim" },
  97.                 },
  98.                 completion = {
  99.                   callSnippet = "Replace",
  100.                 },
  101.               },
  102.             },
  103.           })
  104.         end,
  105.         ["texlab"] = function()
  106.           lspconfig["texlab"].setup({
  107.             capabilities = capabilities,
  108.             filetypes = { "tex", "latex" },
  109.           })
  110.         end,
  111.         ["pyright"] = function()
  112.           lspconfig["pyright"].setup({
  113.             capabilities = capabilities,
  114.             filetypes = { "python" },
  115.           })
  116.         end,
  117.         ["html"] = function()
  118.           lspconfig["html"].setup({
  119.             capabilities = capabilities,
  120.             filetypes = { "html" },
  121.           })
  122.         end,
  123.         ["cssls"] = function()
  124.           lspconfig["cssls"].setup({
  125.             capabilities = capabilities,
  126.             filetypes = { "css" },
  127.           })
  128.         end,
  129.         ["tailwindcss"] = function()
  130.           lspconfig["tailwindcss"].setup({
  131.             capabilities = capabilities,
  132.             filetypes = { "html", "css", "javascript", "typescript", "javascriptreact", "typescriptreact" },
  133.           })
  134.         end,
  135.         ["marksman"] = function()
  136.           lspconfig["marksman"].setup({
  137.             capabilities = capabilities,
  138.             filetypes = { "markdown" },
  139.           })
  140.         end,
  141.         ["taplo"] = function()
  142.           lspconfig["taplo"].setup({
  143.             capabilities = capabilities,
  144.             filetypes = { "toml" },
  145.           })
  146.         end,
  147.         ["yamlls"] = function()
  148.           lspconfig["yamlls"].setup({
  149.             capabilities = capabilities,
  150.             filetypes = { "yaml" },
  151.             settings = {
  152.               yaml = {
  153.                 schemas = {
  154.                   kubernetes = "/*.yaml", -- Example schema for Kubernetes files
  155.                 },
  156.                 validate = true,
  157.                 completion = true,
  158.                 hover = true,
  159.               },
  160.             },
  161.           })
  162.         end,
  163.         ["bashls"] = function()
  164.           lspconfig["bashls"].setup({
  165.             capabilities = capabilities,
  166.             filetypes = { "sh" },
  167.           })
  168.         end,
  169.       },
  170.     })
  171.   end,
  172. }
  173.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement