▲ 35 r/neovim
Native Prettier formatting in Neovim 0.12?
Hey, I rewrote my whole config for Neovim 0.12. Autocompletion and formatting all run on LSP now, I don't use plugins for it. The only thing I struggle with is to integrate Prettier into this.
These are my autocmds. All of them are directly from the docs:
vim.api.nvim_create_autocmd("LspAttach", { group = vim.api.nvim_create_augroup("my.lsp", {}),
callback = function(ev) local client = assert(vim.lsp.get_client_by_id(ev.data.client_id))
if client:supports_method("textDocument/completion") then
vim.lsp.completion.enable(true, client.id, ev.buf, { autotrigger = true })
end
if client:supports_method("textDocument/formatting") then
vim.api.nvim_create_autocmd("BufWritePre", {
group = vim.api.nvim_create_augroup("my.lsp", { clear = false }),
buffer = ev.buf,
callback = function()
vim.lsp.buf.format({ bufnr = ev.buf, id = client.id, timeout_ms = 1000 })
end,
})
end
if client:supports_method("textDocument/inlayHint") then
vim.lsp.inlay_hint.enable(true, { bufnr = ev.buf })
end
end, })
u/3rfan — 5 days ago