summaryrefslogtreecommitdiff
path: root/fnl/plugins/lsp/lspconfig.fnl
blob: 0b6ad79c7ecba0e7a2e3d4d4621323bf35b3dcf4 (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
41
42
43
44
;; Setup of lsps.

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

(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 []
  (let [diagnostics (require :plugins.lsp.diagnostics)
        lspconfig (require :lspconfig)
        lspconfig-win (require :lspconfig.ui.windows)
        mason-lspconfig (require :mason-lspconfig)
        servers (require :plugins.lsp.servers)]
    (diagnostics.setup)
    (on-attach)
    (set lspconfig-win.default_options.border :single)
    (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 :BufReadPost
 :dependencies [:mason.nvim
                :williamboman/mason-lspconfig.nvim
                :b0o/SchemaStore.nvim
                :hrsh7th/cmp-nvim-lsp]
 :config (fn []
           (setup))}