summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChloé Vulquin <code@toast.bunkerlabs.net>2024-08-06 14:11:59 +0200
committerChloé Vulquin <code@toast.bunkerlabs.net>2024-08-06 14:11:59 +0200
commit7425eda3e544fcb1ce81a09c5ff49d839e58ac94 (patch)
treee74368e016160f5c7aa5b532b46c9190e21fc32e
parentnvim: expand .lua gitattributes, mark as non-diffable (diff)
nvim: rework lsp module
There's still some improvements to be made, but this is cleaner. We lose global caps defaults, but those made no sense to begin with. We do also lose caps overrides, I'll add them back in if I need them. In the process, we gain `every?` and `executable?`. There's also a misc comp print vim.inspect to vim.print change.
-rw-r--r--dot_config/nvim/.chezmoiremove3
-rw-r--r--dot_config/nvim/fnl/plugins/lsp/attach.fnl4
-rw-r--r--dot_config/nvim/fnl/plugins/lsp/capabilities.fnl1
-rw-r--r--dot_config/nvim/fnl/plugins/lsp/init.fnl19
-rw-r--r--dot_config/nvim/fnl/toast/core.fnl8
-rw-r--r--dot_config/nvim/fnl/toast/nvim.fnl7
-rw-r--r--dot_config/nvim/lua/plugins/lsp/attach.lua8
-rw-r--r--dot_config/nvim/lua/plugins/lsp/capabilities.lua2
-rw-r--r--dot_config/nvim/lua/plugins/lsp/init.lua33
-rw-r--r--dot_config/nvim/lua/toast/core.lua10
-rw-r--r--dot_config/nvim/lua/toast/nvim.lua11
11 files changed, 64 insertions, 42 deletions
diff --git a/dot_config/nvim/.chezmoiremove b/dot_config/nvim/.chezmoiremove
index 7bd5db4..2aff3b4 100644
--- a/dot_config/nvim/.chezmoiremove
+++ b/dot_config/nvim/.chezmoiremove
@@ -3,3 +3,6 @@ lua/bindings/
fnl/plugins/bindings/
lua/plugins/bindings/
+
+fnl/plugins/lsp/capabilities.fnl
+lua/plugins/lsp/capabilities.lua
diff --git a/dot_config/nvim/fnl/plugins/lsp/attach.fnl b/dot_config/nvim/fnl/plugins/lsp/attach.fnl
index 83a68aa..ed2eb2d 100644
--- a/dot_config/nvim/fnl/plugins/lsp/attach.fnl
+++ b/dot_config/nvim/fnl/plugins/lsp/attach.fnl
@@ -20,8 +20,8 @@
(· :wa lbf.add_workspace_folder & :desc "add folder")
(· :wr lbf.remove_workspace_folder & :desc "remove folder")
- (· :wl #(print (vim.inspect (lbf.list_workspace_folders))) &
- :desc "list folders")]
+ (· :wl #(vim.print (lbf.list_workspace_folders))) &
+ :desc "list folders"]
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
diff --git a/dot_config/nvim/fnl/plugins/lsp/capabilities.fnl b/dot_config/nvim/fnl/plugins/lsp/capabilities.fnl
deleted file mode 100644
index 607602c..0000000
--- a/dot_config/nvim/fnl/plugins/lsp/capabilities.fnl
+++ /dev/null
@@ -1 +0,0 @@
-nil
diff --git a/dot_config/nvim/fnl/plugins/lsp/init.fnl b/dot_config/nvim/fnl/plugins/lsp/init.fnl
index 445eae1..0522c32 100644
--- a/dot_config/nvim/fnl/plugins/lsp/init.fnl
+++ b/dot_config/nvim/fnl/plugins/lsp/init.fnl
@@ -1,4 +1,6 @@
(import-macros {:mixed-table · : recc} :toast.macros)
+(local {: assoc} (require :toast.core))
+(local {: executable?} (require :toast.nvim))
(fn gopts [plist]
{:clangd {}
@@ -16,20 +18,13 @@
:zls {}})
(local attach (require :plugins.lsp.attach))
-(local caps (require :plugins.lsp.capabilities))
[(· :neovim/nvim-lspconfig &
:config (fn [_ opts]
(each [k v (pairs opts)]
- (set v.on_attach (or attach v.on_attach))
- (when (= :table (type caps))
- (set v.capabilities (or v.capabilities caps)))
(let [s (. (require :lspconfig) k)
- c (or v.cmd s.document_config.default_config.cmd)]
- (when (not= 0 (vim.fn.executable (. c 1)))
- (s.setup v)))))
- :opts (fn []
- (let [plist (fn [...]
- (local p (recc :lspconfig.util :root_pattern ...))
- #(p $))]
- (gopts plist))))]
+ c (or v.cmd s.document_config.default_config.cmd)
+ att (or attach v.on_attach)]
+ (when (executable? (. c 1))
+ (s.setup (assoc v :on_attach att))))))
+ :opts #(gopts (partial recc :lspconfig.util :root_pattern)))]
diff --git a/dot_config/nvim/fnl/toast/core.fnl b/dot_config/nvim/fnl/toast/core.fnl
index 2a426d1..82b0c40 100644
--- a/dot_config/nvim/fnl/toast/core.fnl
+++ b/dot_config/nvim/fnl/toast/core.fnl
@@ -19,6 +19,13 @@
"Returns true if the argument is a number."
(= :number (type n)))
+(fn every? [pred xs]
+ "Returns true if (pred x) is logical true for every x in xs, else false."
+ (accumulate [pass true
+ _ x (ipairs xs)
+ &until (not pass)]
+ (pred x)))
+
; sequences
(fn drop [n xs]
"Returns a table of all but the first n elements in xs."
@@ -81,6 +88,7 @@
: empty?
: nil?
: number?
+ : every?
; sequences
: drop
: first
diff --git a/dot_config/nvim/fnl/toast/nvim.fnl b/dot_config/nvim/fnl/toast/nvim.fnl
new file mode 100644
index 0000000..fddc0e7
--- /dev/null
+++ b/dot_config/nvim/fnl/toast/nvim.fnl
@@ -0,0 +1,7 @@
+(local {: every?} (require :toast.core))
+
+(fn executable? [& paths]
+ "Check if every argument specified is an executable that neovim can resolve."
+ (every? #(not= 0 (vim.fn.executable $)) paths))
+
+{: executable?}
diff --git a/dot_config/nvim/lua/plugins/lsp/attach.lua b/dot_config/nvim/lua/plugins/lsp/attach.lua
index 54f60f5..607bea7 100644
--- a/dot_config/nvim/lua/plugins/lsp/attach.lua
+++ b/dot_config/nvim/lua/plugins/lsp/attach.lua
@@ -9,18 +9,18 @@ local function _3_(c, b)
local lbf = lsp.buf
local ll
local function _4_()
- return print(vim.inspect(lbf.list_workspace_folders()))
+ return vim.print(lbf.list_workspace_folders())
end
- ll = {{"", group = "+lsp"}, {"w", group = "+workspace"}, {"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"}, {"wa", lbf.add_workspace_folder, desc = "add folder"}, {"wr", lbf.remove_workspace_folder, desc = "remove folder"}, {"wl", _4_, desc = "list folders"}}
+ ll = {{"", group = "+lsp"}, {"w", group = "+workspace"}, {"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"}, {"wa", lbf.add_workspace_folder, desc = "add folder"}, {"wr", lbf.remove_workspace_folder, desc = "remove folder"}, {"wl", _4_}, __fnl_global___26, "desc", "list folders"}
local ll0
local function _5_(_241)
- return assoc(_241, 1, ("<localleader><localleader>" .. (_241)[1]))
+ return assoc(_241, 1, ("<localleader><localleader>" .. _241[1]))
end
ll0 = map(_5_, ll)
vim.api.nvim_buf_set_option(b, "omnifunc", "v:lua.vim.lsp.omnifunc")
local function _6_()
return vim.lsp.buf.format({async = true})
end
- return (require("which-key")).add({insert(ll0, {"<leader>F", _6_, desc = "run format"}), buffer = b})
+ return require("which-key").add({insert(ll0, {"<leader>F", _6_, desc = "run format"}), buffer = b})
end
return _3_
diff --git a/dot_config/nvim/lua/plugins/lsp/capabilities.lua b/dot_config/nvim/lua/plugins/lsp/capabilities.lua
deleted file mode 100644
index 27ef5b2..0000000
--- a/dot_config/nvim/lua/plugins/lsp/capabilities.lua
+++ /dev/null
@@ -1,2 +0,0 @@
--- [nfnl] Compiled from fnl/plugins/lsp/capabilities.fnl by https://github.com/Olical/nfnl, do not edit.
-return nil
diff --git a/dot_config/nvim/lua/plugins/lsp/init.lua b/dot_config/nvim/lua/plugins/lsp/init.lua
index d26a949..2f05e41 100644
--- a/dot_config/nvim/lua/plugins/lsp/init.lua
+++ b/dot_config/nvim/lua/plugins/lsp/init.lua
@@ -1,35 +1,28 @@
-- [nfnl] Compiled from fnl/plugins/lsp/init.fnl by https://github.com/Olical/nfnl, do not edit.
+local _local_1_ = require("toast.core")
+local assoc = _local_1_["assoc"]
+local _local_2_ = require("toast.nvim")
+local executable_3f = _local_2_["executable?"]
local function gopts(plist)
return {clangd = {}, clojure_lsp = {root_dir = plist("project.clj", "deps.edn", "bb.edn", "build.boot", "shadow-cljs.edn", ".git")}, denols = {root_dir = plist("deno.json", "deno.jsonc"), autostart = false}, gopls = {}, ltex = {}, lua_ls = {}, pyright = {}, ruff = {cmd = {"ruff", "server", "--preview"}}, texlab = {filetypes = {"tex", "plaintex", "bib", "latex"}}, tsserver = {root_dir = plist("tsconfig.json", "package.json"), autostart = false}, zls = {}}
end
local attach = require("plugins.lsp.attach")
-local caps = require("plugins.lsp.capabilities")
-local function _1_(_, opts)
+local function _3_(_, opts)
for k, v in pairs(opts) do
- v.on_attach = (attach or v.on_attach)
- if ("table" == type(caps)) then
- v.capabilities = (v.capabilities or caps)
- else
- end
local s = require("lspconfig")[k]
local c = (v.cmd or s.document_config.default_config.cmd)
- if (0 ~= vim.fn.executable(c[1])) then
- s.setup(v)
+ local att = (attach or v.on_attach)
+ if executable_3f(c[1]) then
+ s.setup(assoc(v, "on_attach", att))
else
end
end
return nil
end
-local function _4_()
- local plist
- local function _5_(...)
- local p = require("lspconfig.util").root_pattern(...)
- local function _6_(_241)
- return p(_241)
- end
- return _6_
+local function _5_()
+ local function _6_(...)
+ return require("lspconfig.util").root_pattern(...)
end
- plist = _5_
- return gopts(plist)
+ return gopts(_6_)
end
-return {{"neovim/nvim-lspconfig", config = _1_, opts = _4_}}
+return {{"neovim/nvim-lspconfig", config = _3_, opts = _5_}}
diff --git a/dot_config/nvim/lua/toast/core.lua b/dot_config/nvim/lua/toast/core.lua
index b2a2e95..6daae14 100644
--- a/dot_config/nvim/lua/toast/core.lua
+++ b/dot_config/nvim/lua/toast/core.lua
@@ -17,6 +17,14 @@ end
local function number_3f(n)
return ("number" == type(n))
end
+local function every_3f(pred, xs)
+ local pass = true
+ for _, x in ipairs(xs) do
+ if not pass then break end
+ pass = pred(x)
+ end
+ return pass
+end
local function drop(n, xs)
local out = {}
for i, v in ipairs(xs) do
@@ -115,4 +123,4 @@ local function map(f, xs)
end
return out
end
-return {dec = dec, inc = inc, ["empty?"] = empty_3f, ["nil?"] = nil_3f, ["number?"] = number_3f, drop = drop, first = first, last = last, group = group, assoc = assoc, map = map}
+return {dec = dec, inc = inc, ["empty?"] = empty_3f, ["nil?"] = nil_3f, ["number?"] = number_3f, ["every?"] = every_3f, drop = drop, first = first, last = last, group = group, assoc = assoc, map = map}
diff --git a/dot_config/nvim/lua/toast/nvim.lua b/dot_config/nvim/lua/toast/nvim.lua
new file mode 100644
index 0000000..a46b92a
--- /dev/null
+++ b/dot_config/nvim/lua/toast/nvim.lua
@@ -0,0 +1,11 @@
+-- [nfnl] Compiled from fnl/toast/nvim.fnl by https://github.com/Olical/nfnl, do not edit.
+local _local_1_ = require("toast.core")
+local every_3f = _local_1_["every?"]
+local function executable_3f(...)
+ local paths = {...}
+ local function _2_(_241)
+ return (0 ~= vim.fn.executable(_241))
+ end
+ return every_3f(_2_, paths)
+end
+return {["executable?"] = executable_3f}