(import-macros {: do-req } :lib/macros) (local lspkind (require :lspkind)) (local lspconfig (require :lspconfig)) (local lspsaga (require :lspsaga)) (local cmp (require :cmp)) (local nvim (require :lib/nvim)) ; (local lspfuzzy (require :lspfuzzy)) ; Not available on Nix ; (local sg (require :sg)) ; (local lsputil (require :lspconfig/util)) (lspsaga.setup {:border_style "rounded" :code_action_icon "" :code_action_num_shortcut true :code_action_lightbulb { :enable false} :show_outline { :enable false}}) (nvim.opt :winbar "%f") (local signs {:Error "îȘ‡ " :Warn " " :Hint " " :Info " "}) (each [t icon (pairs signs)] (let [hl (.. "DiagnosticSign" t)] (vim.fn.sign_define hl {:text icon :texthl hl :numhl hl}))) (tset vim.lsp.handlers :textDocument/hover (vim.lsp.with vim.lsp.handlers.hover {:focusable false :border "rounded"})) (tset vim.lsp.handlers :textDocument/signatureHelp (vim.lsp.with vim.lsp.handlers.signature_help {:focusable false :border "rounded"})) (local capabilities (let [cmp_nvim_lsp (require :cmp_nvim_lsp)] (cmp_nvim_lsp.default_capabilities))) (local formatting-augroup (nvim.augroup :LspFormatting)) (fn goimports [wait-ms] (let [params (vim.lsp.util.make_range_params) result (do (tset params :context {:only [:source.organizeImports]}) (vim.lsp.buf_request_sync 0 :textDocument/codeAction params wait-ms))] (each [_ res (pairs (or result {}))] (each [_ r (pairs (or res.result {}))] (if r.edit (vim.lsp.util.apply_workspace_edit r.edit "utf-16") (vim.lsp.buf.execute_command r.command)))) (vim.lsp.buf.format))) (fn on-attach [client bufnr] (let [filetype (vim.api.nvim_buf_get_option 0 "filetype")] (if (client.supports_method "textDocument/formatting") (do (nvim.autocmd "BufWritePre" {:group formatting-augroup :buffer bufnr :callback (fn [_] (if (= filetype "go") (goimports 2000) (vim.lsp.buf.format {:bufnr bufnr})))}))))) (lspconfig.gopls.setup {:capabilities capabilities :codelens {:generate true :gc_details true} :semanticTokens true :flags {:debounce_text_changes 200} :analyses {:unusedparams true :unusedvariables true :unusedwrite true :nilness true :unusedwrite true :useany true} :completeUnimported true :staticcheck true :experimentalPostfixCompletions true :hints {:constantValues true :functionTypeParameters true :assignVariablesTypes true :compositeLiteralTypes true :compositeLiteralFields true :parameterNames true :rangeVariableTypes true} :on_attach on-attach}) (local lsps [:nil_ls :terraform_lsp :fennel_ls :tsserver :starbin]) (each [index lsp (ipairs lsps)] ((. (. lspconfig lsp) :setup) {})) ; null-ls (let [null-ls (require :null-ls)] (null-ls.setup {:sources [; TODO fix these ;null-ls.builtins.diagnostics.shellcheck null-ls.builtins.diagnostics.commitlint]})) ;null-ls.builtins.diagnostics.jsonlint]})) ;(null-ls.builtins.diagnostics.proselint.with {:filetypes ["vimwiki" "mail"]})]}))