conditional lsp servers

This commit is contained in:
Noah Masur 2022-07-10 14:15:41 +00:00
parent cc801b4981
commit 4851637770
5 changed files with 90 additions and 46 deletions

View File

@ -26,17 +26,6 @@ find_downloads = function()
require("telescope").extensions.file_browser.file_browser(opts) require("telescope").extensions.file_browser.file_browser(opts)
end end
choose_project = function()
local opts = require("telescope.themes").get_ivy({
layout_config = {
bottom_pane = {
height = 10,
},
},
})
require("telescope").extensions.project.project(opts)
end
command_history = function() command_history = function()
local opts = require("telescope.themes").get_ivy({ local opts = require("telescope.themes").get_ivy({
layout_config = { layout_config = {

View File

@ -5,8 +5,7 @@
-- Function to cut down config boilerplate -- Function to cut down config boilerplate
local key = function(mode, key_sequence, action, params) local key = function(mode, key_sequence, action, params)
params = params or {} params = params or {}
params["noremap"] = true vim.keymap.set(mode, key_sequence, action, params)
vim.api.nvim_set_keymap(mode, key_sequence, action, params)
end end
-- Remap space as leader key -- Remap space as leader key
@ -34,9 +33,9 @@ key("n", "<Leader>k", ":Telescope keymaps<CR>")
key("n", "<Leader>/", ":Telescope live_grep<CR>") key("n", "<Leader>/", ":Telescope live_grep<CR>")
key("n", "<Leader>ff", ":Telescope find_files<CR>") key("n", "<Leader>ff", ":Telescope find_files<CR>")
key("n", "<Leader>fp", ":Telescope git_files<CR>") key("n", "<Leader>fp", ":Telescope git_files<CR>")
key("n", "<Leader>fN", "<Cmd>lua find_notes()<CR>") key("n", "<Leader>fN", find_notes)
key("n", "<Leader>N", "<Cmd>lua grep_notes()<CR>") key("n", "<Leader>N", grep_notes)
key("n", "<Leader>fD", "<Cmd>lua find_downloads()<CR>") key("n", "<Leader>fD", find_downloads)
key("n", "<Leader>fa", ":Telescope file_browser<CR>") key("n", "<Leader>fa", ":Telescope file_browser<CR>")
key("n", "<Leader>fw", ":Telescope grep_string<CR>") key("n", "<Leader>fw", ":Telescope grep_string<CR>")
key("n", "<Leader>wt", ":Telescope tmux sessions<CR>") key("n", "<Leader>wt", ":Telescope tmux sessions<CR>")
@ -48,14 +47,11 @@ key("n", "<Leader>hh", ":Telescope help_tags<CR>")
key("n", "<Leader>fr", ":Telescope oldfiles<CR>") key("n", "<Leader>fr", ":Telescope oldfiles<CR>")
key("n", "<Leader>cc", ":Telescope commands<CR>") key("n", "<Leader>cc", ":Telescope commands<CR>")
key("n", "<Leader>cr", "<Cmd>lua command_history()<CR>") key("n", "<Leader>cr", "<Cmd>lua command_history()<CR>")
key("n", "<Leader>y", "<Cmd>lua clipboard_history()<CR>")
key("i", "<c-y>", "<Cmd>lua clipboard_history()<CR>")
key("n", "<Leader>s", ":Telescope current_buffer_fuzzy_find<CR>") key("n", "<Leader>s", ":Telescope current_buffer_fuzzy_find<CR>")
key("n", "<Leader>gc", ":Telescope git_commits<CR>") key("n", "<Leader>gc", ":Telescope git_commits<CR>")
key("n", "<Leader>gf", ":Telescope git_bcommits<CR>") key("n", "<Leader>gf", ":Telescope git_bcommits<CR>")
key("n", "<Leader>gb", ":Telescope git_branches<CR>") key("n", "<Leader>gb", ":Telescope git_branches<CR>")
key("n", "<Leader>gs", ":Telescope git_status<CR>") key("n", "<Leader>gs", ":Telescope git_status<CR>")
key("n", "<C-p>", "<Cmd>lua choose_project()<CR>")
-- Buffer tabs (tmux interferes) -- Buffer tabs (tmux interferes)
-- key("n", "<C-L>", "gt") -- key("n", "<C-L>", "gt")
@ -64,10 +60,10 @@ key("n", "<C-p>", "<Cmd>lua choose_project()<CR>")
-- key("i", "<C-H>", "<Esc>gT") -- key("i", "<C-H>", "<Esc>gT")
-- LSP -- LSP
key("n", "gd", "<Cmd>lua vim.lsp.buf.definition()<CR>", { silent = true }) key("n", "gd", vim.lsp.buf.definition, { silent = true })
key("n", "gT", "<Cmd>lua vim.lsp.buf.type_definition()<CR>", { silent = true }) key("n", "gT", vim.lsp.buf.type_definition, { silent = true })
key("n", "gi", "<Cmd>lua vim.lsp.buf.implementation()<CR>", { silent = true }) key("n", "gi", vim.lsp.buf.implementation, { silent = true })
key("n", "gh", "<Cmd>lua vim.lsp.buf.hover()<CR>", { silent = true }) key("n", "gh", vim.lsp.buf.hover, { silent = true })
key("n", "gr", "<Cmd>Telescope lsp_references<CR>", { silent = true }) key("n", "gr", "<Cmd>Telescope lsp_references<CR>", { silent = true })
key("n", "<Leader>R", "<Cmd>lua vim.lsp.buf.rename()<CR>", { silent = true }) key("n", "<Leader>R", "<Cmd>lua vim.lsp.buf.rename()<CR>", { silent = true })
key("n", "]e", "<Cmd>lua vim.diagnostic.goto_next()<CR>", { silent = true }) key("n", "]e", "<Cmd>lua vim.diagnostic.goto_next()<CR>", { silent = true })

View File

@ -4,6 +4,10 @@
local M = {} local M = {}
function on_path(program)
return vim.fn.executable(program) == 1
end
M.packer = function(use) M.packer = function(use)
-- Language server engine -- Language server engine
use({ use({
@ -13,16 +17,24 @@ M.packer = function(use)
local capabilities = require("cmp_nvim_lsp").update_capabilities( local capabilities = require("cmp_nvim_lsp").update_capabilities(
vim.lsp.protocol.make_client_capabilities() vim.lsp.protocol.make_client_capabilities()
) )
require("lspconfig").rust_analyzer.setup({ capabilities = capabilities }) if on_path("rust-analyzer") then
require("lspconfig").tflint.setup({ capabilities = capabilities }) require("lspconfig").rust_analyzer.setup({ capabilities = capabilities })
require("lspconfig").terraformls.setup({ capabilities = capabilities }) end
require("lspconfig").pyright.setup({ if on_path("tflint") then
on_attach = function() require("lspconfig").tflint.setup({ capabilities = capabilities })
-- set keymaps (requires 0.7.0) end
-- vim.keymap.set("n", "", "", {buffer=0}) if on_path("terraform-ls") then
end, require("lspconfig").terraformls.setup({ capabilities = capabilities })
capabilities = capabilities, end
}) if on_path("pyright") then
require("lspconfig").pyright.setup({
on_attach = function()
-- set keymaps (requires 0.7.0)
-- vim.keymap.set("n", "", "", {buffer=0})
end,
capabilities = capabilities,
})
end
end, end,
}) })
@ -40,16 +52,47 @@ M.packer = function(use)
config = function() config = function()
require("null-ls").setup({ require("null-ls").setup({
sources = { sources = {
require("null-ls").builtins.formatting.stylua, require("null-ls").builtins.formatting.stylua.with({
require("null-ls").builtins.formatting.black, condition = function()
require("null-ls").builtins.formatting.fish_indent, return on_path("stylua")
require("null-ls").builtins.formatting.nixfmt, end,
require("null-ls").builtins.formatting.rustfmt, }),
require("null-ls").builtins.diagnostics.shellcheck, require("null-ls").builtins.formatting.black.with({
condition = function()
return on_path("black")
end,
}),
require("null-ls").builtins.formatting.fish_indent.with({
condition = function()
return on_path("fish_indent")
end,
}),
require("null-ls").builtins.formatting.nixfmt.with({
condition = function()
return on_path("nixfmt")
end,
}),
require("null-ls").builtins.formatting.rustfmt.with({
condition = function()
return on_path("rustfmt")
end,
}),
require("null-ls").builtins.diagnostics.shellcheck.with({
condition = function()
return on_path("shellcheck")
end,
}),
require("null-ls").builtins.formatting.shfmt.with({ require("null-ls").builtins.formatting.shfmt.with({
extra_args = { "-i", "4", "-ci" }, extra_args = { "-i", "4", "-ci" },
condition = function()
return on_path("shfmt")
end,
}),
require("null-ls").builtins.formatting.terraform_fmt.with({
condition = function()
return on_path("terraform")
end,
}), }),
require("null-ls").builtins.formatting.terraform_fmt,
-- require("null-ls").builtins.diagnostics.luacheck, -- require("null-ls").builtins.diagnostics.luacheck,
-- require("null-ls").builtins.diagnostics.markdownlint, -- require("null-ls").builtins.diagnostics.markdownlint,
-- require("null-ls").builtins.diagnostics.pylint, -- require("null-ls").builtins.diagnostics.pylint,
@ -57,12 +100,14 @@ M.packer = function(use)
-- Format on save -- Format on save
on_attach = function(client) on_attach = function(client)
if client.resolved_capabilities.document_formatting then if client.resolved_capabilities.document_formatting then
vim.cmd([[ local id = vim.api.nvim_create_augroup("LspFormatting", {
augroup LspFormatting clear = true,
autocmd! * <buffer> })
autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_seq_sync() vim.api.nvim_create_autocmd("BufWritePre", {
augroup END group = id,
]]) pattern = "*",
callback = vim.lsp.buf.formatting_seq_sync,
})
end end
end, end,
}) })

View File

@ -21,6 +21,7 @@ M.packer = function(use)
"yaml", "yaml",
"json", "json",
}, },
auto_install = true,
highlight = { enable = true }, highlight = { enable = true },
indent = { enable = true }, indent = { enable = true },
}) })

View File

@ -57,6 +57,19 @@ M.packer = function(use)
requires = { "nvim-telescope/telescope.nvim" }, requires = { "nvim-telescope/telescope.nvim" },
config = function() config = function()
require("telescope").load_extension("project") require("telescope").load_extension("project")
choose_project = function()
local opts = require("telescope.themes").get_ivy({
layout_config = {
bottom_pane = {
height = 10,
},
},
})
require("telescope").extensions.project.project(opts)
end
vim.keymap.set("n", "<C-p>", choose_project)
end, end,
}) })