Update init.lua
This commit is contained in:
		
							parent
							
								
									989b9da516
								
							
						
					
					
						commit
						df2ae5a223
					
				
							
								
								
									
										109
									
								
								init.lua
								
								
								
								
							
							
						
						
									
										109
									
								
								init.lua
								
								
								
								
							|  | @ -72,6 +72,14 @@ require('packer').startup(function(use) | ||||||
| 		tag = 'nightly' | 		tag = 'nightly' | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	-- Vim commentary | ||||||
|  | 	use 'tpope/vim-commentary' | ||||||
|  | 
 | ||||||
|  | 	-- prettier.nvim setup | ||||||
|  | 	use('neovim/nvim-lspconfig') | ||||||
|  | 	use('jose-elias-alvarez/null-ls.nvim') | ||||||
|  | 	use('MunifTanjim/prettier.nvim') | ||||||
|  | 
 | ||||||
| 	-- Add custom plugins to packer from ~/.config/nvim/lua/custom/plugins.lua | 	-- Add custom plugins to packer from ~/.config/nvim/lua/custom/plugins.lua | ||||||
| 	local has_plugins, plugins = pcall(require, 'custom.plugins') | 	local has_plugins, plugins = pcall(require, 'custom.plugins') | ||||||
| 	if has_plugins then | 	if has_plugins then | ||||||
|  | @ -103,12 +111,6 @@ vim.api.nvim_create_autocmd('BufWritePost', { | ||||||
| 	group = packer_group, | 	group = packer_group, | ||||||
| 	pattern = vim.fn.expand '$MYVIMRC', | 	pattern = vim.fn.expand '$MYVIMRC', | ||||||
| }) | }) | ||||||
| -- Automatically eslint format on save |  | ||||||
| vim.api.nvim_create_autocmd('BufWritePre', { |  | ||||||
|   pattern = { '*.tsx', '*.ts', '*.jsx', '*.js' }, |  | ||||||
|   command = 'silent! EslintFixAll', |  | ||||||
|   group = vim.api.nvim_create_augroup('MyAutocmdsJavaScripFormatting', {}), |  | ||||||
| }) |  | ||||||
| 
 | 
 | ||||||
| -- [[ Setting options ]] | -- [[ Setting options ]] | ||||||
| -- See `:help vim.o` | -- See `:help vim.o` | ||||||
|  | @ -473,5 +475,100 @@ require("nvim-tree").setup({ | ||||||
| 		ignore = false, | 		ignore = false, | ||||||
| 	}, | 	}, | ||||||
| }) | }) | ||||||
|  | 
 | ||||||
|  | -- prettier.nvim setup | ||||||
|  | 
 | ||||||
|  | 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, | ||||||
|  | }) | ||||||
|  | 
 | ||||||
|  | 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", | ||||||
|  | 	}, | ||||||
|  | }) | ||||||
|  | 
 | ||||||
|  | prettier.setup({ | ||||||
|  | 	["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, | ||||||
|  | 	} | ||||||
|  | }) | ||||||
|  | 
 | ||||||
|  | prettier.setup({ | ||||||
|  | 	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, | ||||||
|  | 	}, | ||||||
|  | }) | ||||||
| -- The line beneath this is called `modeline`. See `:help modeline` | -- The line beneath this is called `modeline`. See `:help modeline` | ||||||
| -- vim: ts=2 sts=2 sw=2 et | -- vim: ts=2 sts=2 sw=2 et | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue