summaryrefslogtreecommitdiff
path: root/fnl/plugins/lsp
diff options
context:
space:
mode:
authorGustaf Rydholm <gustaf.rydholm@gmail.com>2023-09-14 23:39:44 +0200
committerGustaf Rydholm <gustaf.rydholm@gmail.com>2023-09-14 23:39:44 +0200
commit2ea97661a3564c02ac984c3e1280c4b8070dffb2 (patch)
tree9bcc931ff45bd801a5a875aed32b75697c1b3a10 /fnl/plugins/lsp
parent8cb82868b64912ccd73eb8aad3fb94c9bcfde32d (diff)
Add format mods
Diffstat (limited to 'fnl/plugins/lsp')
-rw-r--r--fnl/plugins/lsp/lspconfig.fnl20
1 files changed, 18 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))}