diff options
author | Squibid <me@zacharyscheiman.com> | 2025-01-24 13:56:11 -0600 |
---|---|---|
committer | Squibid <me@zacharyscheiman.com> | 2025-01-24 13:56:11 -0600 |
commit | 8eaa615596be321a3be12378c5e7d65cc7e482b6 (patch) | |
tree | 53fe601048ea302962420de4feff465e4c7d9317 /lua/core/lsp | |
parent | a0ebc39b59a98a69fbb6abf150f86dc4e19987a3 (diff) | |
download | nvim-master.tar.gz nvim-master.tar.bz2 nvim-master.zip |
Diffstat (limited to 'lua/core/lsp')
-rw-r--r-- | lua/core/lsp/functions.lua | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/lua/core/lsp/functions.lua b/lua/core/lsp/functions.lua new file mode 100644 index 0000000..ab47ccc --- /dev/null +++ b/lua/core/lsp/functions.lua @@ -0,0 +1,90 @@ +local misc = require('core.misc') +local map = misc.map + +local M = {} + +function M.setup() + vim.diagnostic.config { + virtual_text = false, + virtual_lines = { + only_current_line = true, + }, + signs = true, + update_in_insert = false, + underline = true, + severity_sort = true + } + + vim.lsp.handlers['textDocument/hover'] = vim.lsp.with( + vim.lsp.handlers.hover, { border = 'solid' }) + + vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with( + vim.lsp.handlers.signature_help, { border = 'solid' }) + + for _, v in pairs({ + { "DiagnosticSignError", "x" }, + { "DiagnosticSignWarn", "!" }, + { "DiagnosticSignInfo", "i" }, + { "DiagnosticSignHint", "h" } + }) do + vim.fn.sign_define(v[1], { text = v[2], texthl = v[1] }) + end +end + +--- generate client capabilities for lsp servers +---@return table capabilities +function M.capabilities() + local capabilities = vim.lsp.protocol.make_client_capabilities() + capabilities.textDocument.completion.completionItem = { + snippetSupport = true, + preselectSupport = true, + insertReplaceSupport = true, + labelDetailsSupport = true, + deprecatedSupport = true, + commitCharactersSupport = true, + tagSupport = { + valueSet = { 1 } + }, + resolveSupport = { + properties = { + "documentation", + "detail", + "additionalTextEdits" + } + } + } + + return capabilities +end + +--- setup basic options on lsp attach +---@param client number client number +---@param bufnr number buffer number +function M.attach(client, bufnr) + local opts = { buffer = bufnr } + -- LSP actions + map('n', 'K', vim.lsp.buf.hover, opts) + map('n', 'gd', vim.lsp.buf.definition, opts) + map('n', 'gD', vim.lsp.buf.declaration) + map('n', 'gi', vim.lsp.buf.implementation, opts) + map('n', 'gy', vim.lsp.buf.type_definition, opts) + map('n', 'gr', vim.lsp.buf.references, opts) + map('n', '<S-Tab>', vim.lsp.buf.signature_help, opts) + map('n', '<leader>r', vim.lsp.buf.rename, opts) + map('n', '<F2>', vim.lsp.buf.rename, opts) + map('n', 'gA', vim.lsp.buf.code_action, { + buffer = bufnr, + desc = 'check code actions', + }) + map('n', '<F4>', vim.lsp.buf.code_action, { + buffer = bufnr, + desc = 'check code actions' + }) + + -- Diagnostics + map('n', '[d', vim.diagnostic.goto_prev, opts) + map('n', ']d', vim.diagnostic.goto_next, opts) + -- map('n', 'qD', vim.diagnostic.setqflist, opts) +end + +return M |