summaryrefslogtreecommitdiff
path: root/lua/lsp/init.lua
diff options
context:
space:
mode:
authorchristianchiarulli <[email protected]>2021-08-11 16:33:41 -0400
committerchristianchiarulli <[email protected]>2021-08-11 16:33:41 -0400
commit83013c0d4f1467f546c38719c61909decfcb8151 (patch)
tree143773ea73c64d953db699e6e621926e44653fc2 /lua/lsp/init.lua
parentf6407e0bdb9c2875bc8f186929ce183af391b2a9 (diff)
parent5a7630cac761e91335d2f25cb07a81271569c791 (diff)
Merge branch 'rolling' of github.com:ChristianChiarulli/LunarVim
Diffstat (limited to 'lua/lsp/init.lua')
-rw-r--r--lua/lsp/init.lua160
1 files changed, 125 insertions, 35 deletions
diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua
index 62c42fd8..e4ea02db 100644
--- a/lua/lsp/init.lua
+++ b/lua/lsp/init.lua
@@ -1,59 +1,149 @@
-local utils = require "utils"
-local service = require "lsp.service"
-local null_ls = require "lsp.null-ls"
local M = {}
-
+local Log = require "core.log"
function M.config()
- require("lsp.kind").setup()
+ vim.lsp.protocol.CompletionItemKind = lvim.lsp.completion.item_kind
+
+ for _, sign in ipairs(lvim.lsp.diagnostics.signs.values) do
+ vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = sign.name })
+ end
+
require("lsp.handlers").setup()
- require("lsp.signs").setup()
- require("lsp.keybinds").setup()
end
-function M.setup(lang)
- local lang_server = lvim.lang[lang].lsp
- local provider = lang_server.provider
- if utils.check_lsp_client_active(provider) then
- return
+local function lsp_highlight_document(client)
+ if lvim.lsp.document_highlight == false then
+ return -- we don't need further
+ end
+ -- Set autocommands conditional on server_capabilities
+ if client.resolved_capabilities.document_highlight then
+ vim.api.nvim_exec(
+ [[
+ hi LspReferenceRead cterm=bold ctermbg=red guibg=#464646
+ hi LspReferenceText cterm=bold ctermbg=red guibg=#464646
+ hi LspReferenceWrite cterm=bold ctermbg=red guibg=#464646
+ augroup lsp_document_highlight
+ autocmd! * <buffer>
+ autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
+ autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
+ augroup END
+ ]],
+ false
+ )
end
+end
- local overrides = lvim.lsp.override
+local function add_lsp_buffer_keybindings(bufnr)
+ local wk = require "which-key"
+ local keys = {
+ ["K"] = { "<cmd>lua vim.lsp.buf.hover()<CR>", "Show hover" },
+ ["gd"] = { "<cmd>lua vim.lsp.buf.definition()<CR>", "Goto Definition" },
+ ["gD"] = { "<cmd>lua vim.lsp.buf.declaration()<CR>", "Goto declaration" },
+ ["gr"] = { "<cmd>lua vim.lsp.buf.references()<CR>", "Goto references" },
+ ["gi"] = { "<cmd>lua vim.lsp.buf.implementation()<CR>", "Goto implementation" },
+ ["gs"] = { "<cmd>lua vim.lsp.buf.signature_help()<CR>", "show signature help" },
+ ["gp"] = { "<cmd>lua require'lsp.peek'.Peek('definition')<CR>", "Peek definition" },
+ ["gl"] = {
+ "<cmd>lua vim.lsp.diagnostic.show_line_diagnostics({ show_header = false, border = 'single' })<CR>",
+ "Show line diagnostics",
+ },
+ }
+ wk.register(keys, { mode = "n", buffer = bufnr })
+end
- if utils.is_table(overrides) then
- if utils.has_value(overrides, lang) then
- return
- end
+local function set_smart_cwd(client)
+ local proj_dir = client.config.root_dir
+ if lvim.lsp.smart_cwd and proj_dir ~= "/" then
+ vim.api.nvim_set_current_dir(proj_dir)
+ require("core.nvimtree").change_tree_dir(proj_dir)
end
+end
- if utils.is_string(overrides) then
- if overrides == lang then
- return
+function M.common_capabilities()
+ local capabilities = vim.lsp.protocol.make_client_capabilities()
+ capabilities.textDocument.completion.completionItem.snippetSupport = true
+ capabilities.textDocument.completion.completionItem.resolveSupport = {
+ properties = {
+ "documentation",
+ "detail",
+ "additionalTextEdits",
+ },
+ }
+ return capabilities
+end
+
+function M.get_ls_capabilities(client_id)
+ local client
+ if not client_id then
+ local buf_clients = vim.lsp.buf_get_clients()
+ for _, buf_client in ipairs(buf_clients) do
+ if buf_client.name ~= "null-ls" then
+ client_id = buf_client.id
+ break
+ end
end
end
- local sources = null_ls.setup(lang)
+ if not client_id then
+ error "Unable to determine client_id"
+ end
- for _, source in pairs(sources) do
- local method = source.method
- local format_method = "NULL_LS_FORMATTING"
+ client = vim.lsp.get_client_by_id(tonumber(client_id))
- if utils.is_table(method) then
- if utils.has_value(method, format_method) then
- lang_server.setup.on_attach = service.no_formatter_on_attach
- end
- end
+ local enabled_caps = {}
- if utils.is_string(method) then
- if method == format_method then
- lang_server.setup.on_attach = service.no_formatter_on_attach
- end
+ for k, v in pairs(client.resolved_capabilities) do
+ if v == true then
+ table.insert(enabled_caps, k)
end
end
- if provider == "" or provider == nil then
+ return enabled_caps
+end
+
+function M.common_on_init(client, bufnr)
+ if lvim.lsp.on_init_callback then
+ lvim.lsp.on_init_callback(client, bufnr)
+ Log:get_default().info "Called lsp.on_init_callback"
+ return
+ end
+
+ local formatters = lvim.lang[vim.bo.filetype].formatters
+ if not vim.tbl_isempty(formatters) and formatters[1]["exe"] ~= nil and formatters[1].exe ~= "" then
+ client.resolved_capabilities.document_formatting = false
+ Log:get_default().info(
+ string.format("Overriding language server [%s] with format provider [%s]", client.name, formatters[1].exe)
+ )
+ end
+end
+
+function M.common_on_attach(client, bufnr)
+ if lvim.lsp.on_attach_callback then
+ lvim.lsp.on_attach_callback(client, bufnr)
+ Log:get_default().info "Called lsp.on_init_callback"
+ end
+ lsp_highlight_document(client)
+ add_lsp_buffer_keybindings(bufnr)
+ set_smart_cwd(client)
+ require("lsp.null-ls").setup(vim.bo.filetype)
+end
+
+function M.setup(lang)
+ local lsp = lvim.lang[lang].lsp
+ if require("utils").check_lsp_client_active(lsp.provider) then
return
end
- require("lspconfig")[provider].setup(lang_server.setup)
+ local overrides = lvim.lsp.override
+
+ if type(overrides) == "table" then
+ if vim.tbl_contains(overrides, lang) then
+ return
+ end
+ end
+
+ if lsp.provider ~= nil and lsp.provider ~= "" then
+ local lspconfig = require "lspconfig"
+ lspconfig[lsp.provider].setup(lsp.setup)
+ end
end
return M