From 4932d32cae9a2a63226b67e6678d459b773f1f8b Mon Sep 17 00:00:00 2001 From: aktersnurra Date: Sat, 23 Apr 2022 21:22:24 +0200 Subject: fix(lsp): error loading capabilities and format --- fnl/config/lsp/handlers.fnl | 116 ++++++++++++++++---------------- fnl/config/lsp/init.fnl | 3 +- fnl/config/lsp/lsp-installer.fnl | 15 +++-- fnl/config/lsp/settings/sumneko-lua.fnl | 26 ++++++- 4 files changed, 92 insertions(+), 68 deletions(-) (limited to 'fnl') diff --git a/fnl/config/lsp/handlers.fnl b/fnl/config/lsp/handlers.fnl index 1e3785b..a90db76 100644 --- a/fnl/config/lsp/handlers.fnl +++ b/fnl/config/lsp/handlers.fnl @@ -1,61 +1,63 @@ (module config.lsp.handlers {autoload {util util nvim aniseed.nvim}}) -(def- signs [{:name :DiagnosticSignError :text ""} - {:name :DiagnosticSignWarn :text ""} - {:name :DiagnosticSignHint :text ""} - {:name :DiagnosticSignInfo :text ""}]) - -(defn- apply-signs [] (each [_ sign (ipairs signs)] - (vim.fn.sign_define sign.name - {:texthl sign.name - :text sign.text - :numhl ""}))) - -(def- config {:virtual_text false - :signs {:active signs} - :update_in_insert true - :underline true - :severity_sort true - :float {:focusable false - :style :minimal - :border :rounded - :source :always - :header "" - :prefix ""}}) - -(defn setup [] (apply-signs) (vim.diagnostic.config config) - (set vim.lsp.handlers.textDocument/hover - (vim.lsp.with {:border :rounded})) - (set vim.lsp.handlers.textDocument/signatureHelp - (vim.lsp.with vim.lsp.handlers.signature_help {:border :rounded}))) +(def- signs + [{:name :DiagnosticSignError :text ""} + {:name :DiagnosticSignWarn :text ""} + {:name :DiagnosticSignHint :text ""} + {:name :DiagnosticSignInfo :text ""}]) + +(defn- apply-signs [] + (each [_ sign (ipairs signs)] + (vim.fn.sign_define sign.name + {:texthl sign.name + :text sign.text + :numhl ""}))) + +(def- config + {:virtual_text false + :signs {:active signs} + :update_in_insert true + :underline true + :severity_sort true + :float {:focusable false + :style :minimal + :border :rounded + :source :always + :header "" + :prefix ""}}) + +(defn setup [] + (apply-signs) + (vim.diagnostic.config config) + (set vim.lsp.handlers.textDocument/hover + (vim.lsp.with {:border :rounded})) + (set vim.lsp.handlers.textDocument/signatureHelp + (vim.lsp.with vim.lsp.handlers.signature_help {:border :rounded}))) (defn- lsp-keymaps [bufnr] - (let [opts {:noremap true :silent true}] - (nvim.buf_set_keymap bufnr :n :gD - "lua vim.lsp.buf.declaration()" opts) - (nvim.buf_set_keymap bufnr :n :gd - "lua vim.lsp.buf.definition()" opts) - (nvim.buf_set_keymap bufnr :n :K "lua vim.lsp.buf.hover()" - opts) - (nvim.buf_set_keymap bufnr :n :gI - "lua vim.lsp.buf.implementation()" opts) - (nvim.buf_set_keymap bufnr :n :gr - "lua vim.lsp.buf.references()" opts) - (nvim.buf_set_keymap bufnr :n :gl - "lua vim.diagnostic.open_float()" opts) - (nvim.buf_set_keymap bufnr :n :q - "lua vim.diagnostic.setloclist()" opts))) - -(defn on-attach [client bufnr] (if (= client.name :html) - (set client.resolved_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.load-plugin :cmp_nvim_lsp)] - (cmp-nvim-lsp.update_capabilities capabilities)) - capabilities)) - -(setup) + (let [opts {:noremap true :silent true}] + (nvim.buf_set_keymap bufnr :n :gD + "lua vim.lsp.buf.declaration()" opts) + (nvim.buf_set_keymap bufnr :n :gd + "lua vim.lsp.buf.definition()" opts) + (nvim.buf_set_keymap bufnr :n :K "lua vim.lsp.buf.hover()" + opts) + (nvim.buf_set_keymap bufnr :n :gI + "lua vim.lsp.buf.implementation()" opts) + (nvim.buf_set_keymap bufnr :n :gr + "lua vim.lsp.buf.references()" opts) + (nvim.buf_set_keymap bufnr :n :gl + "lua vim.diagnostic.open_float()" opts) + (nvim.buf_set_keymap bufnr :n :q + "lua vim.diagnostic.setloclist()" opts))) + +(defn on-attach [client bufnr] + (if (= client.name :html) + (set client.resolved_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.load-plugin :cmp_nvim_lsp)] + (cmp-nvim-lsp.update_capabilities capabilities)))) diff --git a/fnl/config/lsp/init.fnl b/fnl/config/lsp/init.fnl index c4a461d..38c1873 100644 --- a/fnl/config/lsp/init.fnl +++ b/fnl/config/lsp/init.fnl @@ -3,5 +3,6 @@ (let [_ (util.load-plugin :lspconfig)] (require :config.lsp.lsp-installer) - (require :config.lsp.handlers) + (let [handlers (require :config.lsp.handlers)] + (handlers.setup)) (require :config.lsp.null-ls)) diff --git a/fnl/config/lsp/lsp-installer.fnl b/fnl/config/lsp/lsp-installer.fnl index 358ba1c..4e46cfd 100644 --- a/fnl/config/lsp/lsp-installer.fnl +++ b/fnl/config/lsp/lsp-installer.fnl @@ -1,28 +1,29 @@ ;; LSP installer. (module config.lsp.lsp-installer {autoload {util util}}) -(defn- handler-opts [] (let [handlers (require :config.lsp.handlers)] - {:on_attach handlers.on-attach - :capabilities handlers.capabilities})) +(def 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)))) + (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)))) + (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)))) + (vim.tbl_deep_extend :force pyright.opts handler-opts))) (defn- get-server-opts [server] (match server.name "jsonls" (jsonls-opts) "pyright" (pyright-opts) "sumneko_lua" (sumneko-lua-opts) - _ (handler-opts))) + _ handler-opts)) (let [lsp-installer (util.load-plugin :nvim-lsp-installer)] (lsp-installer.on_server_ready (fn [server] diff --git a/fnl/config/lsp/settings/sumneko-lua.fnl b/fnl/config/lsp/settings/sumneko-lua.fnl index acc8df2..d40fe9b 100644 --- a/fnl/config/lsp/settings/sumneko-lua.fnl +++ b/fnl/config/lsp/settings/sumneko-lua.fnl @@ -2,8 +2,28 @@ (module config.lsp.settings.sumneko-lua) (def- workspace - {:library {(vim.fn.expand :$VIMRUNTIME/lua) true - (vim.fn.expand :$VIMRUNTIME/lua/vim/lsp) true}}) + {:library {(vim.fn.expand "$VIMRUNTIME/lua") true + (vim.fn.expand "$VIMRUNTIME/lua/vim/lsp") true}}) +(def- diagnostics + {:globals ["vim" + "map" + "filter" + "range" + "reduce" + "head" + "tail" + "nth" + "use" + "describe" + "it" + "dump"]}) -(def opts {:settings {:Lua {:diagnostics {:globals [ :vim ]} :workspace workspace}}}) +(def- runtime + {:version "LuaJIT" + :path (vim.split package.path ";")}) + +(def opts + {:settings {:Lua {:diagnostics diagnostics + :workspace workspace + :runtime runtime}}}) -- cgit v1.2.3-70-g09d2