Переглянути джерело

dev: automated commit - 2025-05-28 14:17:15

Mariano Z. 8 місяців тому
батько
коміт
a2d2fcb86e
9 змінених файлів з 68 додано та 92 видалено
  1. 0 0
      lsp/gopls.lua
  2. 0 0
      lsp/html.lua
  3. 0 0
      lsp/htmx.lua
  4. 0 0
      lsp/jsonls.lua
  5. 0 1
      lsp/lua_ls.lua
  6. 0 0
      lsp/omnisharp.lua
  7. 0 0
      lsp/vtsls.lua
  8. 0 0
      lsp/yamlls.lua
  9. 68 91
      lua/plugins/lsp/init.lua

+ 0 - 0
lua/config/lsp/gopls.lua → lsp/gopls.lua


+ 0 - 0
lua/config/lsp/html.lua → lsp/html.lua


+ 0 - 0
lua/config/lsp/htmx.lua → lsp/htmx.lua


+ 0 - 0
lua/config/lsp/jsonls.lua → lsp/jsonls.lua


+ 0 - 1
lua/config/lsp/lua_ls.lua → lsp/lua_ls.lua

@@ -1,4 +1,3 @@
--- With 2-space indentation
 return {
   settings = {
     Lua = {

+ 0 - 0
lua/config/lsp/omnisharp.lua → lsp/omnisharp.lua


+ 0 - 0
lua/config/lsp/vtsls.lua → lsp/vtsls.lua


+ 0 - 0
lua/config/lsp/yamlls.lua → lsp/yamlls.lua


+ 68 - 91
lua/plugins/lsp/init.lua

@@ -1,76 +1,60 @@
 local M = {
-  "neovim/nvim-lspconfig",
+  "mson-org/mason-lspconfig.nvim",
   dependencies = {
-    "saghen/blink.cmp",
-    "williamboman/mason.nvim",
-    "williamboman/mason-lspconfig.nvim",
+    "mson-org/mason.nvim",
     "WhoIsSethDaniel/mason-tool-installer.nvim",
-
-    { "j-hui/fidget.nvim", opts = {} },
+    "j-hui/fidget.nvim",
     "ibhagwan/fzf-lua",
-
     require("plugins.lsp.extras.lazydev"),
     require("plugins.lsp.extras.gopher"),
   },
 }
 
--- Key mappings for LSP
 local function setup_keymaps(bufnr)
-  local BORDER = "rounded"
+  local opts = { buffer = bufnr, noremap = true, silent = true }
   local keymaps = {
-    { "<C-h>", vim.lsp.buf.signature_help, "Signature Help", border = BORDER },
-    { "K", vim.lsp.buf.hover, "Hover Doc", border = BORDER },
-    { "<leader>cw", vim.lsp.buf.rename, "Rename" },
-    { "<leader>r", vim.lsp.buf.rename, "Rename" },
-    { "vd", vim.diagnostic.open_float, "Open Diagnostics" },
-    { "<leader>lr", ":LspRestart<CR>", "Restart LSP" },
-    { "<leader>li", ":LspInfo<CR>", "LSP Info" },
-    { "gd", require("fzf-lua").lsp_definitions, "Go to Definition" },
-    { "gr", require("fzf-lua").lsp_references, "Go to References" },
-    { "gD", vim.lsp.buf.declaration, "Go to Declaration" },
-    { "gi", require("fzf-lua").lsp_implementations, "Go to Implementation" },
-    { "gt", require("fzf-lua").lsp_typedefs, "Go to Type Definition" },
-    { "<leader>ca", vim.lsp.buf.code_action, "Code Action" },
-    { "<leader>dl", require("fzf-lua").diagnostics_document, "Document Diagnostics" },
-    { "<leader>dw", require("fzf-lua").diagnostics_workspace, "Workspace Diagnostics" },
-    { "<leader>ds", require("fzf-lua").lsp_document_symbols, "Document Symbols" },
-    { "<leader>ws", require("fzf-lua").lsp_workspace_symbols, "Workspace Symbols" },
+    { "K", vim.lsp.buf.hover, desc = "Hover Doc", border = "rounded" },
+    { "<C-h>", vim.lsp.buf.signature_help, desc = "Signature Help", border = "rounded" },
+    { "<leader>rn", vim.lsp.buf.rename, desc = "Rename" },
+    { "<leader>ca", vim.lsp.buf.code_action, desc = "Code Action" },
+    { "gd", require("fzf-lua").lsp_definitions, desc = "Go to Definition" },
+    { "gr", require("fzf-lua").lsp_references, desc = "Go to References" },
+    { "gD", vim.lsp.buf.declaration, desc = "Go to Declaration" },
+    { "gi", require("fzf-lua").lsp_implementations, desc = "Go to Implementation" },
+    { "gt", require("fzf-lua").lsp_typedefs, desc = "Go to Type Definition" },
+    { "<leader>vd", vim.diagnostic.open_float, desc = "View Diagnostics" },
+    { "<leader>dl", require("fzf-lua").diagnostics_document, desc = "Document Diagnostics" },
+    { "<leader>dw", require("fzf-lua").diagnostics_workspace, desc = "Workspace Diagnostics" },
+    { "<leader>ds", require("fzf-lua").lsp_document_symbols, desc = "Document Symbols" },
+    { "<leader>ws", require("fzf-lua").lsp_workspace_symbols, desc = "Workspace Symbols" },
+    { "<leader>lr", ":LspRestart<CR>", desc = "Restart LSP" },
+    { "<leader>li", ":LspInfo<CR>", desc = "LSP Info" },
   }
-
   for _, map in ipairs(keymaps) do
-    vim.keymap.set("n", map[1], function()
-      map[2](map[4] and { border = map[4] } or nil)
-    end, { buffer = bufnr, desc = map[3] })
+    nmap(map[1], map[2], vim.tbl_extend("force", opts, { desc = map[3], border = map[4] }))
   end
 end
 
 function M.config()
-  -- Mason setup
   require("mason").setup({ max_concurrent_installers = 4 })
+  require("fidget").setup({})
 
   -- Diagnostic configuration
   vim.diagnostic.config({
-    severity_sort = true,
+    virtual_text = { spacing = 2, source = "if_many" },
     float = { border = "rounded", source = "if_many" },
-    underline = { severity = vim.diagnostic.severity.ERROR },
+    severity_sort = true,
     signs = vim.g.have_nerd_font and {
       text = {
-        [vim.diagnostic.severity.ERROR] = "󰅚 ",
-        [vim.diagnostic.severity.WARN] = "󰀪 ",
-        [vim.diagnostic.severity.INFO] = "󰋽 ",
-        [vim.diagnostic.severity.HINT] = "󰌶 ",
+        [vim.diagnostic.severity.ERROR] = "󰅚",
+        [vim.diagnostic.severity.WARN] = "󰀪",
+        [vim.diagnostic.severity.INFO] = "󰋽",
+        [vim.diagnostic.severity.HINT] = "󰌶",
       },
     } or {},
-    virtual_text = {
-      source = "if_many",
-      spacing = 2,
-      format = function(diagnostic)
-        return diagnostic.message
-      end,
-    },
   })
 
-  -- Servers and tools
+  -- List of servers to enable (matching files in ~/.config/nvim/lsp/)
   local servers = {
     "gopls",
     "jsonls",
@@ -78,7 +62,6 @@ function M.config()
     "yamlls",
     "graphql",
     "html",
-    "jsonls",
     "omnisharp",
     "svelte",
     "vtsls",
@@ -86,11 +69,16 @@ function M.config()
     "templ",
   }
 
-  local ensure_installed = vim.tbl_filter(function(s)
-    return s ~= "ccls"
+  -- Servers not supported by mason-lspconfig
+  local mason_unsupported = { "ccls" }
+
+  -- Filter supported servers for mason-lspconfig
+  local mason_servers = vim.tbl_filter(function(server)
+    return not vim.tbl_contains(mason_unsupported, server)
   end, servers)
 
-  vim.list_extend(ensure_installed, {
+  -- Tools
+  local tools = {
     "prettierd",
     "shfmt",
     "stylua",
@@ -98,61 +86,50 @@ function M.config()
     "clang-format",
     "csharpier",
     "quick-lint-js",
+  }
+
+  -- Mason-LSPconfig setup for automatic installation
+  require("mason-lspconfig").setup({
+    ensure_installed = mason_servers,
+    automatic_installation = true,
+    automatic_enable = true,
   })
 
-  require("mason-tool-installer").setup({ ensure_installed = ensure_installed })
+  -- Mason tool installer for tools and ccls
+  require("mason-tool-installer").setup({ ensure_installed = tools })
 
-  -- Document highlight autocommands
-  local function setup_autocommands(client, bufnr)
-    if client.server_capabilities.documentHighlightProvider then
-      local group = vim.api.nvim_create_augroup("LSPDocumentHighlight", { clear = true })
-      vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, {
-        group = group,
-        buffer = bufnr,
-        callback = vim.lsp.buf.document_highlight,
-      })
-      vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, {
-        group = group,
-        buffer = bufnr,
-        callback = vim.lsp.buf.clear_references,
-      })
-    end
-  end
+  -- Enable LSP servers
+  vim.lsp.enable(servers)
 
-  -- LspAttach autocommand
+  -- LSP Attach
   vim.api.nvim_create_autocmd("LspAttach", {
-    group = vim.api.nvim_create_augroup("kickstart-lsp-attach", { clear = true }),
-    callback = function(event)
-      local client = vim.lsp.get_client_by_id(event.data.client_id)
-      local bufnr = event.buf
+    group = vim.api.nvim_create_augroup("UserLspConfig", { clear = true }),
+    callback = function(args)
+      local client = vim.lsp.get_client_by_id(args.data.client_id)
+      local bufnr = args.buf
+
       setup_keymaps(bufnr)
-      setup_autocommands(client, bufnr)
 
-      -- Inlay hints toggle
-      if client.supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint, { bufnr = bufnr }) then
+      -- Inlay hints
+      if client.supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint) then
         vim.keymap.set("n", "<leader>th", function()
           vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = bufnr }))
         end, { buffer = bufnr, desc = "Toggle Inlay Hints" })
       end
+
+      -- Document highlights
+      if client.server_capabilities.documentHighlightProvider then
+        vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, {
+          buffer = bufnr,
+          callback = vim.lsp.buf.document_highlight,
+        })
+        vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, {
+          buffer = bufnr,
+          callback = vim.lsp.buf.clear_references,
+        })
+      end
     end,
   })
-
-  -- Base LSP configuration
-  local base_config = {
-    capabilities = require("blink.cmp").get_lsp_capabilities(),
-    flags = { debounce_text_changes = 150 },
-  }
-
-  -- Setup LSP servers
-  require("mason-lspconfig").setup({ ensure_installed = {}, automatic_installation = true, automatic_enable = false })
-  for _, server in ipairs(servers) do
-    local config = vim.deepcopy(base_config)
-    local ok, server_opts = pcall(require, "config.lsp." .. server)
-    if ok then
-      config = vim.tbl_deep_extend("force", config, server_opts)
-    end
-    require("lspconfig")[server].setup(config)
-  end
 end
 
 return M