summaryrefslogtreecommitdiffstats
path: root/lua/core/lsp/functions.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/core/lsp/functions.lua')
-rw-r--r--lua/core/lsp/functions.lua157
1 files changed, 91 insertions, 66 deletions
diff --git a/lua/core/lsp/functions.lua b/lua/core/lsp/functions.lua
index ab47ccc..4c27bca 100644
--- a/lua/core/lsp/functions.lua
+++ b/lua/core/lsp/functions.lua
@@ -1,90 +1,115 @@
local misc = require('core.misc')
-local map = misc.map
+local map, include = misc.map, misc.include
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] })
+local function on_list(options)
+ vim.fn.setqflist({}, 'r', options)
+ if #options.items > 1 then
+ vim.cmd.copen()
end
+ vim.cmd("cc! 1")
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
+local function _w(func)
+ return function()
+ func({
+ border = "solid",
+ max_width = math.floor(vim.o.columns * 0.7),
+ }, { on_list = on_list })
+ end
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 }
+local function attach(bufnr)
+ local opts = { buffer = bufnr, nowait = true }
+
-- 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, {
+ map('n', 'K', _w(vim.lsp.buf.hover), opts)
+ map('n', 'gd', _w(vim.lsp.buf.definition), opts)
+ map('n', 'gD', _w(vim.lsp.buf.declaration), opts)
+ map('n', 'gi', _w(vim.lsp.buf.implementation), opts)
+ map('n', 'gy', _w(vim.lsp.buf.type_definition), opts)
+ map('n', 'gr', _w(vim.lsp.buf.references), opts)
+ map('n', '<S-Tab>', _w(vim.lsp.buf.signature_help), opts)
+ map('n', { '<leader>r', '<F2>' }, _w(vim.lsp.buf.rename), opts)
+ map('n', 'gA', _w(vim.lsp.buf.code_action), {
buffer = bufnr,
desc = 'check code actions',
})
- map('n', '<F4>', vim.lsp.buf.code_action, {
+ map('n', '<F4>', _w(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', '[d', function()
+ if not vim.fn.has("nvim-0.11") then
+ vim.diagnostic.goto_prev()
+ else
+ vim.diagnostic.jump({ count = -1 })
+ end
+ end, opts)
+ map('n', ']d', function()
+ if not vim.fn.has("nvim-0.11") then
+ vim.diagnostic.goto_next()
+ else
+ vim.diagnostic.jump({ count = 1 })
+ end
+ end, opts)
-- map('n', 'qD', vim.diagnostic.setqflist, opts)
end
+function M.setup()
+ vim.diagnostic.config {
+ virtual_text = false,
+ virtual_lines = {
+ only_current_line = true,
+ },
+ update_in_insert = false,
+ underline = true,
+ severity_sort = true,
+ signs = {
+ text = {
+ [vim.diagnostic.severity.ERROR] = "x",
+ [vim.diagnostic.severity.WARN] = "!",
+ [vim.diagnostic.severity.INFO] = "i",
+ [vim.diagnostic.severity.HINT] = "h",
+ }
+ }
+ }
+
+ if not vim.fn.has("nvim-0.11") then
+ 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' })
+ end
+
+ -- set default capabilities
+ include('lspconfig.util').default_config.capabilities = M.capabilities
+
+ -- run whenever a client attaches
+ vim.api.nvim_create_autocmd('LspAttach', {
+ callback = function(event)
+ -- map keybinds
+ attach(event.buf)
+ end
+ })
+end
+
+--- capabilities that are to be used in lsp servers, for those setup through
+--- lspconfig, this is already set as the default. Incase there is a server
+--- not setup through lspconfig this function may be called to receive the
+--- proper capabilities data.
+M.capabilities = vim.lsp.protocol.make_client_capabilities()
+
+--- add capabilities to the default capabilities string
+---@param new_capabilities lsp.ClientCapabilities
+function M.add_capabilities(new_capabilities)
+ vim.tbl_deep_extend('force', M.capabilities, new_capabilities)
+end
+
return M