From 4997c7028783edff438052a499ff750b4767128c Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Wed, 30 Nov 2022 23:29:58 -0800 Subject: [PATCH] Add untracked fnl/plugin file --- .gitignore | 4 +- fnl/plugin/cmp.fnl | 88 ++++++++++++++++++++++++++++++++++++++++++++ fnl/plugin/jdtls.fnl | 20 ++++++++++ fnl/plugin/lsp.fnl | 86 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 196 insertions(+), 2 deletions(-) create mode 100644 fnl/plugin/cmp.fnl create mode 100644 fnl/plugin/jdtls.fnl create mode 100644 fnl/plugin/lsp.fnl diff --git a/.gitignore b/.gitignore index 6886e99..7c562bb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -lua/ -plugin/ +/lua/ +/plugin/ diff --git a/fnl/plugin/cmp.fnl b/fnl/plugin/cmp.fnl new file mode 100644 index 0000000..7b2d349 --- /dev/null +++ b/fnl/plugin/cmp.fnl @@ -0,0 +1,88 @@ +;;; cmp.fnl - nvim-cmp config + +(import-macros {: module-call!} :macros) + +{ :configure #(let [cmp (require :cmp) + compare (require :cmp.config.compare)] + (cmp.setup + { :snippet { + :expand #(module-call! :snippy :expand_snippet $1.body) } + :mapping { + : (cmp.mapping (cmp.mapping.scroll_docs -4) + [ :i :c ]) + : (cmp.mapping (cmp.mapping.scroll_docs 4) + [ :i :c ]) + : (cmp.mapping (cmp.mapping.complete) + [ :i :c ]) + : (cmp.mapping (cmp.mapping.abort) + [ :i :c ]) + : (cmp.mapping + (cmp.mapping.confirm { :select false }) + [ :i :c ]) + : (cmp.mapping + (cmp.mapping.select_next_item + { :behavior cmp.SelectBehavior.Select }) + [ :i :c ]) + : (cmp.mapping + (cmp.mapping.select_prev_item + { :behavior cmp.SelectBehavior.Select }) + [ :i :c ]) + : (cmp.mapping + (cmp.mapping.select_next_item + { :behavior cmp.SelectBehavior.Select }) + [ :i :c ]) + : (cmp.mapping + (cmp.mapping.select_prev_item + { :behavior cmp.SelectBehavior.Select }) + [ :i :c ]) + : (cmp.mapping + (cmp.mapping.select_next_item + { :behavior cmp.SelectBehavior.Select }) + [ :i :c ]) + : (cmp.mapping + (cmp.mapping.select_prev_item + { :behavior cmp.SelectBehavior.Select }) + [ :i :c ]) } + :formatting { + :format (fn [entry vim_item] + (tset vim_item :menu + (. { :nvim_lsp "[LSP]" + :treesitter "[TS]" + :snippy "[Snippy]" + :buffer "[Buffer]" + :path "[Path]" } + entry.source.name)) + vim_item) + } + :sources (cmp.config.sources + [{ :name "nvim_lsp" :priority 2 } + { :name "snippy" :priority 1 } + { :name "buffer" :priority 0 } + { :name "path" :priority 0 }] + [{ :name "treesitter" :priority 2 } + { :name "snippy" :priority 1 } + { :name "buffer" :priority 0 } + { :name "path" :priority 0 }]) + :sorting { + :priority_weight 2 + :comparators [ + compare.score + compare.locality + compare.recently_used + compare.offset + compare.order + ; compare.scopes + ; compare.exact + ; compare.sort_text + ; compare.kind + ; compare.length + ]}}) + (cmp.setup.cmdline "/" + { :mapping (cmp.mapping.preset.cmdline) + :sources (cmp.config.sources + [{ :name "buffer" }])}) + (cmp.setup.cmdline ":" + { :mapping (cmp.mapping.preset.cmdline) + :sources (cmp.config.sources + [{ :name "cmdline" } + { :name "path" }])}))} diff --git a/fnl/plugin/jdtls.fnl b/fnl/plugin/jdtls.fnl new file mode 100644 index 0000000..52b3d49 --- /dev/null +++ b/fnl/plugin/jdtls.fnl @@ -0,0 +1,20 @@ +;;; jdtls.fnl - nvim-jdtls configuration + +(import-macros {: hook! : module-call! : module-fn!} :macros) + +(fn configure [] + (hook! :FileType :java + #(let [root_dir (module-call! :jdtls.setup :find_root + [ ".git" "mvnw" "gradlew" "build.gradle" ]) + lsp_cap (module-call! :cmp_nvim_lsp :default_capabilities)] + (module-call! :jdtls :start_or_attach + { :capabilities lsp_cap + :on_attach (module-fn! :plugin.lsp :on_attach) + :root_dir root_dir + :cmd [ "jdtls" + "-data" + (module-call! :plugin.lsp + :get_data_dir + :jdtls root_dir) ]})))) + +{: configure} diff --git a/fnl/plugin/lsp.fnl b/fnl/plugin/lsp.fnl new file mode 100644 index 0000000..a0e9c81 --- /dev/null +++ b/fnl/plugin/lsp.fnl @@ -0,0 +1,86 @@ +;;; lsp.fnl - lsp configurations + +(import-macros {: bind!} :macros) + +(fn on_attach [_ buf] + (bind! :n :gD vim.lsp.buf.declaration buf) + (bind! :n :gd vim.lsp.buf.definition buf) + (bind! :n :K vim.lsp.buf.hover buf) + (bind! :n :gI vim.lsp.buf.implementation buf) + (bind! :n : vim.lsp.buf.signature_help buf) + (bind! :n :wa vim.lsp.buf.add_workspace_folder buf) + (bind! :n :wr vim.lsp.buf.remove_workspace_folder buf) + (bind! :n :wl #(print (vim.inspect + (vim.lsp.buf.list_workspace_folders))) buf) + (bind! :n :D vim.lsp.buf.type_definition buf) + (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) + (bind! :n :o #(vim.lsp.buf.format { :async true }) buf) + + ;; Some telescope commands + (let [fzf (require :fzf-lua)] + (bind! :n :gr fzf.lsp_references buf) + (bind! :n :s fzf.lsp_live_workspace_symbols buf) + (bind! :n :fs fzf.lsp_live_workspace_symbols buf) + (bind! :n :fS fzf.lsp_workspace_symbols buf) + (bind! :n :d fzf.lsp_document_symbols buf) + (bind! :n :fd fzf.lsp_document_symbols buf) + (bind! :n :cn fzf.lsp_code_actions buf))) + +(fn get_data_dir [server root] + (let [resolved_path (vim.fn.resolve root) + joined_path (vim.fn.substitute resolved_path "\\/" "@" :g)] + (.. (vim.fn.fnamemodify (.. "~/.local/nvim/lsp-cache/" + server + "/") + ":p") joined_path))) + +(fn configure [] + (let [lsp (require :lspconfig) + configs (require :lspconfig.configs) + lsp_cap ((. (require :cmp_nvim_lsp) :default_capabilities))] + (macro setup_server! [name ...] + (let [opts { :on_attach `on_attach + :capabilities `lsp_cap }] + (var last_key nil) + (each [_ val (ipairs [...])] + (if last_key + (do (tset opts last_key val) + (set last_key nil)) + (set last_key val))) + `((. (. lsp ,name) :setup) ,opts))) + (setup_server! :ccls) + (setup_server! :cmake) + (setup_server! :gopls) + (setup_server! :rust_analyzer) + (setup_server! :texlab) + (setup_server! :sumneko_lua + :settings { + :Lua { + :runtime { + :version "LuaJIT" } + :diagnostics { + :globals [ "vim" ] } + :workspace { + :checkThirdParty false + :library (vim.api.nvim_get_runtime_file "" true) } + :telemetry { + :enable false }}}) + (tset configs :fennel_language_server { + :default_config { + :cmd [ "fennel-language-server" ] + :filetypes [ "fennel" ] + :single_file_support true + :root_dir (lsp.util.root_pattern "fnl") + :settings { + :fennel { + :workspace { + :library (vim.api.nvim_list_runtime_paths) } + :diagnostics { + :globals [ "vim" ] }}}}}) + ; needed to make it not complain about a nil setup function + (if configs.fennel_language_server.setup + (setup_server! :fennel_language_server)))) + +{ : configure : on_attach : get_data_dir }