-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use pcall to invoke configured formatters (#65)
* feat: use pcall to invoke configured formatters * test: neodev * test
- Loading branch information
1 parent
664f888
commit 0655d95
Showing
5 changed files
with
151 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
local root = vim.fn.stdpath("data") | ||
|
||
-- bootstrap lazy | ||
local lazypath = root .. "/lazy/plugins/lazy.nvim" | ||
if not vim.loop.fs_stat(lazypath) then | ||
vim.fn.system({ | ||
"git", | ||
"clone", | ||
"--filter=blob:none", | ||
"https://github.com/folke/lazy.nvim.git", | ||
lazypath, | ||
}) | ||
end | ||
vim.opt.runtimepath:prepend(lazypath) | ||
|
||
-- install plugins | ||
local plugins = { | ||
{ -- Initialize language server configuration | ||
"neovim/nvim-lspconfig", | ||
cmd = { "LspInfo", "LspInstall", "LspUninstall" }, | ||
event = { "BufReadPost", "BufNewFile" }, | ||
dependencies = { | ||
{ "williamboman/mason.nvim", config = true }, | ||
{ "folke/neodev.nvim", config = true }, | ||
}, | ||
config = function() | ||
require("lspconfig")["lua_ls"].setup({ | ||
settings = { | ||
Lua = { | ||
diagnostics = { | ||
enable = true, | ||
globals = { "vim" }, | ||
}, | ||
workspace = { | ||
checkThirdParty = false, | ||
}, | ||
}, | ||
}, | ||
}) | ||
end, | ||
}, | ||
{ | ||
"jose-elias-alvarez/null-ls.nvim", | ||
event = { "BufReadPost", "BufNewFile" }, | ||
dependencies = { "nvim-lua/plenary.nvim" }, | ||
config = function() | ||
local null_ls = require("null-ls") | ||
null_ls.setup({ | ||
sources = { null_ls.builtins.formatting.stylua }, | ||
}) | ||
end, | ||
}, | ||
{ | ||
"nvim-lualine/lualine.nvim", | ||
event = "UIEnter", | ||
dependencies = { | ||
-- Lua fork of vim-web-devicons for neovim | ||
{ "nvim-tree/nvim-web-devicons" }, | ||
-- A performant lsp progress status for Neovim. | ||
{ | ||
"linrongbin16/lsp-progress.nvim", | ||
config = true, | ||
-- dev = true, | ||
-- dir = "~/github/linrongbin16/lsp-progress.nvim", | ||
}, | ||
}, | ||
config = function(_, opts) | ||
require("lualine").setup(opts) | ||
|
||
vim.api.nvim_create_augroup("lualine_augroup", { clear = true }) | ||
vim.api.nvim_create_autocmd("User LspProgressStatusUpdated", { | ||
group = "lualine_augroup", | ||
callback = require("lualine").refresh, | ||
}) | ||
end, | ||
opts = { | ||
sections = { | ||
lualine_a = { "mode" }, | ||
lualine_b = {}, | ||
lualine_c = { "filename" }, | ||
lualine_x = { | ||
{ -- Setup lsp-progress component | ||
function() | ||
return require("lsp-progress").progress({ | ||
max_size = 80, | ||
}) | ||
end, | ||
icon = { "", align = "right" }, | ||
}, | ||
"diagnostics", | ||
}, | ||
lualine_y = { "filetype", "encoding", "fileformat" }, | ||
lualine_z = { "location" }, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
-- Attach autocmd to enable auto-formatting on save | ||
vim.api.nvim_create_autocmd({ "LspAttach" }, { | ||
callback = function(ev) | ||
-- Apply autocmd if client supports formatting | ||
vim.api.nvim_create_autocmd("BufWritePre", { | ||
buffer = ev.buf, | ||
desc = "Apply Auto-formatting for to document on save", | ||
group = vim.api.nvim_create_augroup("LspFormat." .. ev.buf, {}), | ||
callback = function() | ||
vim.lsp.buf.format({ | ||
bufnr = ev.buf, | ||
filter = function(client) | ||
return client.name == "null-ls" | ||
end, | ||
}) | ||
end, | ||
}) | ||
end, | ||
}) | ||
|
||
-- Setup lazy.nvim | ||
require("lazy").setup(plugins, { | ||
root = root .. "/lazy/plugins", | ||
}) |