From 42be4bcc88ca39a7f703719998cf50550b1dda45 Mon Sep 17 00:00:00 2001 From: Vinit Neogi <20491952+vneogi199@users.noreply.github.com> Date: Mon, 13 Nov 2023 00:10:35 +0530 Subject: [PATCH] add formatter using conform.nvim --- init.lua | 23 ++++++++++++++++------ lazy-lock.json | 1 + lua/custom/plugins/conform.lua | 36 ++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 lua/custom/plugins/conform.lua diff --git a/init.lua b/init.lua index 772f4153..4cf48f74 100644 --- a/init.lua +++ b/init.lua @@ -88,7 +88,7 @@ require('lazy').setup({ -- Useful status updates for LSP -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})` - { 'j-hui/fidget.nvim', tag = 'legacy', opts = {} }, + { 'j-hui/fidget.nvim', tag = 'legacy', opts = {} }, -- Additional lua configuration, makes nvim stuff amazing! 'folke/neodev.nvim', @@ -378,7 +378,7 @@ local function live_grep_git_root() local git_root = find_git_root() if git_root then require('telescope.builtin').live_grep({ - search_dirs = {git_root}, + search_dirs = { git_root }, }) end end @@ -411,7 +411,7 @@ vim.keymap.set('n', 'sr', require('telescope.builtin').resume, { desc = vim.defer_fn(function() require('nvim-treesitter.configs').setup { -- Add languages to be installed here that you want installed for treesitter - ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'tsx', 'javascript', 'typescript', 'vimdoc', 'vim', 'bash' }, + ensure_installed = { 'bash', 'go', 'lua', 'python', 'rust', 'tsx', 'javascript', 'typescript', 'vimdoc', 'vim' }, -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!) auto_install = false, @@ -532,7 +532,15 @@ require('which-key').register { -- mason-lspconfig requires that these setup functions are called in this order -- before setting up the servers. -require('mason').setup() +require('mason').setup({ + ui = { + icons = { + package_installed = "✓", + package_pending = "➜", + package_uninstalled = "✗", + }, + }, +}) require('mason-lspconfig').setup() -- Enable the following language servers @@ -548,8 +556,11 @@ local servers = { -- gopls = {}, -- pyright = {}, -- rust_analyzer = {}, - -- tsserver = {}, - -- html = { filetypes = { 'html', 'twig', 'hbs'} }, + angularls = {}, + cssls = {}, + emmet_ls = {}, + tsserver = {}, + html = { filetypes = { 'html', 'twig', 'hbs' } }, lua_ls = { Lua = { diff --git a/lazy-lock.json b/lazy-lock.json index fc36a043..446f4378 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -5,6 +5,7 @@ "cheatsheet.nvim": { "branch": "master", "commit": "9716f9aaa94dd1fd6ce59b5aae0e5f25e2a463ef" }, "cmp-nvim-lsp": { "branch": "main", "commit": "44b16d11215dce86f253ce0c30949813c0a90765" }, "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" }, + "conform.nvim": { "branch": "master", "commit": "e388bd6725d83f83639e24482b9d1bca01c0c040" }, "fidget.nvim": { "branch": "main", "commit": "0ba1e16d07627532b6cae915cc992ecac249fb97" }, "flash.nvim": { "branch": "main", "commit": "48817af25f51c0590653bbc290866e4890fe1cbe" }, "friendly-snippets": { "branch": "main", "commit": "43727c2ff84240e55d4069ec3e6158d74cb534b6" }, diff --git a/lua/custom/plugins/conform.lua b/lua/custom/plugins/conform.lua new file mode 100644 index 00000000..c40fb1d3 --- /dev/null +++ b/lua/custom/plugins/conform.lua @@ -0,0 +1,36 @@ +return { + 'stevearc/conform.nvim', + event = { "BufReadPre", "BufNewFile" }, + config = function() + local conform = require('conform'); + conform.setup({ + formatters_by_ft = { + javascript = { "prettier" }, + typescript = { "prettier" }, + javascriptreact = { "prettier" }, + typescriptreact = { "prettier" }, + svelte = { "prettier" }, + css = { "prettier" }, + html = { "prettier" }, + json = { "prettier" }, + yaml = { "prettier" }, + markdown = { "prettier" }, + graphql = { "prettier" }, + lua = { "stylua" }, + -- python = { "isort", "black" }, + }, + format_on_save = { + lsp_fallback = true, + async = false, + timeout_ms = 500, + }, + }) + vim.keymap.set({ "n", "v" }, "mp", function() + conform.format({ + lsp_fallback = true, + async = false, + timeout_ms = 500, + }) + end, { desc = "Format file or range (in visual mode)" }) + end +}