mirror of
https://github.com/ViViDboarder/vim-settings.git
synced 2024-12-23 04:47:36 +00:00
Add a try_require utility rather than checking packer
This commit is contained in:
parent
e11ba17d15
commit
1c9990750b
@ -30,8 +30,8 @@ function M.config_lsp_ui()
|
|||||||
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
|
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
|
||||||
end
|
end
|
||||||
|
|
||||||
if utils.is_plugin_loaded("trouble") then
|
utils.try_require("trouble", function(trouble)
|
||||||
require("trouble").setup({
|
trouble.setup({
|
||||||
fold_open = "▼",
|
fold_open = "▼",
|
||||||
fold_closed = "▶",
|
fold_closed = "▶",
|
||||||
signs = {
|
signs = {
|
||||||
@ -42,7 +42,7 @@ function M.config_lsp_ui()
|
|||||||
other = "",
|
other = "",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
end
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function default_attach(client, bufnr)
|
local function default_attach(client, bufnr)
|
||||||
@ -108,10 +108,7 @@ local function default_attach(client, bufnr)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Some override some fuzzy finder bindings to use lsp sources
|
-- Some override some fuzzy finder bindings to use lsp sources
|
||||||
if packer_plugins["nvim-lspfuzzy"] then
|
if utils.try_require("telescope.nvim") ~= nil then
|
||||||
buf_set_keymap("n", "<leader>t", "<cmd>lua vim.lsp.buf.document_symbol()<CR>", opts)
|
|
||||||
-- buf_set_keymap("n", "<leader>ft", "<cmd>lua vim.lsp.buf.workspace_symbol()<CR>", opts)
|
|
||||||
elseif packer_plugins["telescope.nvim"] then
|
|
||||||
buf_set_keymap("n", "<leader>t", "<cmd>Telescope lsp_document_symbols<CR>", opts)
|
buf_set_keymap("n", "<leader>t", "<cmd>Telescope lsp_document_symbols<CR>", opts)
|
||||||
buf_set_keymap("n", "<leader>ft", "<cmd>Telescope lsp_dynamic_workspace_symbols<CR>", opts)
|
buf_set_keymap("n", "<leader>ft", "<cmd>Telescope lsp_dynamic_workspace_symbols<CR>", opts)
|
||||||
end
|
end
|
||||||
@ -153,14 +150,13 @@ function M.config_lsp()
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if utils.is_plugin_loaded("null-ls.nvim") then
|
utils.try_require("null-ls", function()
|
||||||
M.config_null_ls()
|
|
||||||
lsp_config["null-ls"].setup({ capabilities = capabilities, on_attach = default_attach })
|
lsp_config["null-ls"].setup({ capabilities = capabilities, on_attach = default_attach })
|
||||||
end
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.config_lsp_saga()
|
function M.config_lsp_saga()
|
||||||
local saga = require("lspsaga")
|
utils.try_require("lspsaga", function(saga)
|
||||||
saga.init_lsp_saga({
|
saga.init_lsp_saga({
|
||||||
error_sign = "🔥",
|
error_sign = "🔥",
|
||||||
warn_sign = "⚠️",
|
warn_sign = "⚠️",
|
||||||
@ -172,10 +168,11 @@ function M.config_lsp_saga()
|
|||||||
sign = false,
|
sign = false,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.config_null_ls()
|
function M.config_null_ls()
|
||||||
local null_ls = require("null-ls")
|
utils.try_require("null-ls", function(null_ls)
|
||||||
null_ls.setup({
|
null_ls.setup({
|
||||||
sources = {
|
sources = {
|
||||||
-- Generic
|
-- Generic
|
||||||
@ -203,6 +200,6 @@ function M.config_null_ls()
|
|||||||
null_ls.builtins.formatting.stylua,
|
null_ls.builtins.formatting.stylua,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
@ -98,4 +98,23 @@ function M.is_plugin_loaded(name)
|
|||||||
return _G["packer_plugins"] and packer_plugins[name] and packer_plugins[name].loaded
|
return _G["packer_plugins"] and packer_plugins[name] and packer_plugins[name].loaded
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Try to require something and perform some action if it was found
|
||||||
|
function M.try_require(name, on_found, on_notfound)
|
||||||
|
local status, module = pcall(require, name)
|
||||||
|
if status then
|
||||||
|
if on_found ~= nil then
|
||||||
|
on_found(module)
|
||||||
|
end
|
||||||
|
|
||||||
|
return module
|
||||||
|
else
|
||||||
|
if on_notfound ~= nil then
|
||||||
|
on_notfound(name)
|
||||||
|
end
|
||||||
|
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
Loading…
Reference in New Issue
Block a user