diff options
| author | Mike Vink <> | 2023-04-01 17:43:31 +0200 |
|---|---|---|
| committer | Mike Vink <> | 2023-04-01 17:43:31 +0200 |
| commit | e4602c57b81f9baf73f9c9be226bb0ba03db3d90 (patch) | |
| tree | 2cba4b0d84e38dc08126d3bf6301e88fb1c85a3b /fnl/conf/lsp.fnl | |
| parent | 4c0079983a4279387017c3e73417caa5249e7a37 (diff) | |
add format on save stuff
Diffstat (limited to 'fnl/conf/lsp.fnl')
| -rw-r--r-- | fnl/conf/lsp.fnl | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/fnl/conf/lsp.fnl b/fnl/conf/lsp.fnl index 47577bc..b4f35ab 100644 --- a/fnl/conf/lsp.fnl +++ b/fnl/conf/lsp.fnl @@ -1,7 +1,3 @@ -(fn P [p] - (print (vim.inspect p)) - p) - (fn map-to-capabilities [{: client : buf} format] (fn bo [name value] (vim.api.nvim_buf_set_option buf name value)) @@ -37,9 +33,9 @@ #(vim.lsp.buf.format {:async true}))))))) (each [cpb enabled? (pairs client.server_capabilities)] - (P cpb) (if enabled? - (use cpb)))) + (use cpb))) + {: client : buf}) (fn register-handlers [{: client : buf}] (tset (. client :handlers) :textDocument/publishDiagnostics @@ -53,9 +49,29 @@ :severity_sort true})) {: client : buf}) +(var format-on-save true) +(fn toggle-format-on-save [] + (set format-on-save (not format-on-save))) + +(vim.api.nvim_create_user_command :LspToggleOnSave toggle-format-on-save + {:nargs 1 :complete (fn [] [:format])}) + +(fn events [{: client : buf}] + (match client.server_capabilities + {:documentFormattingProvider true} + (let [format-events-group (vim.api.nvim_create_augroup :format-events + {:clear true})] + (vim.api.nvim_create_autocmd [:BufWritePre] + {:group format-events-group + :callback (lambda [] + (if format-on-save + (vim.lsp.buf.format))) + :buffer buf})))) + (fn attach [client buf format] (-> {: client : buf} (register-handlers) - (map-to-capabilities format))) + (map-to-capabilities format) + (events))) {: attach} |
