This repository has been archived by the owner on Oct 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
lspconfig.fnl
99 lines (87 loc) · 4.73 KB
/
lspconfig.fnl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
(module config.plugin.lspconfig
{autoload {nvim aniseed.nvim
lsp lspconfig
cmplsp cmp_nvim_lsp}})
;lsp loading progress
(var progress-message {:status "" :percent 0 :msg ""})
(defn get-progress-message []
progress-message)
(defn progress-handler [_ msg info]
(when-let [client (vim.lsp.get_client_by_id info.client_id)]
(set progress-message.status msg.value.kind)
(when (not= msg.value.percentage nil)
(set progress-message.percent msg.value.percentage))
(if
(and (not= msg.value.message nil)
(and (not= msg.token nil)
(not= (type (tonumber msg.token)) "number")))
(set progress-message.msg (.. msg.token " : " msg.value.message))
(not= msg.value.message nil)
(set progress-message.msg msg.value.message)
(not= msg.token nil)
(set progress-message.msg msg.token))))
(defn setup-progress-handler []
(let [original-handler (. vim.lsp.handlers :$/progress)]
(tset vim.lsp.handlers :$/progress
(fn [...]
(let [args (vim.F.pack_len ...)]
(progress-handler (vim.F.unpack_len args))
(original-handler ...))))))
(setup-progress-handler)
;symbols to show for lsp diagnostics
(defn define-signs
[prefix]
(let [error (.. prefix "SignError")
warn (.. prefix "SignWarn")
info (.. prefix "SignInfo")
hint (.. prefix "SignHint")]
(vim.fn.sign_define error {:text "" :texthl error})
(vim.fn.sign_define warn {:text "" :texthl warn})
(vim.fn.sign_define info {:text "" :texthl info})
(vim.fn.sign_define hint {:text "" :texthl hint})))
(define-signs "Diagnostic")
;server features
(let [handlers {"textDocument/publishDiagnostics"
(vim.lsp.with
vim.lsp.diagnostic.on_publish_diagnostics
{:severity_sort true
:update_in_insert false
:underline true
:virtual_text false})
"textDocument/hover"
(vim.lsp.with
vim.lsp.handlers.hover
{:border "single"})
"textDocument/signatureHelp"
(vim.lsp.with
vim.lsp.handlers.signature_help
{:border "single"})}
capabilities (cmplsp.default_capabilities)
before_init (fn [params]
(set params.workDoneToken :1))
on_attach (fn [client bufnr]
(do
(nvim.buf_set_keymap bufnr :n :gd "<Cmd>lua vim.lsp.buf.definition()<CR>" {:noremap true})
(nvim.buf_set_keymap bufnr :n :K "<Cmd>lua vim.lsp.buf.hover()<CR>" {:noremap true})
(nvim.buf_set_keymap bufnr :n :<leader>ld "<Cmd>lua vim.lsp.buf.declaration()<CR>" {:noremap true})
(nvim.buf_set_keymap bufnr :n :<leader>lt "<cmd>lua vim.lsp.buf.type_definition()<CR>" {:noremap true})
(nvim.buf_set_keymap bufnr :n :<leader>lh "<cmd>lua vim.lsp.buf.signature_help()<CR>" {:noremap true})
(nvim.buf_set_keymap bufnr :n :<leader>ln "<cmd>lua vim.lsp.buf.rename()<CR>" {:noremap true})
(nvim.buf_set_keymap bufnr :n :<leader>le "<cmd>lua vim.diagnostic.open_float()<CR>" {:noremap true})
(nvim.buf_set_keymap bufnr :n :<leader>lq "<cmd>lua vim.diagnostic.setloclist()<CR>" {:noremap true})
(nvim.buf_set_keymap bufnr :n :<leader>lf "<cmd>lua vim.lsp.buf.format()<CR>" {:noremap true})
(nvim.buf_set_keymap bufnr :n :<leader>lj "<cmd>lua vim.diagnostic.goto_next()<CR>" {:noremap true})
(nvim.buf_set_keymap bufnr :n :<leader>lk "<cmd>lua vim.diagnostic.goto_prev()<CR>" {:noremap true})
(nvim.buf_set_keymap bufnr :n :<leader>la "<cmd>lua vim.lsp.buf.code_action()<CR>" {:noremap true})
(nvim.buf_set_keymap bufnr :v :<leader>la "<cmd>lua vim.lsp.buf.range_code_action()<CR> " {:noremap true})
;telescope
(nvim.buf_set_keymap bufnr :n :<leader>lw ":lua require('telescope.builtin').diagnostics()<cr>" {:noremap true})
(nvim.buf_set_keymap bufnr :n :<leader>lr ":lua require('telescope.builtin').lsp_references()<cr>" {:noremap true})
(nvim.buf_set_keymap bufnr :n :<leader>li ":lua require('telescope.builtin').lsp_implementations()<cr>" {:noremap true})))]
;; To add support to more language servers check:
;; https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
;; Clojure
(lsp.clojure_lsp.setup {:on_attach on_attach
:handlers handlers
:before_init before_init
:capabilities capabilities}))