From 5cc2e3d846c693e615af88ed7678422edadd3a04 Mon Sep 17 00:00:00 2001 From: Gustaf Rydholm Date: Wed, 27 Jul 2022 00:32:49 +0200 Subject: Replace lsp-installer with mason --- fnl/config/lsp/init.fnl | 3 +- fnl/config/lsp/lsp-installer.fnl | 62 -------------------------------------- fnl/config/lsp/mason-lspconfig.fnl | 56 ++++++++++++++++++++++++++++++++++ fnl/config/lsp/mason.fnl | 9 ++++++ fnl/config/which-key.fnl | 5 ++- fnl/plugins.fnl | 4 ++- 6 files changed, 72 insertions(+), 67 deletions(-) delete mode 100644 fnl/config/lsp/lsp-installer.fnl create mode 100644 fnl/config/lsp/mason-lspconfig.fnl create mode 100644 fnl/config/lsp/mason.fnl diff --git a/fnl/config/lsp/init.fnl b/fnl/config/lsp/init.fnl index c20b93c..6c7f823 100644 --- a/fnl/config/lsp/init.fnl +++ b/fnl/config/lsp/init.fnl @@ -1,7 +1,8 @@ ;; Loads the LSP functionality. (module config.lsp.init {autoload {: util}}) -(require :config.lsp.lsp-installer) +(require :config.lsp.mason) +(require :config.lsp.mason-lspconfig) (let [handlers (require :config.lsp.handlers)] (handlers.setup)) diff --git a/fnl/config/lsp/lsp-installer.fnl b/fnl/config/lsp/lsp-installer.fnl deleted file mode 100644 index 1ad0af7..0000000 --- a/fnl/config/lsp/lsp-installer.fnl +++ /dev/null @@ -1,62 +0,0 @@ -;; Loads default handlers and specific language settings. -(module config.lsp.lsp-installer {autoload {: util}}) - -(def- default-servers {:bashls true - :clangd true - :cssls true - :dockerls true - :html true - :hls true - :jsonls true - :pyright true - :rust_analyzer true - :terraformls true - :texlab true - :tflint true - :yamlls true - :taplo true - :zk true}) - -(defn- merge [default-servers installed-servers] - (let [servers default-servers] - (each [_ server (ipairs installed-servers)] - (if (not= (. servers server.name) true) - (tset servers server.name true))) - (icollect [k (pairs servers)] - k))) - -(defn- handler-opts [] - (let [handlers (require :config.lsp.handlers)] - {:on_attach handlers.on-attach :capabilities (handlers.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- pyright-opts [] - (let [pyright (require :config.lsp.settings.pyright)] - (vim.tbl_deep_extend :force pyright.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) - :pyright (pyright-opts) - :sumneko_lua (sumneko-lua-opts) - :rust_analyzer (rust-opts) - _ (handler-opts))) - -(let [lsp-installer (util.load-plugin :nvim-lsp-installer) - lspconfig (util.load-plugin :lspconfig)] - (let [servers (merge default-servers (lsp-installer.get_installed_servers))] - (lsp-installer.setup {:ensure_installed servers}) - (each [_ server (ipairs servers)] - (let [server-config (. lspconfig server)] - (server-config.setup (get-server-opts server)))))) diff --git a/fnl/config/lsp/mason-lspconfig.fnl b/fnl/config/lsp/mason-lspconfig.fnl new file mode 100644 index 0000000..704761d --- /dev/null +++ b/fnl/config/lsp/mason-lspconfig.fnl @@ -0,0 +1,56 @@ +;; TBD +(module config.lsp.mason-lspconfig {autoload {: util}}) + +(def- servers [:bashls + :clangd + :cssls + :dockerls + :html + :hls + :jsonls + :pyright + :rust_analyzer + :taplo + :terraformls + :texlab + :sumneko_lua + :tflint + :yamlls + :zk]) + +(defn- handler-opts [] + (let [handlers (require :config.lsp.handlers)] + {:on_attach handlers.on-attach :capabilities (handlers.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- pyright-opts [] + (let [pyright (require :config.lsp.settings.pyright)] + (vim.tbl_deep_extend :force pyright.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) + :pyright (pyright-opts) + :sumneko_lua (sumneko-lua-opts) + :rust_analyzer (rust-opts) + _ (handler-opts))) + +(def- opts {:ensure_installed servers :automatic_installation true}) + +(util.use-config :mason-lspconfig opts) + +(let [lspconfig (util.load-plugin :lspconfig)] + (each [_ server (ipairs servers)] + (let [server-config (. lspconfig server)] + (server-config.setup (get-server-opts server))))) diff --git a/fnl/config/lsp/mason.fnl b/fnl/config/lsp/mason.fnl new file mode 100644 index 0000000..66963cb --- /dev/null +++ b/fnl/config/lsp/mason.fnl @@ -0,0 +1,9 @@ +;; Mason manages external tooling, e.g. lsp, formatters, and linters. +(module config.lsp.mason {autoload {: util}}) + +(def- opts {:ui {:icons {:package_installed "✓" + :package_pending "➜" + :package_uninstalled "✗"}} + :max_concurrent_installers 10}) + +(util.use-config :mason opts) diff --git a/fnl/config/which-key.fnl b/fnl/config/which-key.fnl index 608c629..65997b3 100644 --- a/fnl/config/which-key.fnl +++ b/fnl/config/which-key.fnl @@ -81,9 +81,8 @@ "Workspace Diagnostics"] :f ["lua vim.lsp.buf.format { async = true }" :Format] :i [:LspInfo :Info] - :I [:LspInstallInfo "Installer Info"] - :j ["lua vim.lsp.diagnostic.goto_next()" "Next Diagnostic"] - :k ["lua vim.lsp.diagnostic.goto_prev()" "Prev Diagnostic"] + :j ["lua vim.lsp.diagnostic.goto_next({buffer=0})" "Next Diagnostic"] + :k ["lua vim.lsp.diagnostic.goto_prev({buffer=0})" "Prev Diagnostic"] :l ["lua vim.lsp.codelens.run()" "CodeLens Action"] :q ["lua vim.lsp.diagnostic.set_loclist()" :Quickfix] :r ["lua vim.lsp.buf.rename()" :Rename] diff --git a/fnl/plugins.fnl b/fnl/plugins.fnl index 3985c54..0e41dfb 100644 --- a/fnl/plugins.fnl +++ b/fnl/plugins.fnl @@ -14,7 +14,7 @@ :onsails/lspkind-nvim {} :hrsh7th/cmp-nvim-lsp {} :neovim/nvim-lspconfig {} - :williamboman/nvim-lsp-installer {} + ;; :williamboman/nvim-lsp-installer {} :tamago324/nlsp-settings.nvim {} :jose-elias-alvarez/null-ls.nvim {} :b0o/SchemaStore.nvim {} @@ -53,4 +53,6 @@ :stevearc/aerial.nvim {} :TimUntersberger/neogit {:requires :nvim-lua/plenary.nvim} :aktersnurra/minibar.nvim {} + :williamboman/mason.nvim {:branch :alpha} + :williamboman/mason-lspconfig.nvim {} :s1n7ax/nvim-window-picker {}} -- cgit v1.2.3-70-g09d2