restructure init.lua | lspconfig

pull/630/head
siduck 3 years ago
parent a256591e90
commit 8de3f4e84c

@ -1,5 +1,21 @@
local ok, err = pcall(require, "core")
local userconf = pcall(require, "custom")
if not ok then
error("Error loading core" .. "\n\n" .. err)
if userconf then
require "custom"
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()

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

@ -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()

@ -258,13 +258,13 @@ M.merge_table = function(into, from, nodes_to_replace)
-- function that will be executed with loadstring
local replace_fn = function(node)
local base_fn = [[
return function(table1, table2)
local t1, t2 = table1_node or false , table2_node or false
if t1 and t2 then
table1_node = table2_node
end
return table1
end]]
return function(table1, table2)
local t1, t2 = table1_node or false , table2_node or false
if t1 and t2 then
table1_node = table2_node
end
return table1
end]]
-- replace the _node in base_fn to actual given node value
local fn = base_fn:gsub("_node", node)
@ -374,9 +374,9 @@ M.override_req = function(name, default_req)
result = result:sub(2)
result = result:gsub("%)%.", "').", 1)
return "require('" .. result
else
return "require('" .. result .. "')"
end
return "require('" .. result .. "')"
end
return M

@ -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
local addlsp_confs = require("core.utils").load_config().plugins.options.lspconfig.setup_lspconf
if #addlsp_confs ~= 0 then
require(addlsp_confs).setup_lsp(on_attach, capabilities)
end
require("plugins.configs.others").lsp_handlers()

@ -107,4 +107,43 @@ M.signature = function()
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

Loading…
Cancel
Save