From 2ea97661a3564c02ac984c3e1280c4b8070dffb2 Mon Sep 17 00:00:00 2001 From: Gustaf Rydholm Date: Thu, 14 Sep 2023 23:39:44 +0200 Subject: Add format mods --- fnl/plugins/lsp/lspconfig.fnl | 20 ++++++++++++++++++-- lazy-lock.json | 1 + 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/fnl/plugins/lsp/lspconfig.fnl b/fnl/plugins/lsp/lspconfig.fnl index b29f1b1..d4f8790 100644 --- a/fnl/plugins/lsp/lspconfig.fnl +++ b/fnl/plugins/lsp/lspconfig.fnl @@ -1,11 +1,26 @@ ;; Setup of lsps. +(fn get-client-by-id [args] + (let [client-id (. (. args :data) :client_id)] + (vim.lsp.get_client_by_id client-id))) + +(fn format-modifications [client buffer] + (let [lsp-format-modifications (require :lsp-format-modifications)] + (vim.api.nvim_buf_create_user_command buffer :FormatModifications + (fn [] + (lsp-format-modifications.format_modifications client + buffer)) + {}))) + (fn on-attach [] (vim.api.nvim_create_autocmd :LspAttach {:callback (fn [args] (let [keymaps (require :plugins.lsp.keymaps) - buffer (. args :buf)] - (keymaps.on-attach buffer)))})) + buffer (. args :buf) + client (get-client-by-id args)] + (keymaps.on-attach buffer) + (format-modifications client + buffer)))})) (fn capabilities [] (let [cmp-lsp (require :cmp_nvim_lsp)] @@ -38,6 +53,7 @@ :dependencies [:mason.nvim :williamboman/mason-lspconfig.nvim :b0o/SchemaStore.nvim + :joechrisellis/lsp-format-modifications.nvim :hrsh7th/cmp-nvim-lsp] :config (fn [] (setup))} diff --git a/lazy-lock.json b/lazy-lock.json index 8ea9509..9ab8fbf 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -20,6 +20,7 @@ "hotpot.nvim": { "branch": "master", "commit": "1dc11eb47ca15828df8ed3c7a014eeca9c564e55" }, "lazy.nvim": { "branch": "main", "commit": "2a9354c7d2368d78cbd5575a51a2af5bd8a6ad01" }, "leap.nvim": { "branch": "main", "commit": "5efe985cf68fac3b6a6dfe7a75fbfaca8db2af9c" }, + "lsp-format-modifications.nvim": { "branch": "main", "commit": "006d4cd88f4f09fdc4375fcb75dd5b7d981a723b" }, "lspkind-nvim": { "branch": "master", "commit": "57610d5ab560c073c465d6faf0c19f200cb67e6e" }, "lualine-lsp-progress": { "branch": "master", "commit": "56842d097245a08d77912edf5f2a69ba29f275d7" }, "lualine.nvim": { "branch": "master", "commit": "45e27ca739c7be6c49e5496d14fcf45a303c3a63" }, -- cgit v1.2.3-70-g09d2