summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/lsp/init.lua
diff options
context:
space:
mode:
Diffstat (limited to '.config/nvim/lua/lsp/init.lua')
-rw-r--r--.config/nvim/lua/lsp/init.lua124
1 files changed, 56 insertions, 68 deletions
diff --git a/.config/nvim/lua/lsp/init.lua b/.config/nvim/lua/lsp/init.lua
index f0f7b45..8eebe0a 100644
--- a/.config/nvim/lua/lsp/init.lua
+++ b/.config/nvim/lua/lsp/init.lua
@@ -1,15 +1,6 @@
local M = {}
local Log = require "core.log"
-
-function M.config()
- vim.lsp.protocol.CompletionItemKind = options.lsp.completion.item_kind
-
- for _, sign in ipairs(options.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()
-end
+local utils = require "utils"
local function lsp_highlight_document(client)
if options.lsp.document_highlight == false then
@@ -19,9 +10,6 @@ local function lsp_highlight_document(client)
if client.resolved_capabilities.document_highlight then
vim.api.nvim_exec(
[[
- hi LspReferenceRead cterm=bold ctermbg=red guibg=#353d46
- hi LspReferenceText cterm=bold ctermbg=red guibg=#353d46
- hi LspReferenceWrite cterm=bold ctermbg=red guibg=#353d46
augroup lsp_document_highlight
autocmd! * <buffer>
autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
@@ -65,35 +53,31 @@ function M.common_capabilities()
"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
+ local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
+ if status_ok then
+ capabilities = cmp_nvim_lsp.update_capabilities(capabilities)
end
- if not client_id then
- error "Unable to determine client_id"
- end
-
- client = vim.lsp.get_client_by_id(tonumber(client_id))
- local enabled_caps = {}
+ return capabilities
+end
- for k, v in pairs(client.resolved_capabilities) do
- if v == true then
- table.insert(enabled_caps, k)
+local function select_default_formater(client)
+ local client_formatting = client.resolved_capabilities.document_formatting
+ or client.resolved_capabilities.document_range_formatting
+ if client.name == "null-ls" or not client_formatting then
+ return
+ end
+ Log:debug("Checking for formatter overriding for " .. client.name)
+ local client_filetypes = client.config.filetypes or {}
+ for _, filetype in ipairs(client_filetypes) do
+ if not vim.tbl_isempty(lvim.lang[filetype].formatters) then
+ Log:debug("Formatter overriding detected. Disabling formatting capabilities for " .. client.name)
+ client.resolved_capabilities.document_formatting = false
+ client.resolved_capabilities.document_range_formatting = false
+ return
end
end
-
- return enabled_caps
end
function M.common_on_init(client, bufnr)
@@ -102,55 +86,59 @@ function M.common_on_init(client, bufnr)
Log:debug "Called lsp.on_init_callback"
return
end
-
- local formatters = options.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:debug(
- string.format("Overriding language server [%s] with format provider [%s]", client.name, formatters[1].exe)
- )
- end
+ select_default_formater(client)
end
function M.common_on_attach(client, bufnr)
if options.lsp.on_attach_callback then
options.lsp.on_attach_callback(client, bufnr)
- Log:debug "Called lsp.on_init_callback"
+ Log:debug "Called lsp.on_attach_callback"
end
lsp_highlight_document(client)
add_lsp_buffer_keybindings(bufnr)
- require("lsp.null-ls").setup(vim.bo.filetype)
end
-function M.setup(lang)
- local lsp_utils = require "lsp.utils"
- local lsp = options.lang[lang].lsp
- if (lsp.active ~= nil and not lsp.active) or lsp_utils.is_client_active(lsp.provider) then
+local function bootstrap_nlsp(opts)
+ opts = opts or {}
+ local lsp_settings_status_ok, lsp_settings = pcall(require, "nlspsettings")
+ if lsp_settings_status_ok then
+ lsp_settings.setup(opts)
+ end
+end
+
+function M.get_common_opts()
+ return {
+ on_attach = M.common_on_attach,
+ on_init = M.common_on_init,
+ capabilities = M.common_capabilities(),
+ }
+end
+
+function M.setup()
+ Log:debug "Setting up LSP support"
+
+ local lsp_status_ok, _ = pcall(require, "lspconfig")
+ if not lsp_status_ok then
return
end
- local overrides = options.lsp.override
- if type(overrides) == "table" then
- if vim.tbl_contains(overrides, lang) then
- return
- end
+ for _, sign in ipairs(options.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()
+
+ if not utils.is_directory(options.lsp.templates_dir) then
+ require("lsp.templates").generate_templates()
end
- if lsp.provider ~= nil and lsp.provider ~= "" then
- local lspconfig = require "lspconfig"
+ bootstrap_nlsp { config_home = utils.join_paths(get_config_dir(), "lsp-settings") }
- if not lsp.setup.on_attach then
- lsp.setup.on_attach = M.common_on_attach
- end
- if not lsp.setup.on_init then
- lsp.setup.on_init = M.common_on_init
- end
- if not lsp.setup.capabilities then
- lsp.setup.capabilities = M.common_capabilities()
- end
+ require("lsp.null-ls").setup()
- lspconfig[lsp.provider].setup(lsp.setup)
- end
+ require("utils").toggle_autoformat()
end
return M