From ccc185d43e03db06fbb679770b164c2eab6b6b49 Mon Sep 17 00:00:00 2001 From: Mike Vink Date: Tue, 22 Nov 2022 01:02:29 +0100 Subject: messing around... --- home.nix | 1 + neovim/fnl/conf/build-init.fnl | 0 neovim/fnl/conf/init.fnl | 3 +++ neovim/fnl/conf/log.fnl | 28 ++++++++++++++++++++++++++ neovim/fnl/conf/lsp.fnl | 43 ++++++++++++++++++++++++++++++++++++++++ neovim/fnl/conf/macros.fnl | 6 +++++- neovim/fnl/conf/pkgs.fnl | 1 + neovim/fnl/conf/pkgs/cmp.fnl | 28 +++++++++++--------------- neovim/fnl/conf/pkgs/null-ls.fnl | 17 ++++++++++++++++ 9 files changed, 110 insertions(+), 17 deletions(-) delete mode 100644 neovim/fnl/conf/build-init.fnl create mode 100644 neovim/fnl/conf/log.fnl create mode 100644 neovim/fnl/conf/lsp.fnl create mode 100644 neovim/fnl/conf/pkgs/null-ls.fnl diff --git a/home.nix b/home.nix index 1c90dde..29a4f45 100644 --- a/home.nix +++ b/home.nix @@ -99,6 +99,7 @@ yaml-language-server alejandra statix + fnlfmt ]; extraConfig = " lua < (vim.api.nvim_create_buf true false) + (setopt :filetype ft) + (setopt :buftype :nofile) + (setopt :bufhidden :hide) + (setopt :swapfile false))))) + +(let [log (fn [...] (P [...]))] + (vim.api.nvim_create_user_command + :Scratch + (fn [c] + (let [name c.args] + (fn exists? [buf] (not= buf nil)) + (fn get [] (. scratches c.args)) + (fn goto [buf] + (vim.api.nvim_set_current_buf buf)) + + (let [buf (get) current (vim.api.nvim_get_current_buf)] + (if (exists? buf) (goto buf) (goto (scratch-buffer name (vim.api.nvim_buf_get_option current :filetype))))))) + {:complete log + :nargs 1})) diff --git a/neovim/fnl/conf/lsp.fnl b/neovim/fnl/conf/lsp.fnl new file mode 100644 index 0000000..8cd4d53 --- /dev/null +++ b/neovim/fnl/conf/lsp.fnl @@ -0,0 +1,43 @@ +(fn map-to-capabilities [{: client : buf}] + (fn bufoption [name value] + (vim.api.nvim_buf_set_option buf name value)) + + (fn bufmap [mode key cb] + (vim.keymap.set mode key cb {:silent true :noremap true :buffer buf})) + + (fn lspdo [action] + (. vim.lsp action)) + + (fn use [cpb] + (match cpb + :completion (bufoption :omnifunc "v:lua.vim.lsp.omnifunc") + :rename (bufmap :n :gr (lspdo :rename)) + :signature_help (bufmap :n :gs (lspdo :signature_help)) + :goto_definition (bufmap :n :gd (lspdo :definition)) + :declaration (bufmap :n :gD (lspdo :declaration)) + :implementation (bufmap :n :gi (lspdo :implementation)) + :find_references (bufmap :n :gi (lspdo :references)) + :document_symbol (bufmap :n :gds (lspdo :workspace_symbol)) + :code_action (bufmap :n :ga (lspdo :code_action)) + :document_range_formatting (bufmap :v :gq + (lspdo :range_formatting)) + :hover (bufoption :keywordprg ":LspHover") + :documentFormattingProvider ((fn [] + (bufoption :formatexpr + "v:lua.vim.lsp.format()") + (bufmap :n :gq + #(vim.lsp.buf.format {:async true})))))) + + (each [cpb enabled? (pairs client.server_capabilities)] + (if enabled? + (use cpb)))) + +(fn attach [client buf] + (fn P [p] + (print (vim.inspect p)) + p) + + (-> {: client : buf} + (map-to-capabilities))) + +{: attach} diff --git a/neovim/fnl/conf/macros.fnl b/neovim/fnl/conf/macros.fnl index fe10ed3..80568b6 100644 --- a/neovim/fnl/conf/macros.fnl +++ b/neovim/fnl/conf/macros.fnl @@ -21,4 +21,8 @@ [a# "false"] (tset (. vim "opt") k# false) [a# b#] (tset (. vim "opt") k# v#))))) -{: settings} +(fn P [p] + `(print (vim.inspect ,p))) + +{: settings + : P} diff --git a/neovim/fnl/conf/pkgs.fnl b/neovim/fnl/conf/pkgs.fnl index 77b3e73..df59b09 100644 --- a/neovim/fnl/conf/pkgs.fnl +++ b/neovim/fnl/conf/pkgs.fnl @@ -1 +1,2 @@ (require :conf.pkgs.cmp) +(require :conf.pkgs.null-ls) diff --git a/neovim/fnl/conf/pkgs/cmp.fnl b/neovim/fnl/conf/pkgs/cmp.fnl index c31cb02..db3cbf9 100644 --- a/neovim/fnl/conf/pkgs/cmp.fnl +++ b/neovim/fnl/conf/pkgs/cmp.fnl @@ -1,18 +1,14 @@ (let [cmp (require :cmp) luasnip (require :luasnip) - snip (fn [args] (luasnip.lsp_expand (. args :body)))] - - (cmp.setup - {:snippet {:expand snip} - :completion {:autocomplete false} - :mapping - (cmp.mapping.preset.insert - {"" (cmp.mapping.scroll_docs -4) - "" (cmp.mapping.scroll_docs 4) - "" (cmp.mapping.complete) - "" (cmp.mapping.confirm {:select true})}) - :sources (cmp.config.sources - [{:name :conjure} - {:name :nvim_lsp} - {:name :path} - {:name :luasnip}])})) + snip (fn [args] + (luasnip.lsp_expand (. args :body)))] + (cmp.setup {:snippet {:expand snip} + :completion {:autocomplete false} + :mapping (cmp.mapping.preset.insert {: (cmp.mapping.scroll_docs -4) + : (cmp.mapping.scroll_docs 4) + : (cmp.mapping.complete) + : (cmp.mapping.confirm {:select true})}) + :sources (cmp.config.sources [{:name :conjure} + {:name :nvim_lsp} + {:name :path} + {:name :luasnip}])})) diff --git a/neovim/fnl/conf/pkgs/null-ls.fnl b/neovim/fnl/conf/pkgs/null-ls.fnl new file mode 100644 index 0000000..45a507d --- /dev/null +++ b/neovim/fnl/conf/pkgs/null-ls.fnl @@ -0,0 +1,17 @@ +(fn reload [mod] + (fn loaded? [mod] + (not= (. package.loaded mod) nil)) + + (fn unload [mod] + (tset package.loaded mod nil)) + + (if (loaded? mod) (unload mod)) + (require mod)) + +(let [null-ls (require :null-ls)] + (null-ls.setup {:update_on_insert false + :on_attach (. (reload :conf.lsp) :attach) + :sources [null-ls.builtins.formatting.black + null-ls.builtins.formatting.raco_fmt + null-ls.builtins.formatting.alejandra + null-ls.builtins.formatting.fnlfmt]})) -- cgit v1.2.3