🔧 Configured neovim with prettier directly
This commit is contained in:
parent
0b66336477
commit
f9e4432c45
3 changed files with 95 additions and 9 deletions
32
.config/nvim/after/plugin/null-ls.lua
Normal file
32
.config/nvim/after/plugin/null-ls.lua
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
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"
|
||||
|
||||
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" })
|
||||
|
||||
-- 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", "<Leader>f", function()
|
||||
vim.lsp.buf.format({ bufnr = vim.api.nvim_get_current_buf() })
|
||||
end, { buffer = bufnr, desc = "[lsp] format" })
|
||||
end
|
||||
end,
|
||||
})
|
||||
52
.config/nvim/after/plugin/prettier.lua
Normal file
52
.config/nvim/after/plugin/prettier.lua
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
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",
|
||||
},
|
||||
["null-ls"] = {
|
||||
condition = function()
|
||||
return prettier.config_exists({
|
||||
-- if `false`, skips checking `package.json` for `"prettier"` key
|
||||
check_package_json = true,
|
||||
})
|
||||
end,
|
||||
runtime_condition = function(params)
|
||||
-- return false to skip running prettier
|
||||
return true
|
||||
end,
|
||||
timeout = 5000,
|
||||
},
|
||||
cli_options = {
|
||||
arrow_parens = "always",
|
||||
bracket_spacing = true,
|
||||
bracket_same_line = false,
|
||||
embedded_language_formatting = "auto",
|
||||
end_of_line = "lf",
|
||||
html_whitespace_sensitivity = "css",
|
||||
-- jsx_bracket_same_line = false,
|
||||
jsx_single_quote = false,
|
||||
print_width = 80,
|
||||
prose_wrap = "preserve",
|
||||
quote_props = "as-needed",
|
||||
semi = true,
|
||||
single_attribute_per_line = false,
|
||||
single_quote = false,
|
||||
tab_width = 2,
|
||||
trailing_comma = "es5",
|
||||
use_tabs = false,
|
||||
vue_indent_script_and_style = false,
|
||||
},
|
||||
})
|
||||
|
|
@ -6,14 +6,14 @@ vim.cmd([[packadd packer.nvim]])
|
|||
return require("packer").startup(function(use)
|
||||
-- Packer can manage itself
|
||||
use("wbthomason/packer.nvim")
|
||||
use({ "nvim-treesitter/nvim-treesitter", run = ":TSUpdate" })
|
||||
use({ "nvim-treesitter/playground" })
|
||||
use({
|
||||
"shaunsingh/nord.nvim",
|
||||
config = function()
|
||||
vim.cmd("colorscheme nord")
|
||||
end,
|
||||
})
|
||||
use({ "nvim-treesitter/nvim-treesitter", run = ":TSUpdate" })
|
||||
use({ "nvim-treesitter/playground" })
|
||||
use({
|
||||
"shaunsingh/nord.nvim",
|
||||
config = function()
|
||||
vim.cmd("colorscheme nord")
|
||||
end,
|
||||
})
|
||||
use({ "preservim/nerdcommenter" })
|
||||
use({ "nvim-lualine/lualine.nvim", requires = { "kyazdani42/nvim-web-devicons", opt = true } })
|
||||
use({ "kyazdani42/nvim-web-devicons" })
|
||||
|
|
@ -24,7 +24,7 @@ return require("packer").startup(function(use)
|
|||
use({ "lewis6991/impatient.nvim" })
|
||||
use({ "airblade/vim-gitgutter" })
|
||||
use({ "f-person/git-blame.nvim" })
|
||||
use({ "norcalli/nvim-colorizer.lua" })
|
||||
-- use({ "norcalli/nvim-colorizer.lua" })
|
||||
use({ "mattn/emmet-vim" })
|
||||
use({ "windwp/nvim-autopairs" })
|
||||
use({ "simeji/winresizer" })
|
||||
|
|
@ -71,6 +71,8 @@ return require("packer").startup(function(use)
|
|||
{ "rafamadriz/friendly-snippets" },
|
||||
},
|
||||
})
|
||||
use('jose-elias-alvarez/null-ls.nvim')
|
||||
use('MunifTanjim/prettier.nvim')
|
||||
use({ "rcarriga/nvim-dap-ui", requires = { "mfussenegger/nvim-dap" } })
|
||||
use({
|
||||
"mfussenegger/nvim-dap",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue