restructure init.lua | lspconfig

This commit is contained in:
siduck 2021-11-14 06:49:33 +05:30
parent a256591e90
commit 8de3f4e84c
6 changed files with 69 additions and 72 deletions

View file

@ -1,5 +1,21 @@
local ok, err = pcall(require, "core") local userconf = pcall(require, "custom")
if not ok then if userconf then
error("Error loading core" .. "\n\n" .. err) require "custom"
end end
local core_modules = {
"core.options",
"core.autocmds",
"core.mappings",
}
for _, module in ipairs(core_modules) do
local ok, err = pcall(require, module)
if not ok then
error("Error loading " .. module .. "\n\n" .. err)
end
end
-- non plugin mappings
require("core.mappings").misc()

View file

@ -1,5 +0,0 @@
local moduleExists = pcall(require, "custom")
if moduleExists then
require "custom"
end

View file

@ -1,16 +0,0 @@
local core_modules = {
"core.custom",
"core.options",
"core.autocmds",
"core.mappings",
}
for _, module in ipairs(core_modules) do
local ok, err = pcall(require, module)
if not ok then
error("Error loading " .. module .. "\n\n" .. err)
end
end
-- set all the non plugin mappings
require("core.mappings").misc()

View file

@ -374,9 +374,9 @@ M.override_req = function(name, default_req)
result = result:sub(2) result = result:sub(2)
result = result:gsub("%)%.", "').", 1) result = result:gsub("%)%.", "').", 1)
return "require('" .. result return "require('" .. result
else
return "require('" .. result .. "')"
end end
return "require('" .. result .. "')"
end end
return M return M

View file

@ -50,48 +50,11 @@ capabilities.textDocument.completion.completionItem.resolveSupport = {
}, },
} }
-- replace the default lsp diagnostic symbols
local function lspSymbol(name, icon)
vim.fn.sign_define("LspDiagnosticsSign" .. name, { text = icon, numhl = "LspDiagnosticsDefault" .. name })
end
lspSymbol("Error", "")
lspSymbol("Information", "")
lspSymbol("Hint", "")
lspSymbol("Warning", "")
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
virtual_text = {
prefix = "",
spacing = 0,
},
signs = true,
underline = true,
update_in_insert = false, -- update diagnostics insert mode
})
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, {
border = "single",
})
vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, {
border = "single",
})
-- suppress error messages from lang servers
vim.notify = function(msg, log_level, _opts)
if msg:match "exit code" then
return
end
if log_level == vim.log.levels.ERROR then
vim.api.nvim_err_writeln(msg)
else
vim.api.nvim_echo({ { msg } }, true, {})
end
end
-- requires a file containing user's lspconfigs -- requires a file containing user's lspconfigs
local addlsp_confs = require("core.utils").load_config().plugins.options.lspconfig.setup_lspconf local addlsp_confs = require("core.utils").load_config().plugins.options.lspconfig.setup_lspconf
if #addlsp_confs ~= 0 then if #addlsp_confs ~= 0 then
require(addlsp_confs).setup_lsp(on_attach, capabilities) require(addlsp_confs).setup_lsp(on_attach, capabilities)
end end
require("plugins.configs.others").lsp_handlers()

View file

@ -107,4 +107,43 @@ M.signature = function()
end end
end end
M.lsp_handlers = function()
local function lspSymbol(name, icon)
vim.fn.sign_define("LspDiagnosticsSign" .. name, { text = icon, numhl = "LspDiagnosticsDefault" .. name })
end
lspSymbol("Error", "")
lspSymbol("Information", "")
lspSymbol("Hint", "")
lspSymbol("Warning", "")
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
virtual_text = {
prefix = "",
spacing = 0,
},
signs = true,
underline = true,
update_in_insert = false, -- update diagnostics insert mode
})
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, {
border = "single",
})
vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, {
border = "single",
})
-- suppress error messages from lang servers
vim.notify = function(msg, log_level, _opts)
if msg:match "exit code" then
return
end
if log_level == vim.log.levels.ERROR then
vim.api.nvim_err_writeln(msg)
else
vim.api.nvim_echo({ { msg } }, true, {})
end
end
end
return M return M