From 57fa8ef0db844433e6238b443b2dafe6bb57283e Mon Sep 17 00:00:00 2001 From: "Xin.Chen" Date: Thu, 6 Jan 2022 15:44:02 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20autoformat=20lua?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/lsp/lang/lua.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lua/lsp/lang/lua.lua b/lua/lsp/lang/lua.lua index 24fb67b..94c2d9d 100644 --- a/lua/lsp/lang/lua.lua +++ b/lua/lsp/lang/lua.lua @@ -34,12 +34,15 @@ local opts = { -- 禁用格式化功能,交给专门插件插件处理 client.resolved_capabilities.document_formatting = false client.resolved_capabilities.document_range_formatting = false + local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end -- local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end -- 绑定快捷键 require("keybindings").mapLSP(buf_set_keymap) + -- 保存时自动格式化 + vim.cmd("autocmd BufWritePre lua vim.lsp.buf.formatting_sync()") end, }