nvim: Migrate configuration to lua and built-in plugin manager
This commit is contained in:
parent
9d31a63799
commit
6440203958
26 changed files with 453 additions and 616 deletions
|
|
@ -1,127 +1,3 @@
|
|||
return {
|
||||
"neovim/nvim-lspconfig",
|
||||
event = { "BufReadPre", "BufNewFile" },
|
||||
dependencies = {
|
||||
"hrsh7th/cmp-nvim-lsp",
|
||||
},
|
||||
keys = {
|
||||
{ "<space>e", vim.diagnostic.open_float },
|
||||
{ "[d", vim.diagnostic.goto_prev },
|
||||
{ "]d", vim.diagnostic.goto_next },
|
||||
{ "<space>q", vim.diagnostic.setloclist },
|
||||
{ "gD", vim.lsp.buf.declaration },
|
||||
{ "gd", vim.lsp.buf.definition },
|
||||
{ "K", vim.lsp.buf.hover },
|
||||
{ "gi", vim.lsp.buf.implementation },
|
||||
{ "<C-k>", vim.lsp.buf.signature_help },
|
||||
{ "<space>D", vim.lsp.buf.type_definition },
|
||||
{ "<space>rn", vim.lsp.buf.rename },
|
||||
{ "<space>ca", vim.lsp.buf.code_action },
|
||||
{ "gr", vim.lsp.buf.references },
|
||||
{
|
||||
"<space>f",
|
||||
function()
|
||||
vim.lsp.buf.format { async = true }
|
||||
end
|
||||
},
|
||||
},
|
||||
config = function()
|
||||
|
||||
local on_attach = function(client, bufnr)
|
||||
-- Format on save
|
||||
if client.server_capabilities.documentFormattingProvider then
|
||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
group = vim.api.nvim_create_augroup("Format", { clear = true }),
|
||||
buffer = bufnr,
|
||||
callback = function()
|
||||
vim.lsp.buf.format()
|
||||
end,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
-- Typos
|
||||
vim.lsp.config("typos_lsp", {
|
||||
settings = {
|
||||
filetypes = {
|
||||
'java',
|
||||
'go'
|
||||
},
|
||||
},
|
||||
init_options = {
|
||||
diagnosticSeverity = "Hint",
|
||||
}
|
||||
})
|
||||
|
||||
-- HTML
|
||||
vim.lsp.enable('html')
|
||||
|
||||
-- CSS
|
||||
vim.lsp.enable('cssls')
|
||||
|
||||
-- JSON
|
||||
vim.lsp.enable('jsonls')
|
||||
|
||||
-- Python
|
||||
vim.lsp.enable('pylsp')
|
||||
|
||||
-- Go
|
||||
vim.lsp.config("gopls", {
|
||||
settings = {
|
||||
gopls = {
|
||||
gofumpt = true,
|
||||
staticcheck = true,
|
||||
analyses = {
|
||||
unusedparams = true,
|
||||
unusedresult = true,
|
||||
unusedwrite = true,
|
||||
unusedvariable = true,
|
||||
useany = true,
|
||||
fieldalignment = false,
|
||||
nilness = true,
|
||||
shadow = true,
|
||||
},
|
||||
hints = {
|
||||
assignVariableTypes = true,
|
||||
compositeLiteralFields = true,
|
||||
compositeLiteralTypes = true,
|
||||
constantValues = true,
|
||||
functionTypeParameters = true,
|
||||
parameterNames = true,
|
||||
rangeVariableTypes = true,
|
||||
},
|
||||
codelenses = {
|
||||
gc_details = true,
|
||||
generate = true,
|
||||
regenerate_cgo = true,
|
||||
tidy = true,
|
||||
upgrade_dependency = true,
|
||||
vendor = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
-- Organize imports and format code on save
|
||||
vim.api.nvim_create_autocmd({"BufWritePre"}, {
|
||||
pattern = "*.go",
|
||||
callback = function()
|
||||
local params = vim.lsp.util.make_range_params()
|
||||
params.context = {only = {"source.organizeImports"}}
|
||||
local result = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params)
|
||||
for cid, res in pairs(result or {}) do
|
||||
for _, r in pairs(res.result or {}) do
|
||||
if r.edit then
|
||||
local enc = (vim.lsp.get_client_by_id(cid) or {}).offset_encoding or "utf-16"
|
||||
vim.lsp.util.apply_workspace_edit(r.edit, enc)
|
||||
end
|
||||
end
|
||||
end
|
||||
vim.lsp.buf.format({async = false})
|
||||
end
|
||||
})
|
||||
vim.lsp.enable('gopls')
|
||||
|
||||
-- PHP
|
||||
vim.lsp.enable('phpactor')
|
||||
end,
|
||||
}
|
||||
vim.pack.add({
|
||||
gh("neovim/nvim-lspconfig"),
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue