mirror of
https://github.com/dcarrillo/dotfiles.git
synced 2025-07-02 02:49:26 +00:00
Add neovim dotfiles
This commit is contained in:
91
.config/nvim/lua/user/lsp/handlers.lua
Normal file
91
.config/nvim/lua/user/lsp/handlers.lua
Normal file
@ -0,0 +1,91 @@
|
||||
local M = {}
|
||||
|
||||
local status_cmp_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
|
||||
if not status_cmp_ok then
|
||||
return
|
||||
end
|
||||
|
||||
M.capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
M.capabilities.textDocument.completion.completionItem.snippetSupport = true
|
||||
M.capabilities = cmp_nvim_lsp.update_capabilities(M.capabilities)
|
||||
|
||||
M.setup = function()
|
||||
local signs = {
|
||||
|
||||
{ name = "DiagnosticSignError", text = "" },
|
||||
{ name = "DiagnosticSignWarn", text = "" },
|
||||
{ name = "DiagnosticSignHint", text = "" },
|
||||
{ name = "DiagnosticSignInfo", text = "" },
|
||||
}
|
||||
|
||||
for _, sign in ipairs(signs) do
|
||||
vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = "" })
|
||||
end
|
||||
|
||||
local config = {
|
||||
virtual_text = false, -- disable virtual text
|
||||
signs = {
|
||||
active = signs, -- show signs
|
||||
},
|
||||
update_in_insert = true,
|
||||
underline = true,
|
||||
severity_sort = true,
|
||||
float = {
|
||||
focusable = true,
|
||||
style = "minimal",
|
||||
border = "rounded",
|
||||
source = "always",
|
||||
header = "",
|
||||
prefix = "",
|
||||
},
|
||||
}
|
||||
|
||||
vim.diagnostic.config(config)
|
||||
|
||||
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, {
|
||||
border = "rounded",
|
||||
})
|
||||
|
||||
vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, {
|
||||
border = "rounded",
|
||||
})
|
||||
end
|
||||
|
||||
local function lsp_keymaps(bufnr)
|
||||
local opts = { noremap = true, silent = true }
|
||||
local keymap = vim.api.nvim_buf_set_keymap
|
||||
keymap(bufnr, "n", "gD", "<cmd>lua vim.lsp.buf.declaration()<CR>", opts)
|
||||
keymap(bufnr, "n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>", opts)
|
||||
keymap(bufnr, "n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", opts)
|
||||
keymap(bufnr, "n", "gI", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts)
|
||||
keymap(bufnr, "n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts)
|
||||
keymap(bufnr, "n", "gl", "<cmd>lua vim.diagnostic.open_float()<CR>", opts)
|
||||
keymap(bufnr, "n", "<leader>lf", "<cmd>lua vim.lsp.buf.formatting()<cr>", opts)
|
||||
-- keymap(bufnr, "n", "<leader>li", "<cmd>LspInfo<cr>", opts)
|
||||
-- keymap(bufnr, "n", "<leader>lI", "<cmd>LspInstallInfo<cr>", opts)
|
||||
keymap(bufnr, "n", "<leader>la", "<cmd>lua vim.lsp.buf.code_action()<cr>", opts)
|
||||
keymap(bufnr, "n", "<leader>lj", "<cmd>lua vim.diagnostic.goto_next({buffer=0})<cr>", opts)
|
||||
keymap(bufnr, "n", "<leader>lk", "<cmd>lua vim.diagnostic.goto_prev({buffer=0})<cr>", opts)
|
||||
keymap(bufnr, "n", "<leader>lr", "<cmd>lua vim.lsp.buf.rename()<cr>", opts)
|
||||
keymap(bufnr, "n", "<leader>ls", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts)
|
||||
keymap(bufnr, "n", "<leader>lq", "<cmd>lua vim.diagnostic.setloclist()<CR>", opts)
|
||||
end
|
||||
|
||||
M.on_attach = function(client, bufnr)
|
||||
if client.name == "tsserver" then
|
||||
client.resolved_capabilities.document_formatting = false
|
||||
end
|
||||
|
||||
if client.name == "sumneko_lua" then
|
||||
client.resolved_capabilities.document_formatting = false
|
||||
end
|
||||
|
||||
lsp_keymaps(bufnr)
|
||||
local status_ok, illuminate = pcall(require, "illuminate")
|
||||
if not status_ok then
|
||||
return
|
||||
end
|
||||
illuminate.on_attach(client)
|
||||
end
|
||||
|
||||
return M
|
8
.config/nvim/lua/user/lsp/init.lua
Normal file
8
.config/nvim/lua/user/lsp/init.lua
Normal file
@ -0,0 +1,8 @@
|
||||
local status_ok, _ = pcall(require, "lspconfig")
|
||||
if not status_ok then
|
||||
return
|
||||
end
|
||||
|
||||
require("user.lsp.lsp-installer")
|
||||
require("user.lsp.handlers").setup()
|
||||
require("user.lsp.null-ls")
|
46
.config/nvim/lua/user/lsp/lsp-installer.lua
Normal file
46
.config/nvim/lua/user/lsp/lsp-installer.lua
Normal file
@ -0,0 +1,46 @@
|
||||
local status_ok, lsp_installer = pcall(require, "nvim-lsp-installer")
|
||||
if not status_ok then
|
||||
return
|
||||
end
|
||||
|
||||
local servers = {
|
||||
"sumneko_lua",
|
||||
-- "cssls",
|
||||
-- "html",
|
||||
-- "tsserver",
|
||||
"gopls",
|
||||
-- "grammarly",
|
||||
"golangci_lint_ls",
|
||||
"pyright",
|
||||
"bashls",
|
||||
"jsonls",
|
||||
"yamlls",
|
||||
}
|
||||
|
||||
lsp_installer.setup()
|
||||
|
||||
local lspconfig_status_ok, lspconfig = pcall(require, "lspconfig")
|
||||
if not lspconfig_status_ok then
|
||||
return
|
||||
end
|
||||
|
||||
local opts = {}
|
||||
|
||||
for _, server in pairs(servers) do
|
||||
opts = {
|
||||
on_attach = require("user.lsp.handlers").on_attach,
|
||||
capabilities = require("user.lsp.handlers").capabilities,
|
||||
}
|
||||
|
||||
if server == "sumneko_lua" then
|
||||
local sumneko_opts = require("user.lsp.settings.sumneko_lua")
|
||||
opts = vim.tbl_deep_extend("force", sumneko_opts, opts)
|
||||
end
|
||||
|
||||
if server == "pyright" then
|
||||
local pyright_opts = require("user.lsp.settings.pyright")
|
||||
opts = vim.tbl_deep_extend("force", pyright_opts, opts)
|
||||
end
|
||||
|
||||
lspconfig[server].setup(opts)
|
||||
end
|
29
.config/nvim/lua/user/lsp/null-ls.lua
Normal file
29
.config/nvim/lua/user/lsp/null-ls.lua
Normal file
@ -0,0 +1,29 @@
|
||||
local null_ls_status_ok, null_ls = pcall(require, "null-ls")
|
||||
if not null_ls_status_ok then
|
||||
return
|
||||
end
|
||||
|
||||
-- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/formatting
|
||||
local formatting = null_ls.builtins.formatting
|
||||
-- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/diagnostics
|
||||
local diagnostics = null_ls.builtins.diagnostics
|
||||
|
||||
-- https://github.com/prettier-solidity/prettier-plugin-solidity
|
||||
null_ls.setup({
|
||||
debug = false,
|
||||
sources = {
|
||||
formatting.prettier.with({
|
||||
extra_filetypes = { "toml" },
|
||||
extra_args = { "--no-semi", "--single-quote", "--jsx-single-quote" },
|
||||
}),
|
||||
formatting.black.with({ extra_args = { "--fast" } }),
|
||||
formatting.stylua,
|
||||
diagnostics.golangci_lint.with({ extra_args = { "--fast" } }),
|
||||
diagnostics.flake8.with({
|
||||
extra_args = { "--max-line-length=120" },
|
||||
}),
|
||||
diagnostics.cfn_lint,
|
||||
diagnostics.shellcheck,
|
||||
diagnostics.hadolint,
|
||||
},
|
||||
})
|
9
.config/nvim/lua/user/lsp/settings/pyright.lua
Normal file
9
.config/nvim/lua/user/lsp/settings/pyright.lua
Normal file
@ -0,0 +1,9 @@
|
||||
return {
|
||||
settings = {
|
||||
python = {
|
||||
analysis = {
|
||||
typeCheckingMode = "off",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
18
.config/nvim/lua/user/lsp/settings/sumneko_lua.lua
Normal file
18
.config/nvim/lua/user/lsp/settings/sumneko_lua.lua
Normal file
@ -0,0 +1,18 @@
|
||||
return {
|
||||
settings = {
|
||||
Lua = {
|
||||
diagnostics = {
|
||||
globals = { "vim" },
|
||||
},
|
||||
workspace = {
|
||||
library = {
|
||||
[vim.fn.expand("$VIMRUNTIME/lua")] = true,
|
||||
[vim.fn.stdpath("config") .. "/lua"] = true,
|
||||
},
|
||||
},
|
||||
telemetry = {
|
||||
enable = false,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
Reference in New Issue
Block a user