summaryrefslogtreecommitdiff
path: root/fnl/config
diff options
context:
space:
mode:
authorGustaf Rydholm <gustaf.rydholm@gmail.com>2023-01-07 22:03:56 +0100
committerGustaf Rydholm <gustaf.rydholm@gmail.com>2023-01-07 22:03:56 +0100
commit3df8130947ad44ef97cc3e022bc2551f1fff7765 (patch)
tree96c4abab3fe814347378c4d5b7d7bf7a22b826ab /fnl/config
parentba42524c3dbe9e59d6621d3ce02fb5dbc39126ff (diff)
Refactor lsp
Diffstat (limited to 'fnl/config')
-rw-r--r--fnl/config/lsp/keymaps.fnl38
-rw-r--r--fnl/config/lsp/lspconfig.fnl68
-rw-r--r--fnl/config/lsp/mason-lspconfig.fnl8
-rw-r--r--fnl/config/lsp/mason-null-ls.fnl6
-rw-r--r--fnl/config/lsp/null-ls.fnl10
-rw-r--r--fnl/config/lsp/servers.fnl44
-rw-r--r--fnl/config/lsp/settings/jsonls.fnl10
-rw-r--r--fnl/config/lsp/settings/rust.fnl6
-rw-r--r--fnl/config/lsp/settings/sumneko-lua.fnl8
9 files changed, 83 insertions, 115 deletions
diff --git a/fnl/config/lsp/keymaps.fnl b/fnl/config/lsp/keymaps.fnl
index 56a84a3..c60dfa9 100644
--- a/fnl/config/lsp/keymaps.fnl
+++ b/fnl/config/lsp/keymaps.fnl
@@ -1,22 +1,22 @@
;; Key mappings for lsp.
(module config.lsp.keymaps {autoload {nvim aniseed.nvim}})
-(defn keymaps [bufnr] (let [opts {:noremap true :silent true}]
- (nvim.buf_set_keymap bufnr :n :gD
- "<cmd>lua vim.lsp.buf.declaration()<CR>"
- opts)
- (nvim.buf_set_keymap bufnr :n :gd
- "<cmd>lua vim.lsp.buf.definition()<CR>"
- opts)
- (nvim.buf_set_keymap bufnr :n :gI
- "<cmd>lua vim.lsp.buf.implementation()<CR>"
- opts)
- (nvim.buf_set_keymap bufnr :n :gr
- "<cmd>lua vim.lsp.buf.references()<CR>"
- opts)
- (nvim.buf_set_keymap bufnr :n :gl
- "<cmd>lua vim.diagnostic.open_float()<CR>"
- opts)
- (nvim.buf_set_keymap bufnr :n :gs
- "<cmd>lua vim.lsp.buf.signature_help()<CR>"
- opts)))
+(defn on-attach [bufnr] (let [opts {:noremap true :silent true}]
+ (nvim.buf_set_keymap bufnr :n :gD
+ "<cmd>lua vim.lsp.buf.declaration()<CR>"
+ opts)
+ (nvim.buf_set_keymap bufnr :n :gd
+ "<cmd>lua vim.lsp.buf.definition()<CR>"
+ opts)
+ (nvim.buf_set_keymap bufnr :n :gI
+ "<cmd>lua vim.lsp.buf.implementation()<CR>"
+ opts)
+ (nvim.buf_set_keymap bufnr :n :gr
+ "<cmd>lua vim.lsp.buf.references()<CR>"
+ opts)
+ (nvim.buf_set_keymap bufnr :n :gl
+ "<cmd>lua vim.diagnostic.open_float()<CR>"
+ opts)
+ (nvim.buf_set_keymap bufnr :n :gs
+ "<cmd>lua vim.lsp.buf.signature_help()<CR>"
+ opts)))
diff --git a/fnl/config/lsp/lspconfig.fnl b/fnl/config/lsp/lspconfig.fnl
index c9baba7..b7143ab 100644
--- a/fnl/config/lsp/lspconfig.fnl
+++ b/fnl/config/lsp/lspconfig.fnl
@@ -1,40 +1,30 @@
;; Setup of lsps.
-(module config.lsp.lspconfig {autoload {util config.util lsp config.lsp.keymaps}})
-
-(defn on-attach [client bufnr] (if (= client.name :html)
- (set client.server_capabilities.document_formatting
- false))
- (lsp.keymaps bufnr))
-
-(defn capabilities []
- (let [capabilities (vim.lsp.protocol.make_client_capabilities)]
- (set capabilities.textDocument.completion.completionItem.snippetSupport
- true)
- (let [cmp-nvim-lsp (util.prequire :cmp_nvim_lsp)]
- (cmp-nvim-lsp.default_capabilities capabilities))))
-
-(defn- handler-opts [] {:on_attach on-attach :capabilities (capabilities)})
-
-(defn- jsonls-opts []
- (let [jsonls-opts (require :config.lsp.settings.jsonls)]
- (vim.tbl_deep_extend :force jsonls-opts (handler-opts))))
-
-(defn- sumneko-lua-opts []
- (let [sumneko-lua (require :config.lsp.settings.sumneko-lua)]
- (vim.tbl_deep_extend :force sumneko-lua.opts (handler-opts))))
-
-(defn- rust-opts []
- (let [rust (require :config.lsp.settings.rust)]
- (vim.tbl_deep_extend :force rust.opts (handler-opts))))
-
-(defn- get-server-opts [server]
- (match server
- :jsonls (jsonls-opts)
- :sumneko_lua (sumneko-lua-opts)
- :rust_analyzer (rust-opts)
- _ (handler-opts)))
-
-(let [lspconfig (util.prequire :lspconfig) servers (require :config.lsp.servers)]
- (each [_ server (ipairs servers)]
- (let [server-config (. lspconfig server)]
- (server-config.setup (get-server-opts server)))))
+(module config.lsp.lspconfig
+ {autoload {nvim aniseed.nvim
+ util config.util
+ keymaps config.lsp.keymaps}})
+
+(defn- on-attach []
+ (nvim.create_autocmd :LspAttach
+ {:callback (fn [args]
+ (let [bufnr (. args :buf)]
+ (keymaps.on-attach bufnr)))}))
+
+(defn- capabilities []
+ (let [cmp-lsp (util.prequire :cmp_nvim_lsp)]
+ (cmp-lsp.default_capabilities (vim.lsp.protocol.make_client_capabilities))))
+
+(defn- mason-opts [servers]
+ {:ensure_installed (vim.tbl_keys servers) :automatic_installation true})
+
+(let [lspconfig (util.prequire :lspconfig)
+ mason-lspconfig (util.prequire :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)))]))
diff --git a/fnl/config/lsp/mason-lspconfig.fnl b/fnl/config/lsp/mason-lspconfig.fnl
deleted file mode 100644
index 5180549..0000000
--- a/fnl/config/lsp/mason-lspconfig.fnl
+++ /dev/null
@@ -1,8 +0,0 @@
-;; Automatic installation and updating of some lsps.
-(module config.lsp.mason-lspconfig {autoload {util config.util}})
-
-(def- servers (require :config.lsp.servers))
-
-(def- opts {:ensure_installed servers :automatic_installation true})
-
-(util.setup :mason-lspconfig opts)
diff --git a/fnl/config/lsp/mason-null-ls.fnl b/fnl/config/lsp/mason-null-ls.fnl
deleted file mode 100644
index 40eaab7..0000000
--- a/fnl/config/lsp/mason-null-ls.fnl
+++ /dev/null
@@ -1,6 +0,0 @@
-;; Automatic installation and updating lsp diagnostics etc..
-(module config.lsp.mason-null-ls {autoload {util config.util}})
-
-(def- opts {:ensure_installed nil :automatic_installation true :automatic_setup false})
-
-(util.setup :mason-null-ls opts)
diff --git a/fnl/config/lsp/null-ls.fnl b/fnl/config/lsp/null-ls.fnl
index 2df7a55..fd3a61d 100644
--- a/fnl/config/lsp/null-ls.fnl
+++ b/fnl/config/lsp/null-ls.fnl
@@ -1,7 +1,12 @@
;; Adds LSP diagnostics and formatting.
(module config.lsp.null-ls {autoload {util config.util}})
-(let [null-ls (util.prequire :null-ls)]
+(def- mason-opts {:ensure_installed nil
+ :automatic_installation true
+ :automatic_setup false})
+
+(let [null-ls (util.prequire :null-ls)
+ mason-null-ls (util.prequire :mason-null-ls)]
(let [formatting null-ls.builtins.formatting
diagnostics null-ls.builtins.diagnostics]
(null-ls.setup {:debug false
@@ -26,4 +31,5 @@
formatting.shfmt
formatting.sqlfluff
formatting.stylua
- formatting.terraform_fmt]})))
+ formatting.terraform_fmt]}))
+ (mason-null-ls.setup mason-opts))
diff --git a/fnl/config/lsp/servers.fnl b/fnl/config/lsp/servers.fnl
index 6a41f69..2403c1a 100644
--- a/fnl/config/lsp/servers.fnl
+++ b/fnl/config/lsp/servers.fnl
@@ -1,19 +1,29 @@
;; List of lsp that should be automatically installed and supported.
-[:bashls
- :clangd
- :cssls
- :dockerls
- :hls
- :html
- :jsonls
- :pyright
- :rust_analyzer
- :sqls
- :sumneko_lua
- :taplo
- :terraformls
- :texlab
- :tflint
- :yamlls
- :zk]
+{:bashls {}
+ :clangd {}
+ :cssls {}
+ :dockerls {}
+ :hls {}
+ :html {}
+ :jsonls {:init_options {:providerFormatter false}
+ :settings {:json {:schemas (let [schemastore (require :schemastore)]
+ (schemastore.json.schemas))}}
+ :setup {:commands {:Format [(fn []
+ (vim.lsp.buf.range_formatting [] [0 0]
+ [(vim.fn.line "$"
+ 0)]))]}}}
+ :pyright {}
+ :rust_analyzer {:settings {:rust-analyzer {:lens {:enable true}
+ :checkOnSave {:command :clippy}}}}
+ :sqls {}
+ :sumneko_lua {:settings {:Lua {:completion {:callSnippet :Replace}
+ :workspace {:checkThirdParty false}
+ :runtime {:version :LuaJIT
+ :path (vim.split package.path ";")}}}}
+ :taplo {}
+ :terraformls {}
+ :texlab {}
+ :tflint {}
+ :yamlls {}
+ :zk {}}
diff --git a/fnl/config/lsp/settings/jsonls.fnl b/fnl/config/lsp/settings/jsonls.fnl
deleted file mode 100644
index 55c6115..0000000
--- a/fnl/config/lsp/settings/jsonls.fnl
+++ /dev/null
@@ -1,10 +0,0 @@
-;; Json schema store catalog language server.
-(module config.lsp.settings.jsonls {autoload {util config.util}})
-
-(let [schemastore (util.prequire :schemastore)]
- {:init_options {:providerFormatter false}
- :settings {:json {:schemas (schemastore.json.schemas)}}
- :setup {:commands {:Format [(fn []
- (vim.lsp.buf.range_formatting [] [0 0]
- [(vim.fn.line "$"
- 0)]))]}}})
diff --git a/fnl/config/lsp/settings/rust.fnl b/fnl/config/lsp/settings/rust.fnl
deleted file mode 100644
index b7277a1..0000000
--- a/fnl/config/lsp/settings/rust.fnl
+++ /dev/null
@@ -1,6 +0,0 @@
-;; Configuration for rust langauage server.
-(module config.lsp.settings.rust)
-
-(def opts
- {:settings {:rust-analyzer {:lens {:enable true}
- :checkOnSave {:command :clippy}}}})
diff --git a/fnl/config/lsp/settings/sumneko-lua.fnl b/fnl/config/lsp/settings/sumneko-lua.fnl
deleted file mode 100644
index 83817f8..0000000
--- a/fnl/config/lsp/settings/sumneko-lua.fnl
+++ /dev/null
@@ -1,8 +0,0 @@
-;; Config for the sumneko-lua language server.
-(module config.lsp.settings.sumneko-lua)
-
-(def- runtime {:version :LuaJIT :path (vim.split package.path ";")})
-
-(def opts {:settings {:Lua {:completion {:callSnippet :Replace}
- :workspace {:checkThirdParty false}
- : runtime}}})