123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- ;;; lsp.fnl - lsp configurations
- (import-macros {: bind! : setup!} :macros)
- (fn on-attach [client 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 :<C-k> vim.lsp.buf.signature_help buf)
- (bind! :n :<leader>wa vim.lsp.buf.add_workspace_folder buf)
- (bind! :n :<leader>wr vim.lsp.buf.remove_workspace_folder buf)
- (bind! :n :<leader>wl #(print (vim.inspect
- (vim.lsp.buf.list_workspace_folders))) buf)
- ; (bind! :n :<leader>D vim.lsp.buf.type_definition buf)
- (bind! :n :<leader>rn vim.lsp.buf.rename buf)
- (bind! :n :<leader>cn vim.lsp.buf.code_action buf)
- ; (bind! :n :gr vim.lsp.buf.references buf)
- (bind! [ :n :v ] :<leader>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 "")
- ;; Some telescope commands
- (bind! :n :<leader>s "<cmd>Telescope lsp_dynamic_workspace_symbols<cr>" buf)
- (bind! :n :<leader>fs "<cmd>Telescope lsp_dynamic_workspace_symbols<cr>" buf)
- (bind! :n :<leader>fS "<cmd>Telescope lsp_workspace_symbols<cr>" buf)
- ;(print (vim.inspect client.server_capabilities))
- (when client.server_capabilities.documentSymbolProvider
- (bind! :n :<leader>d "<cmd>Telescope lsp_document_symbols<cr>" buf)
- (bind! :n :<leader>fd "<cmd>Telescope lsp_document_symbols<cr>" buf))
- (bind! :n :gr "<cmd>Telescope lsp_references<cr>" buf)
- (bind! :n :gd "<cmd>Telescope lsp_definitions<cr>" buf)
- (bind! :n :gI "<cmd>Telescope lsp_implementations<cr>" buf)
- (bind! :n :D "<cmd>Telescope lsp_type_definitions<cr>" buf)
- (bind! :n :<leader>fq "<cmd>Telescope diagnostics<cr>" buf)
- ;; Some trouble commands
- (bind! :n :<leader>q (fn []
- (let [trouble (require :trouble)]
- (if (trouble.is_open)
- (trouble.close)
- true
- (trouble.open :document_diagnostics)))))
- (bind! :n :<leader>Q (fn []
- (let [trouble (require :trouble)]
- (if (trouble.is_open)
- (trouble.close)
- true
- (trouble.open :workspace_diagnostics))))))
- (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! :clangd
- :on_attach (fn [client buf]
- (lsp-utils.on-attach client buf)
- (bind! :n :go :<cmd>ClangdSwitchSourceHeader<cr> buf))
- :cmd [ "clangd"
- "--header-insertion-decorators=0"
- "--background-index"
- "--clang-tidy"
- "--completion-style=bundled"
- "--function-arg-placeholders"
- "--header-insertion=never"
- "--malloc-trim"
- "--pch-storage=memory"
- "--offset-encoding=utf-16" ])
- (setup-server! :cmake)
- (setup-server! :vala_ls)
- (setup-server! :gopls)
- (setup-server! :rust_analyzer)
- (setup-server! :texlab)
- (setup-server! :pylsp)
- (setup-server! :lua_ls
- :settings {
- :Lua {
- :runtime {
- :version "LuaJIT" }
- :diagnostics {
- :globals [ "vim" ] }
- :workspace {
- :checkThirdParty false
- :library (vim.api.nvim_get_runtime_file "" true) }
- :telemetry {
- :enable false }}})
- (setup-server! :fennel_language_server
- :settings {
- :fennel {
- :workspace {
- :library (vim.api.nvim_list_runtime_paths) }
- :diagnostics {
- :globals [ "vim" ] }}})))
- (fn setup-null-ls []
- (let [builtins (. (require :null-ls) :builtins)]
- (setup! :null-ls
- :on_attach (fn [client buf]
- (bind! [ :n :v ]
- :<leader>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.stylua
- (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 }
|