Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions after/plugin/prettier.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
local null_ls = require("null-ls")

null_ls.setup({
on_attach = function(client, bufnr)
if client.supports_method("textDocument/formatting") then
vim.keymap.set("n", "<Leader>f", function()
vim.lsp.buf.format({ bufnr = vim.api.nvim_get_current_buf() })
end, { buffer = bufnr, desc = "[lsp] format" })

-- uncomment to enable format on save
--[[
local group = vim.api.nvim_create_augroup("lsp_format_on_save", { clear = false })
local event = "BufWritePre" -- or "BufWritePost"
local async = event == "BufWritePost"

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", "<Leader>f", function()
vim.lsp.buf.format({ bufnr = vim.api.nvim_get_current_buf() })
end, { buffer = bufnr, desc = "[lsp] format" })
end
end,
})

local prettier = require("prettier")

prettier.setup({
bin = 'prettier', -- or `'prettierd'` (v0.22+)
filetypes = {
"css",
"graphql",
"html",
"javascript",
"javascriptreact",
"json",
"less",
"markdown",
"scss",
"typescript",
"typescriptreact",
"yaml",
},
})
4 changes: 4 additions & 0 deletions lua/theprimeagen/packer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ return require('packer').startup(function(use)
-- Snippets
{'L3MON4D3/LuaSnip'},
{'rafamadriz/friendly-snippets'},

-- prettier format
{'jose-elias-alvarez/null-ls.nvim'},
{'MunifTanjim/prettier.nvim'},
}
}

Expand Down