From a6a553c6b061d1468fc170721a8c65cc366db6aa Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Fri, 18 Aug 2023 10:44:33 -0700 Subject: [PATCH] Add back null-ls --- fnl/plugin.fnl | 66 +++++++++++++++++++++++++--------------------- fnl/plugin/lsp.fnl | 45 ++++++++++++++++++++++++++++--- 2 files changed, 78 insertions(+), 33 deletions(-) diff --git a/fnl/plugin.fnl b/fnl/plugin.fnl index d49f5ae..0fb0c9e 100644 --- a/fnl/plugin.fnl +++ b/fnl/plugin.fnl @@ -191,42 +191,48 @@ :config (module-call! :plugin.lsp :configure)) + ;; null-ls.nvim + (use! :jose-elias-alvarez/null-ls.nvim + :after :nvim-lspconfig + :config + (module-call! :plugin.lsp :setup-null-ls)) + ;; nvim-jdtls (use! :mfussenegger/nvim-jdtls :config (module-call! :plugin.jdtls :configure)) ;; formatter.nvim - (use! :mhartington/formatter.nvim - :cmd [ :Format :FormatWrite ] - :setup - (bind! :n :o "Format") - (bind! :v :o ":Format") - :config - (setup! :formatter - :logging true - :log_level _G.vim.log.levels.WARN - :filetype { - :c [ (module-fn! :formatter.filetypes.c :astyle) ] - :cpp [ (module-fn! :formatter.filetypes.cpp :astyle) ] - :cmake [ - (module-fn! :formatter.filetypes.cmake :cmakeformat) ] - :java [ (fn [] {:exe :astyle - :stdin true - :args [ :--mode=java ]}) ] - :sh [ (module-fn! :formatter.filetypes.sh :shfmt) ] - :rust [ (module-fn! :formatter.filetypes.rust :rustfmt) ] - :tex [ (module-fn! :formatter.filetypes.latex :latexindent) ] - :python [ (module-fn! :formatter.filetypes.python :yapf) ] - :json [ (module-fn! :formatter.filetypes.json :prettier) ] - :html [ (module-fn! :formatter.filetypes.html :prettier) ] - :css [ (module-fn! :formatter.filetypes.css :prettier) ] - :javascript [ (module-fn! :formatter.filetypes.javascript :prettier) ] - :markdown [ - (module-fn! :formatter.filetypes.markdown :prettier ) ] - :fennel [ (fn [] {:exe :fnlfmt - :stdin true - :args [ "-" ]})]})) + ;(use! :mhartington/formatter.nvim + ; :cmd [ :Format :FormatWrite ] + ; :setup + ; (bind! :n :o "Format") + ; (bind! :v :o ":Format") + ; :config + ; (setup! :formatter + ; :logging true + ; :log_level _G.vim.log.levels.WARN + ; :filetype { + ; :c [ (module-fn! :formatter.filetypes.c :astyle) ] + ; :cpp [ (module-fn! :formatter.filetypes.cpp :astyle) ] + ; :cmake [ + ; (module-fn! :formatter.filetypes.cmake :cmakeformat) ] + ; :java [ (fn [] {:exe :astyle + ; :stdin true + ; :args [ :--mode=java ]}) ] + ; :sh [ (module-fn! :formatter.filetypes.sh :shfmt) ] + ; :rust [ (module-fn! :formatter.filetypes.rust :rustfmt) ] + ; :tex [ (module-fn! :formatter.filetypes.latex :latexindent) ] + ; :python [ (module-fn! :formatter.filetypes.python :yapf) ] + ; :json [ (module-fn! :formatter.filetypes.json :prettier) ] + ; :html [ (module-fn! :formatter.filetypes.html :prettier) ] + ; :css [ (module-fn! :formatter.filetypes.css :prettier) ] + ; :javascript [ (module-fn! :formatter.filetypes.javascript :prettier) ] + ; :markdown [ + ; (module-fn! :formatter.filetypes.markdown :prettier ) ] + ; :fennel [ (fn [] {:exe :fnlfmt + ; :stdin true + ; :args [ "-" ]})]})) ;; Sync all packages on first launch (if _G.first_launch diff --git a/fnl/plugin/lsp.fnl b/fnl/plugin/lsp.fnl index 42e64cd..53153c3 100644 --- a/fnl/plugin/lsp.fnl +++ b/fnl/plugin/lsp.fnl @@ -21,8 +21,13 @@ (bind! :n :rn vim.lsp.buf.rename buf) (bind! :n :cn vim.lsp.buf.code_action buf) ; (bind! :n :gr vim.lsp.buf.references buf) - (when (= client.name :rust_analyzer) - (bind! [ :n :v ] :o #(vim.lsp.buf.format {:async true}))) + (bind! [ :n :v ] :o + #(vim.lsp.buf.format { :filter + ;; use null-ls for formatting + (fn [client] (or + (= client.name :null-ls) + (= client.name :rust_analyzer))) + :async true }) buf) ;; Use builtin formatexpr (vim.api.nvim_buf_set_option buf :formatexpr "") @@ -106,4 +111,38 @@ :diagnostics { :globals [ "vim" ] }}}))) -{: configure : on-attach : get-data-dir } +(fn setup-null-ls [] + (let [builtins (. (require :null-ls) :builtins)] + (setup! :null-ls + :on_attach (fn [client buf] + (bind! [ :n :v ] + :o + #(vim.lsp.buf.format + { :filter + ;; use null-ls for formatting + (fn [client] + (or + (= client.name :null-ls) + (= client.name :rust_analyzer))) + :async true }) buf) + (vim.api.nvim_buf_set_option buf :formatexpr "")) + :sources [ + builtins.formatting.astyle + builtins.formatting.prettier + builtins.formatting.yapf + builtins.formatting.fnlfmt + builtins.formatting.shfmt + builtins.formatting.cmake_format + builtins.formatting.latexindent + builtins.formatting.stylua + builtins.code_actions.shellcheck + (builtins.completion.spell.with { :filetypes [ :text + :markdown + :tex ]}) + builtins.diagnostics.cmake_lint + ;;builtins.diagnostics.codespell + ;;builtins.diagnostics.shellcheck + (builtins.diagnostics.glslc.with + { :extra_args [ "--target-env=opengl" ]})]))) + +{: configure : on-attach : get-data-dir : setup-null-ls }