summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Vink <>2023-04-01 17:43:31 +0200
committerMike Vink <>2023-04-01 17:43:31 +0200
commite4602c57b81f9baf73f9c9be226bb0ba03db3d90 (patch)
tree2cba4b0d84e38dc08126d3bf6301e88fb1c85a3b
parent4c0079983a4279387017c3e73417caa5249e7a37 (diff)
add format on save stuff
-rw-r--r--fnl/conf/init.fnl6
-rw-r--r--fnl/conf/lsp.fnl30
-rw-r--r--fnl/conf/macros.fnl5
-rw-r--r--fnl/conf/pkgs/lspconfig.fnl26
4 files changed, 43 insertions, 24 deletions
diff --git a/fnl/conf/init.fnl b/fnl/conf/init.fnl
index b1a0af1..4728c76 100644
--- a/fnl/conf/init.fnl
+++ b/fnl/conf/init.fnl
@@ -23,3 +23,9 @@
(map :n "]q" ":cnext<cr>")
(map :n "[x" ":lprevious<cr>")
(map :n "]x" ":lnext<cr>"))
+
+(tset _G :P (lambda [...]
+ (let [inspected (icollect [_ v (ipairs [...])]
+ (vim.inspect v))]
+ (each [_ printer (ipairs inspected)]
+ (print printer)))))
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}
diff --git a/fnl/conf/macros.fnl b/fnl/conf/macros.fnl
index 04a7251..9ce8b26 100644
--- a/fnl/conf/macros.fnl
+++ b/fnl/conf/macros.fnl
@@ -42,7 +42,4 @@
(each [a# b# (ipairs l#)]
(tset (. vim :g) (. b# 1) (. b# 2)))))
-(fn P [...]
- `(print (vim.inspect [...])))
-
-{: P : settings : globals}
+{: settings : globals}
diff --git a/fnl/conf/pkgs/lspconfig.fnl b/fnl/conf/pkgs/lspconfig.fnl
index 680709d..af232ba 100644
--- a/fnl/conf/pkgs/lspconfig.fnl
+++ b/fnl/conf/pkgs/lspconfig.fnl
@@ -17,16 +17,16 @@
;; Show a code lens toggling the display of gc's choices.}
:buildFlags [:-tags=all]}}})
-(tset configs :fennel_language_server
- {:default_config {;; replace it with true path
- :cmd [:fennel-language-server]
- :filetypes [:fennel]
- :single_file_support true
- ;; source code resides in directory `fnl/`
- :root_dir (lspconfig.util.root_pattern :fnl)
- :settings {:fennel {:workspace {;; If you are using hotpot.nvim or aniseed,
- ;; make the server aware of neovim runtime files.
- :library (vim.api.nvim_list_runtime_paths)}
- :diagnostics {:globals [:vim]}}}}})
-
-(lspconfig.fennel_language_server.setup {:on_attach attach})
+;; (tset configs :fennel_language_server
+;; {:default_config {;; replace it with true path
+;; :cmd [:fennel-language-server]
+;; :filetypes [:fennel]
+;; :single_file_support true
+;; ;; source code resides in directory `fnl/`
+;; :root_dir (lspconfig.util.root_pattern :fnl)
+;; :settings {:fennel {:workspace {;; If you are using hotpot.nvim or aniseed,
+;; ;; make the server aware of neovim runtime files.
+;; :library (vim.api.nvim_list_runtime_paths)}
+;; :diagnostics {:globals [:vim]}}}}})
+;;
+;; (lspconfig.fennel_language_server.setup {:on_attach attach})