2022-11-30 23:29:58 -08:00
|
|
|
;;; 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 :<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 :<leader>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 :<leader>s fzf.lsp_live_workspace_symbols buf)
|
|
|
|
(bind! :n :<leader>fs fzf.lsp_live_workspace_symbols buf)
|
|
|
|
(bind! :n :<leader>fS fzf.lsp_workspace_symbols buf)
|
|
|
|
(bind! :n :<leader>d fzf.lsp_document_symbols buf)
|
|
|
|
(bind! :n :<leader>fd fzf.lsp_document_symbols buf)
|
|
|
|
(bind! :n :<leader>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)
|
2022-12-02 00:12:15 -08:00
|
|
|
lsp_cap ((. (require :cmp_nvim_lsp) :default_capabilities))
|
|
|
|
lsp_utils (require :plugin.lsp)]
|
2022-11-30 23:29:58 -08:00
|
|
|
(macro setup_server! [name ...]
|
2022-12-02 00:12:15 -08:00
|
|
|
(let [opts { :on_attach `lsp_utils.on_attach
|
2022-11-30 23:29:58 -08:00
|
|
|
: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 }
|