Add lsplib which shouldve been in last commit

This commit is contained in:
Martin Larsson 2025-05-30 13:57:37 +02:00
parent 9fb6438efa
commit 872e7bec51

44
nvim/lua/lsplib.lua Normal file
View file

@ -0,0 +1,44 @@
local inlay_hints_handler = require("inlay_hints_handler")
local format_handler = require("format_handler")
local utils = require("utils")
local lsp = vim.lsp.buf
local api = vim.api
local M = {}
function M.configure_generic_client(client, bufnr)
inlay_hints_handler.add_buffer(bufnr)
if client.server_capabilities.documentFormattingProvider then
api.nvim_buf_create_user_command(bufnr, "Format", lsp.format, { nargs = 0 })
api.nvim_create_autocmd("BufWritePre", {
buffer = bufnr,
callback = function()
format_handler.format()
end,
})
end
-- Built-in LSP completion.
-- Could switch to this if they just appeared automatically when typing, and didn't
-- only rely on showing when the servers completionCharacters are typed.
-- if client:supports_method("textDocument/completion") then
-- vim.lsp.completion.enable(true, client.id, bufnr, { autotrigger = true })
-- end
for mode, keys in pairs({
n = {
{ "K", function() lsp.hover() end, { buffer = bufnr } },
{ "<leader>r", function() lsp.rename() end, { buffer = bufnr } },
{ "<leader>a", function() lsp.code_action() end, { buffer = bufnr } },
},
i = {
{ "<C-s>", function() lsp.signature_help() end, { buffer = bufnr } },
},
}) do
utils.set_keymap_list(keys, mode)
end
end
return M