2022-11-30 23:29:58 -08:00
|
|
|
;;; lsp.fnl - lsp configurations
|
|
|
|
|
|
|
|
(import-macros {: bind!} :macros)
|
|
|
|
|
2023-02-07 20:16:58 -08:00
|
|
|
(fn on-attach [client buf]
|
2022-12-07 03:39:47 -08:00
|
|
|
((. (. (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 }]})
|
2022-11-30 23:29:58 -08:00
|
|
|
(bind! :n :gD vim.lsp.buf.declaration buf)
|
2023-02-07 20:16:58 -08:00
|
|
|
; (bind! :n :gd vim.lsp.buf.definition buf)
|
2022-11-30 23:29:58 -08:00
|
|
|
(bind! :n :K vim.lsp.buf.hover buf)
|
2023-02-07 20:16:58 -08:00
|
|
|
; (bind! :n :gI vim.lsp.buf.implementation buf)
|
2022-11-30 23:29:58 -08:00
|
|
|
(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)
|
2022-12-25 16:34:21 -08:00
|
|
|
(bind! :n :<leader>wl #(print (vim.inspect
|
2022-11-30 23:29:58 -08:00
|
|
|
(vim.lsp.buf.list_workspace_folders))) buf)
|
2023-02-07 20:16:58 -08:00
|
|
|
; (bind! :n :<leader>D vim.lsp.buf.type_definition buf)
|
2022-11-30 23:29:58 -08:00
|
|
|
(bind! :n :<leader>rn vim.lsp.buf.rename buf)
|
2023-02-07 12:16:21 -08:00
|
|
|
(bind! :n :<leader>cn vim.lsp.buf.code_action buf)
|
2022-11-30 23:29:58 -08:00
|
|
|
; (bind! :n :gr vim.lsp.buf.references buf)
|
2023-02-07 20:16:58 -08:00
|
|
|
;(when client.server_capabilities.documentFormattingProvider
|
|
|
|
; (bind! :n :<leader>o #(vim.lsp.buf.format { :async true }) buf))
|
2023-02-07 12:16:21 -08:00
|
|
|
|
|
|
|
;; Some telescope commands
|
2023-02-07 20:16:58 -08:00
|
|
|
(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)
|
2023-02-07 22:31:05 -08:00
|
|
|
(bind! :n :D "<cmd>Telescope lsp_type_definitions<cr>" buf)
|
|
|
|
|
|
|
|
;; Some trouble commands
|
2023-02-08 21:45:02 -08:00
|
|
|
(bind! :n :<leader>q "<cmd>TroubleToggle document_diagnostics<cr>")
|
|
|
|
(bind! :n :<leader>Q "<cmd>TroubleToggle workspace_diagnostics<cr>"))
|
2023-02-07 12:16:21 -08:00
|
|
|
|
2022-11-30 23:29:58 -08:00
|
|
|
|
2022-12-02 16:38:31 -08:00
|
|
|
(fn get-data-dir [server root]
|
2022-11-30 23:29:58 -08:00
|
|
|
(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 19:22:59 -08:00
|
|
|
lsp-cap ((. (require :cmp_nvim_lsp) :default_capabilities))
|
|
|
|
lsp-utils (require :plugin.lsp)]
|
|
|
|
(macro setup-server! [name ...]
|
2022-12-02 19:54:12 -08:00
|
|
|
(let [opts { :on_attach `lsp-utils.on-attach
|
2022-12-02 19:22:59 -08:00
|
|
|
:capabilities `lsp-cap }]
|
|
|
|
(var last-key nil)
|
2022-11-30 23:29:58 -08:00
|
|
|
(each [_ val (ipairs [...])]
|
2022-12-02 19:22:59 -08:00
|
|
|
(if last-key
|
|
|
|
(do (tset opts last-key val)
|
|
|
|
(set last-key nil))
|
|
|
|
(set last-key val)))
|
2022-11-30 23:29:58 -08:00
|
|
|
`((. (. lsp ,name) :setup) ,opts)))
|
2022-12-02 19:22:59 -08:00
|
|
|
(setup-server! :ccls)
|
|
|
|
(setup-server! :cmake)
|
|
|
|
(setup-server! :gopls)
|
|
|
|
(setup-server! :rust_analyzer)
|
|
|
|
(setup-server! :texlab)
|
2022-12-25 16:34:21 -08:00
|
|
|
(setup-server! :pylsp)
|
2023-02-12 14:20:27 -08:00
|
|
|
(setup-server! :lua_ls
|
2022-11-30 23:29:58 -08:00
|
|
|
: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
|
2022-12-02 19:22:59 -08:00
|
|
|
(setup-server! :fennel_language_server))))
|
2022-11-30 23:29:58 -08:00
|
|
|
|
2022-12-02 16:38:31 -08:00
|
|
|
{ : configure : on-attach : get-data-dir }
|