;;; lsp.fnl - lsp configurations (import-macros {: bind!} :macros) (fn on-attach [_ buf] ((. (. (require :cmp) :setup) :buffer) { :sources [{ :name "nvim_lsp" :priority 1 :group 1 } { :name "snippy" :priority 1 :group 2 } { :name "buffer" :priority 0 :group 3 } { :name "path" :priority 0 :group 4 }]}) (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 fzf commands ;(bind! :n :gr "FzfLua lsp_references" buf) ;(bind! :n :s "FzfLua lsp_live_workspace_symbols" buf) ;(bind! :n :fs "FzfLua lsp_live_workspace_symbols" buf) ;(bind! :n :fS "FzfLua lsp_workspace_symbols" buf) ;(bind! :n :d "FzfLua lsp_document_symbols" buf) ;(bind! :n :fd "FzfLua lsp_document_symbols" buf) ;(bind! :n :cn "FzfLua lsp_code_actions" buf) ;; Some telescope commands (let [builtin (require :telescope.builtin)] (bind! :n :gr builtin.lsp_references buf) (bind! :n :s builtin.lsp_live_workspace_symbols buf) (bind! :n :fs builtin.lsp_live_workspace_symbols buf) (bind! :n :fS builtin.lsp_workspace_symbols buf) (bind! :n :d builtin.lsp_document_symbols buf) (bind! :n :fd builtin.lsp_document_symbols buf) (bind! :n :cn builtin.lsp_code_actions buf) (bind! :n :gd vim.lsp.buf.definition buf) (bind! :n :gI vim.lsp.buf.implementation 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)) lsp-utils (require :plugin.lsp)] (macro setup-server! [name ...] (let [opts { :on_attach `lsp-utils.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! :pylsp) (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 }