summaryrefslogtreecommitdiff
path: root/dot_config/nvim/fnl/plugins/lsp.fnl
blob: 963c1b795cbc5952e52d98366709289e6027ffe1 (plain) (blame)
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
(import-macros {:mixed-table · : recc} :toast.macros)
(local {: assoc : map} (require :toast.core))
(local {: insert} (require :toast.table))
(local {: executable?} (require :toast.nvim))

(fn gopts [plist]
  {:clangd {}
   :clojure_lsp {:root_dir (plist :project.clj :deps.edn :bb.edn :build.boot :shadow-cljs.edn :.git)}
   :denols {:autostart false
            :root_dir (plist :deno.json :deno.jsonc)}
   :gopls {}
   :ltex {}
   :lua_ls {}
   :pyright {}
   :ruff {:cmd [:ruff :server :--preview]}
   :texlab {:filetypes [:tex :plaintex :bib :latex]}
   :tsserver {:autostart false
              :root_dir (plist :tsconfig.json :package.json)}
   :zls {}})

; default on-attach
(fn attach [c b]
  (let [lsp vim.lsp
        lbf lsp.buf
        ll  [;groups
             (· "" & :group :+lsp)
             (· :w & :group :+workspace)
             ; actions
             (· :D lbf.declaration     & :desc "goto declaration")
             (· :d lbf.definition      & :desc "goto definition")
             (· :k lbf.hover           & :desc "hover")
             (· :K lbf.signature_help  & :desc "signature help")
             (· :i lbf.implementation  & :desc "goto implementation")
             (· :t lbf.type_definition & :desc "goto type definition")
             (· :r lbf.rename          & :desc "rename")
             (· :c lbf.code_action     & :desc "code action")
             (· :R lbf.reference       & :desc "list references")]
        ll (map #(assoc $ 1 (.. :<localleader><localleader> (. $ 1))) ll)]
   (vim.api.nvim_buf_set_option b :omnifunc :v:lua.vim.lsp.omnifunc)
   (recc :which-key :add
         (· (insert ll
                    (· :<leader>F #(vim.lsp.buf.format {:async true}) &
                       :desc "run format")) &
            :buffer b))))

[(· :neovim/nvim-lspconfig &
    :config (fn [_ opts]
             (each [k v (pairs opts)]
              (let [s (. (require :lspconfig) k)
                    c (or v.cmd s.document_config.default_config.cmd)
                    att (or v.on_attach attach)]
                 (when (executable? (. c 1))
                  (s.setup (assoc v :on_attach att))))))
    :opts #(gopts (partial recc :lspconfig.util :root_pattern)))]