mirror of https://github.com/E-Almqvist/dotfiles
parent
e3bb86e043
commit
fd5ca88b83
@ -0,0 +1,34 @@ |
||||
local null_ls = require("null-ls") |
||||
|
||||
local group = vim.api.nvim_create_augroup("lsp_format_on_save", { clear = false }) |
||||
local event = "BufWritePre" -- or "BufWritePost" |
||||
local async = event == "BufWritePost" |
||||
|
||||
local format_bind = "<A-g>" |
||||
|
||||
null_ls.setup({ |
||||
on_attach = function(client, bufnr) |
||||
if client.supports_method("textDocument/formatting") then |
||||
vim.keymap.set("n", format_bind, function() |
||||
vim.lsp.buf.format({ bufnr = vim.api.nvim_get_current_buf() }) |
||||
end, { buffer = bufnr, desc = "[lsp] Format" }) |
||||
|
||||
-- format on save |
||||
vim.api.nvim_clear_autocmds({ buffer = bufnr, group = group }) |
||||
vim.api.nvim_create_autocmd(event, { |
||||
buffer = bufnr, |
||||
group = group, |
||||
callback = function() |
||||
vim.lsp.buf.format({ bufnr = bufnr, async = async }) |
||||
end, |
||||
desc = "[lsp] Format on save", |
||||
}) |
||||
end |
||||
|
||||
if client.supports_method("textDocument/rangeFormatting") then |
||||
vim.keymap.set("x", format_bind, function() |
||||
vim.lsp.buf.format({ bufnr = vim.api.nvim_get_current_buf() }) |
||||
end, { buffer = bufnr, desc = "[lsp] Format" }) |
||||
end |
||||
end, |
||||
}) |
@ -0,0 +1,19 @@ |
||||
local prettier = require("prettier") |
||||
|
||||
prettier.setup({ |
||||
bin = "prettier", -- or `"prettierd"` (v0.23.3+) |
||||
filetypes = { |
||||
"css", |
||||
"graphql", |
||||
"html", |
||||
"javascript", |
||||
"javascriptreact", |
||||
"json", |
||||
"less", |
||||
"markdown", |
||||
"scss", |
||||
"typescript", |
||||
"typescriptreact", |
||||
"yaml", |
||||
}, |
||||
}) |
Loading…
Reference in new issue