From f913fce8ee455b1808231026e3d04fa410f86615 Mon Sep 17 00:00:00 2001 From: Juni Kim Date: Tue, 7 Feb 2023 08:17:59 -0500 Subject: [PATCH] lsp formatting --- after/plugin/lsp.lua | 26 +++++++++++++++++++------- lua/junikim/options.lua | 9 --------- lua/junikim/remap.lua | 3 --- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/after/plugin/lsp.lua b/after/plugin/lsp.lua index a72fede..f6eaaa5 100644 --- a/after/plugin/lsp.lua +++ b/after/plugin/lsp.lua @@ -75,16 +75,28 @@ null_ls.setup({ }) end, sources = { - null_ls.builtins.formatting.prettier, - null_ls.builtins.formatting.autopep8, - null_ls.builtins.formatting.gofmt, - null_ls.builtins.diagnostics.eslint, - null_ls.builtins.diagnostics.shellcheck, } }) +vim.api.nvim_create_autocmd("BufWritePre", { + pattern = { "*.go", "*.py", "*.lua", "*.rs" }, + callback = function(args) + vim.lsp.buf.format { + timeout_ms = 5000 + } + end +}) + +vim.keymap.set("n", "ft", function() + vim.lsp.buf.format() +end) + +require('mason').setup() + require('mason-null-ls').setup({ - ensure_installed = nil, + ensure_installed = { "prettier", "autopep8", "eslint", "gofmt", "rustfmt", "shellcheck" }, automatic_installation = true, - automatic_setup = false, + automatic_setup = true, }) + +require('mason-null-ls').setup_handlers() diff --git a/lua/junikim/options.lua b/lua/junikim/options.lua index e13a9cb..7173fa9 100644 --- a/lua/junikim/options.lua +++ b/lua/junikim/options.lua @@ -21,7 +21,6 @@ vim.opt.undofile = true vim.opt.hlsearch = false vim.opt.incsearch = true - vim.opt.nu = true vim.opt.rnu = true vim.opt.termguicolors = true @@ -76,14 +75,6 @@ vim.api.nvim_create_autocmd("FileType", { vim.bo.softtabstop = 4 vim.bo.preserveindent = true vim.bo.copyindent = true - vim.bo.formatprg = "gofmt -e -w" vim.api.nvim_set_keymap("n", "", ":w|:!cpgo test", { noremap = true }) end }) - -vim.api.nvim_create_autocmd("BufWritePre", { - pattern = { "*.go", "*.py", "*.lua", "*.ts", "*.tsx", "*.js", "*.md", "*.json", "*.rs" }, - callback = function(args) - vim.lsp.buf.formatting_sync() - end -}) diff --git a/lua/junikim/remap.lua b/lua/junikim/remap.lua index daa731d..4d0e445 100644 --- a/lua/junikim/remap.lua +++ b/lua/junikim/remap.lua @@ -38,9 +38,6 @@ vim.keymap.set("n", "e", "!%:p", { silent = true }) vim.keymap.set("n", "vz", "e ~/.zshrc"); vim.keymap.set("n", "vc", "e ~/.config/nvim"); -vim.keymap.set("n", "fmt", function() - vim.lsp.buf.format() -end) if os.getenv("TMUX") ~= nil then vim.keymap.set("n", "", [[silent !tmux neww tmuxs\; setenv WORKSPACES $WORKSPACES \;]])