nvim: Update LSP configuration
This commit is contained in:
parent
1a9e0964e7
commit
399fc584dd
1 changed files with 86 additions and 3 deletions
|
|
@ -26,9 +26,6 @@ return {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
config = function()
|
config = function()
|
||||||
local nvim_lsp = require("lspconfig")
|
|
||||||
|
|
||||||
local protocol = require("vim.lsp.protocol")
|
|
||||||
|
|
||||||
local on_attach = function(client, bufnr)
|
local on_attach = function(client, bufnr)
|
||||||
-- Format on save
|
-- Format on save
|
||||||
|
|
@ -42,5 +39,91 @@ return {
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Typos
|
||||||
|
vim.lsp.config("typos_lsp", {
|
||||||
|
settings = {
|
||||||
|
filetypes = {
|
||||||
|
'java',
|
||||||
|
'go'
|
||||||
|
},
|
||||||
|
},
|
||||||
|
init_options = {
|
||||||
|
diagnosticSeverity = "Hint",
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Gradle
|
||||||
|
--vim.lsp.enable('gradle_ls')
|
||||||
|
|
||||||
|
-- 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
|
||||||
|
})
|
||||||
|
|
||||||
|
-- PHP
|
||||||
|
vim.lsp.enable('phpactor')
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue