summaryrefslogtreecommitdiffstats
path: root/lua/core/lsp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lua/core/lsp/functions.lua90
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