mirror of
https://github.com/ViViDboarder/vim-settings.git
synced 2024-12-22 23:47:34 +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,56 +150,56 @@ 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 = "⚠️",
|
||||||
hint_sign = "🤔",
|
hint_sign = "🤔",
|
||||||
dianostic_header_icon = " 💬 ",
|
dianostic_header_icon = " 💬 ",
|
||||||
code_action_icon = "💡",
|
code_action_icon = "💡",
|
||||||
code_action_prompt = {
|
code_action_prompt = {
|
||||||
enable = false,
|
enable = false,
|
||||||
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
|
||||||
-- null_ls.builtins.formatting.preittier,
|
-- null_ls.builtins.formatting.preittier,
|
||||||
-- null_ls.builtins.formatting.trim_whitespace,
|
-- null_ls.builtins.formatting.trim_whitespace,
|
||||||
-- null_ls.builtins.formatting.trim_newlines,
|
-- null_ls.builtins.formatting.trim_newlines,
|
||||||
-- Fish
|
-- Fish
|
||||||
-- null_ls.builtins.formatting.fish_indent,
|
-- null_ls.builtins.formatting.fish_indent,
|
||||||
-- Python
|
-- Python
|
||||||
null_ls.builtins.formatting.reorder_python_imports,
|
null_ls.builtins.formatting.reorder_python_imports,
|
||||||
null_ls.builtins.formatting.black,
|
null_ls.builtins.formatting.black,
|
||||||
null_ls.builtins.diagnostics.mypy,
|
null_ls.builtins.diagnostics.mypy,
|
||||||
-- Go
|
-- Go
|
||||||
null_ls.builtins.diagnostics.golangci_lint,
|
null_ls.builtins.diagnostics.golangci_lint,
|
||||||
-- Text
|
-- Text
|
||||||
-- null_ls.builtins.code_actions.proselint,
|
-- null_ls.builtins.code_actions.proselint,
|
||||||
-- Ansible
|
-- Ansible
|
||||||
-- null_ls.builtins.diagnostics.ansiblelint,
|
-- null_ls.builtins.diagnostics.ansiblelint,
|
||||||
-- Shell
|
-- Shell
|
||||||
null_ls.builtins.diagnostics.shellcheck,
|
null_ls.builtins.diagnostics.shellcheck,
|
||||||
-- Rust
|
-- Rust
|
||||||
-- null_ls.builtins.formatting.rustfmt,
|
-- null_ls.builtins.formatting.rustfmt,
|
||||||
-- Lua
|
-- Lua
|
||||||
null_ls.builtins.diagnostics.luacheck,
|
null_ls.builtins.diagnostics.luacheck,
|
||||||
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