From 118e3f5a2a1f6792d60c5474ed7c829598690b6d Mon Sep 17 00:00:00 2001 From: Ariel D'Alessandro Date: Fri, 9 Sep 2022 09:26:48 +0200 Subject: Improve format on save, remove move panels --- after/plugin/hydra.lua | 8 ++++---- after/plugin/lsp.lua | 49 +++++++++++++++++++++++++++++++++++++------------ 2 files changed, 41 insertions(+), 16 deletions(-) (limited to 'after/plugin') diff --git a/after/plugin/hydra.lua b/after/plugin/hydra.lua index 6f60f21..64088ab 100644 --- a/after/plugin/hydra.lua +++ b/after/plugin/hydra.lua @@ -19,10 +19,10 @@ hydra({ { "H", "2<" }, { "J", "2-" }, { "K", "2+" }, - { "", "L" }, - { "", "H" }, - { "", "J" }, - { "", "K" }, + -- { "", "L" }, + -- { "", "H" }, + -- { "", "J" }, + -- { "", "K" }, { "=", "=" }, }, }) diff --git a/after/plugin/lsp.lua b/after/plugin/lsp.lua index 8983cf4..9464813 100644 --- a/after/plugin/lsp.lua +++ b/after/plugin/lsp.lua @@ -1,18 +1,43 @@ local telescope_mapper = require("alpha.telescope.mappings") -local format_on_save = function(_) - vim.cmd([[ - augroup lsp_buf_format - au! BufWritePre - autocmd BufWritePre :lua vim.lsp.buf.format({ async = true }) - augroup END - ]]) + +local lsp_formatting = function(bufnr, allowed_clientes) + vim.lsp.buf.format({ + filter = function(client) + for _, value in pairs(allowed_clientes) do + if client.name == value then + return true + end + end + + return false + end, + bufnr = bufnr, + }) +end + +-- if you want to set up formatting on save, you can use this as a callback +local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) + +local format_on_save = function (allowed_clients) + return function(client, bufnr) + if client.supports_method("textDocument/formatting") then + vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) + vim.api.nvim_create_autocmd("BufWritePre", { + group = augroup, + buffer = bufnr, + callback = function() + lsp_formatting(bufnr, allowed_clients) + end, + }) + end + end end local filetype_attach = setmetatable({ - go = format_on_save, - -- php = format_on_save, - -- lua = format_on_save, + go = format_on_save({"gopls"}), + -- php = format_on_save, + -- lua = format_on_save, gdscript = function(_) end, }, { @@ -30,7 +55,7 @@ vim.keymap.set("n", "vf", function() return vim.lsp.buf.format({ async = true }) end, {}) -local function on_attach(client) +local function on_attach(client, bufnr) local filetype = vim.api.nvim_buf_get_option(0, "filetype") -- keymaps for lsp vim.keymap.set("n", "K", vim.lsp.buf.hover, { buffer = 0 }) @@ -48,7 +73,7 @@ local function on_attach(client) vim.bo.omnifunc = "v:lua.vim.lsp.omnifunc" -- Attach any filetype specific options to the client - filetype_attach[filetype](client) + filetype_attach[filetype](client,bufnr) end -- vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { -- cgit v1.2.3