mirror of
https://github.com/nmasur/dotfiles
synced 2024-11-22 19:15:37 +00:00
conditional lsp servers
This commit is contained in:
parent
cc801b4981
commit
4851637770
@ -26,17 +26,6 @@ find_downloads = function()
|
||||
require("telescope").extensions.file_browser.file_browser(opts)
|
||||
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()
|
||||
local opts = require("telescope.themes").get_ivy({
|
||||
layout_config = {
|
||||
|
@ -5,8 +5,7 @@
|
||||
-- Function to cut down config boilerplate
|
||||
local key = function(mode, key_sequence, action, params)
|
||||
params = params or {}
|
||||
params["noremap"] = true
|
||||
vim.api.nvim_set_keymap(mode, key_sequence, action, params)
|
||||
vim.keymap.set(mode, key_sequence, action, params)
|
||||
end
|
||||
|
||||
-- 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>ff", ":Telescope find_files<CR>")
|
||||
key("n", "<Leader>fp", ":Telescope git_files<CR>")
|
||||
key("n", "<Leader>fN", "<Cmd>lua find_notes()<CR>")
|
||||
key("n", "<Leader>N", "<Cmd>lua grep_notes()<CR>")
|
||||
key("n", "<Leader>fD", "<Cmd>lua find_downloads()<CR>")
|
||||
key("n", "<Leader>fN", find_notes)
|
||||
key("n", "<Leader>N", grep_notes)
|
||||
key("n", "<Leader>fD", find_downloads)
|
||||
key("n", "<Leader>fa", ":Telescope file_browser<CR>")
|
||||
key("n", "<Leader>fw", ":Telescope grep_string<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>cc", ":Telescope commands<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>gc", ":Telescope git_commits<CR>")
|
||||
key("n", "<Leader>gf", ":Telescope git_bcommits<CR>")
|
||||
key("n", "<Leader>gb", ":Telescope git_branches<CR>")
|
||||
key("n", "<Leader>gs", ":Telescope git_status<CR>")
|
||||
key("n", "<C-p>", "<Cmd>lua choose_project()<CR>")
|
||||
|
||||
-- Buffer tabs (tmux interferes)
|
||||
-- key("n", "<C-L>", "gt")
|
||||
@ -64,10 +60,10 @@ key("n", "<C-p>", "<Cmd>lua choose_project()<CR>")
|
||||
-- key("i", "<C-H>", "<Esc>gT")
|
||||
|
||||
-- LSP
|
||||
key("n", "gd", "<Cmd>lua vim.lsp.buf.definition()<CR>", { silent = true })
|
||||
key("n", "gT", "<Cmd>lua vim.lsp.buf.type_definition()<CR>", { silent = true })
|
||||
key("n", "gi", "<Cmd>lua vim.lsp.buf.implementation()<CR>", { silent = true })
|
||||
key("n", "gh", "<Cmd>lua vim.lsp.buf.hover()<CR>", { silent = true })
|
||||
key("n", "gd", vim.lsp.buf.definition, { silent = true })
|
||||
key("n", "gT", vim.lsp.buf.type_definition, { silent = true })
|
||||
key("n", "gi", vim.lsp.buf.implementation, { silent = true })
|
||||
key("n", "gh", vim.lsp.buf.hover, { 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", "]e", "<Cmd>lua vim.diagnostic.goto_next()<CR>", { silent = true })
|
||||
|
@ -4,6 +4,10 @@
|
||||
|
||||
local M = {}
|
||||
|
||||
function on_path(program)
|
||||
return vim.fn.executable(program) == 1
|
||||
end
|
||||
|
||||
M.packer = function(use)
|
||||
-- Language server engine
|
||||
use({
|
||||
@ -13,16 +17,24 @@ M.packer = function(use)
|
||||
local capabilities = require("cmp_nvim_lsp").update_capabilities(
|
||||
vim.lsp.protocol.make_client_capabilities()
|
||||
)
|
||||
require("lspconfig").rust_analyzer.setup({ capabilities = capabilities })
|
||||
require("lspconfig").tflint.setup({ capabilities = capabilities })
|
||||
require("lspconfig").terraformls.setup({ capabilities = capabilities })
|
||||
require("lspconfig").pyright.setup({
|
||||
on_attach = function()
|
||||
-- set keymaps (requires 0.7.0)
|
||||
-- vim.keymap.set("n", "", "", {buffer=0})
|
||||
end,
|
||||
capabilities = capabilities,
|
||||
})
|
||||
if on_path("rust-analyzer") then
|
||||
require("lspconfig").rust_analyzer.setup({ capabilities = capabilities })
|
||||
end
|
||||
if on_path("tflint") then
|
||||
require("lspconfig").tflint.setup({ capabilities = capabilities })
|
||||
end
|
||||
if on_path("terraform-ls") then
|
||||
require("lspconfig").terraformls.setup({ 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,
|
||||
})
|
||||
|
||||
@ -40,16 +52,47 @@ M.packer = function(use)
|
||||
config = function()
|
||||
require("null-ls").setup({
|
||||
sources = {
|
||||
require("null-ls").builtins.formatting.stylua,
|
||||
require("null-ls").builtins.formatting.black,
|
||||
require("null-ls").builtins.formatting.fish_indent,
|
||||
require("null-ls").builtins.formatting.nixfmt,
|
||||
require("null-ls").builtins.formatting.rustfmt,
|
||||
require("null-ls").builtins.diagnostics.shellcheck,
|
||||
require("null-ls").builtins.formatting.stylua.with({
|
||||
condition = function()
|
||||
return on_path("stylua")
|
||||
end,
|
||||
}),
|
||||
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({
|
||||
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.markdownlint,
|
||||
-- require("null-ls").builtins.diagnostics.pylint,
|
||||
@ -57,12 +100,14 @@ M.packer = function(use)
|
||||
-- Format on save
|
||||
on_attach = function(client)
|
||||
if client.resolved_capabilities.document_formatting then
|
||||
vim.cmd([[
|
||||
augroup LspFormatting
|
||||
autocmd! * <buffer>
|
||||
autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_seq_sync()
|
||||
augroup END
|
||||
]])
|
||||
local id = vim.api.nvim_create_augroup("LspFormatting", {
|
||||
clear = true,
|
||||
})
|
||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
group = id,
|
||||
pattern = "*",
|
||||
callback = vim.lsp.buf.formatting_seq_sync,
|
||||
})
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
@ -21,6 +21,7 @@ M.packer = function(use)
|
||||
"yaml",
|
||||
"json",
|
||||
},
|
||||
auto_install = true,
|
||||
highlight = { enable = true },
|
||||
indent = { enable = true },
|
||||
})
|
||||
|
@ -57,6 +57,19 @@ M.packer = function(use)
|
||||
requires = { "nvim-telescope/telescope.nvim" },
|
||||
config = function()
|
||||
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,
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user