summaryrefslogtreecommitdiff
path: root/fnl/config/lsp/lspconfig.fnl
blob: 74faa26306660761f72fa6848ac3e081dba2c630 (plain)
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
;; Setup of lsps.

(fn on-attach []
       (vim.api.nvim_create_autocmd :LspAttach
                                    {:callback (fn [args]
                                                 (let [keymaps (require :config.lsp.keymaps)
                                                       bufnr (. args :buf)]
                                                   (keymaps.on-attach bufnr)))}))

(fn capabilities []
       (let [cmp-lsp (require :cmp_nvim_lsp)]
         (cmp-lsp.default_capabilities (vim.lsp.protocol.make_client_capabilities))))

(fn mason-opts [servers]
       {:ensure_installed (vim.tbl_keys servers) :automatic_installation true})

(fn setup []
  (require :config.lsp.diagnostics)
  (let [lspconfig (require :lspconfig)
        mason-lspconfig (require :mason-lspconfig)
        servers (require :config.lsp.servers)]
    (on-attach)
    (mason-lspconfig.setup (mason-opts servers))
    (mason-lspconfig.setup_handlers [(fn [server-name]
                                       (let [server-config (. lspconfig
                                                              server-name)
                                             opts (or (. servers server-name)
                                                      {})]
                                         (tset opts :capabilities
                                               (capabilities))
                                         (server-config.setup opts)))])))

{1 :neovim/nvim-lspconfig
 :event :BufReadPre
 :dependencies [:mason.nvim
                :williamboman/mason-lspconfig.nvim
                :b0o/SchemaStore.nvim
                :hrsh7th/cmp-nvim-lsp]
 :config (fn []
           (setup))}