mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-07-10 09:24:37 +02:00
feat: initial commit
This commit is contained in:
commit
58e5dae036
18 changed files with 683 additions and 0 deletions
49
lua/user/plugins/lsp/format.lua
Normal file
49
lua/user/plugins/lsp/format.lua
Normal file
|
@ -0,0 +1,49 @@
|
|||
local M = {}
|
||||
|
||||
M.autoformat = true
|
||||
|
||||
function M.toggle()
|
||||
M.autoformat = not M.autoformat
|
||||
if M.autoformat then
|
||||
vim.notify("enabled format on save")
|
||||
else
|
||||
vim.notify("disabled format on save")
|
||||
end
|
||||
end
|
||||
|
||||
function M.format()
|
||||
if M.autoformat then
|
||||
vim.lsp.buf.format()
|
||||
end
|
||||
end
|
||||
|
||||
function M.nls_formatter(ft)
|
||||
local sources = require("null-ls.sources")
|
||||
local available = sources.get_available(ft, "NULL_LS_FORMATTING")
|
||||
return #available > 0
|
||||
end
|
||||
|
||||
function M.on_attach(client, buf)
|
||||
local ft = vim.api.nvim_buf_get_option(buf, "filetype")
|
||||
|
||||
local enable = false
|
||||
if M.nls_formatter(ft) then
|
||||
enable = client.name == "null-ls"
|
||||
else
|
||||
enable = not (client.name == "null-ls")
|
||||
end
|
||||
|
||||
client.server_capabilities.documentFormattingProvider = enable
|
||||
-- format on save
|
||||
if client.server_capabilities.documentFormattingProvider then
|
||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
group = vim.api.nvim_create_augroup("LspFormat", {}),
|
||||
buffer = 0,
|
||||
callback = function()
|
||||
M.format()
|
||||
end,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
49
lua/user/plugins/lsp/init.lua
Normal file
49
lua/user/plugins/lsp/init.lua
Normal file
|
@ -0,0 +1,49 @@
|
|||
local servers = require("user.plugins.lsp.servers")
|
||||
local function on_attach(client, bufnr)
|
||||
require("user.plugins.lsp.format").on_attach(client, bufnr)
|
||||
require("user.plugins.lsp.mappings").on_attach(client, bufnr)
|
||||
end
|
||||
|
||||
return {
|
||||
-- lspconfig
|
||||
{
|
||||
"neovim/nvim-lspconfig",
|
||||
event = "BufReadPre",
|
||||
dependencies = {
|
||||
{ "folke/neoconf.nvim", cmd = "Neoconf", config = true },
|
||||
{ "folke/neodev.nvim", config = true },
|
||||
{ "williamboman/mason.nvim", config = true },
|
||||
{ "williamboman/mason-lspconfig.nvim", config = { ensure_installed = vim.tbl_keys(servers) } },
|
||||
"hrsh7th/cmp-nvim-lsp",
|
||||
},
|
||||
config = function()
|
||||
---@type _.lspconfig.options
|
||||
local defaults = {
|
||||
on_attach = on_attach,
|
||||
capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()),
|
||||
}
|
||||
|
||||
for server, opts in pairs(servers) do
|
||||
opts = vim.tbl_deep_extend("force", {}, defaults, opts or {})
|
||||
require("lspconfig")[server].setup(opts)
|
||||
end
|
||||
end,
|
||||
},
|
||||
|
||||
-- formatters
|
||||
{
|
||||
"jose-elias-alvarez/null-ls.nvim",
|
||||
event = "BufReadPre",
|
||||
config = function()
|
||||
local nls = require("null-ls")
|
||||
nls.setup({
|
||||
on_attach = on_attach,
|
||||
sources = {
|
||||
-- nls.builtins.formatting.prettierd,
|
||||
nls.builtins.formatting.stylua,
|
||||
nls.builtins.diagnostics.flake8,
|
||||
},
|
||||
})
|
||||
end,
|
||||
},
|
||||
}
|
70
lua/user/plugins/lsp/mappings.lua
Normal file
70
lua/user/plugins/lsp/mappings.lua
Normal file
|
@ -0,0 +1,70 @@
|
|||
local M = {}
|
||||
|
||||
function M.on_attach(client, buffer)
|
||||
local cap = client.server_capabilities
|
||||
|
||||
require("which-key").register({
|
||||
buffer = buffer,
|
||||
["<leader>"] = {
|
||||
c = {
|
||||
name = "+code",
|
||||
{
|
||||
cond = client.name == "tsserver",
|
||||
o = { "<cmd>:TypescriptOrganizeImports<CR>", "Organize Imports" },
|
||||
R = { "<cmd>:TypescriptRenameFile<CR>", "Rename File" },
|
||||
},
|
||||
r = { "<cmd>lua vim.lsp.buf.rename()<cr>", "Rename", cond = cap.renameProvider },
|
||||
a = {
|
||||
{ vim.lsp.buf.code_action, "Code Action" },
|
||||
{ "<cmd>lua vim.lsp.buf.code_action()<cr>", "Code Action", mode = "v" },
|
||||
},
|
||||
f = {
|
||||
{
|
||||
require("user.plugins.lsp.format").format,
|
||||
"Format Document",
|
||||
cond = cap.documentFormatting,
|
||||
},
|
||||
{
|
||||
require("user.plugins.lsp.format").format,
|
||||
"Format Range",
|
||||
cond = cap.documentRangeFormatting,
|
||||
mode = "v",
|
||||
},
|
||||
},
|
||||
d = { vim.diagnostic.open_float, "Line Diagnostics" },
|
||||
l = {
|
||||
name = "+lsp",
|
||||
i = { "<cmd>LspInfo<cr>", "Lsp Info" },
|
||||
},
|
||||
},
|
||||
x = {
|
||||
d = { "<cmd>Telescope diagnostics<cr>", "Search Diagnostics" },
|
||||
},
|
||||
},
|
||||
g = {
|
||||
name = "+goto",
|
||||
d = { "<cmd>Telescope lsp_definitions<cr>", "Goto Definition" },
|
||||
r = { "<cmd>Telescope lsp_references<cr>", "References" },
|
||||
R = { "<cmd>Trouble lsp_references<cr>", "Trouble References" },
|
||||
D = { "<cmd>Telescope lsp_declarations<CR>", "Goto Declaration" },
|
||||
I = { "<cmd>Telescope lsp_implementations<CR>", "Goto Implementation" },
|
||||
t = { "<cmd>Telescope lsp_type_definitions<cr>", "Goto Type Definition" },
|
||||
},
|
||||
["<C-k>"] = { "<cmd>lua vim.lsp.buf.signature_help()<CR>", "Signature Help", mode = { "n", "i" } },
|
||||
["K"] = { "<cmd>lua vim.lsp.buf.hover()<CR>", "Hover" },
|
||||
["[d"] = { "<cmd>lua vim.diagnostic.goto_prev()<CR>", "Next Diagnostic" },
|
||||
["]d"] = { "<cmd>lua vim.diagnostic.goto_next()<CR>", "Prev Diagnostic" },
|
||||
["[e"] = { "<cmd>lua vim.diagnostic.goto_prev({severity = vim.diagnostic.severity.ERROR})<CR>", "Next Error" },
|
||||
["]e"] = { "<cmd>lua vim.diagnostic.goto_next({severity = vim.diagnostic.severity.ERROR})<CR>", "Prev Error" },
|
||||
["[w"] = {
|
||||
"<cmd>lua vim.diagnostic.goto_prev({severity = vim.diagnostic.severity.WARNING})<CR>",
|
||||
"Next Warning",
|
||||
},
|
||||
["]w"] = {
|
||||
"<cmd>lua vim.diagnostic.goto_next({severity = vim.diagnostic.severity.WARNING})<CR>",
|
||||
"Prev Warning",
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
25
lua/user/plugins/lsp/servers.lua
Normal file
25
lua/user/plugins/lsp/servers.lua
Normal file
|
@ -0,0 +1,25 @@
|
|||
---@type lspconfig.options
|
||||
local servers = {
|
||||
bashls = {},
|
||||
clangd = {},
|
||||
cssls = {},
|
||||
tsserver = {},
|
||||
html = {},
|
||||
jsonls = {},
|
||||
pyright = {},
|
||||
yamlls = {},
|
||||
sumneko_lua = {
|
||||
settings = {
|
||||
Lua = {
|
||||
workspace = {
|
||||
checkThirdParty = false,
|
||||
},
|
||||
completion = {
|
||||
callSnippet = "Replace",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return servers
|
Loading…
Add table
Add a link
Reference in a new issue