diff options
Diffstat (limited to 'fnl/plugins/lsp')
-rw-r--r-- | fnl/plugins/lsp/diagnostics.fnl | 33 | ||||
-rw-r--r-- | fnl/plugins/lsp/init.fnl | 5 | ||||
-rw-r--r-- | fnl/plugins/lsp/keymaps.fnl | 23 | ||||
-rw-r--r-- | fnl/plugins/lsp/lspconfig.fnl | 42 | ||||
-rw-r--r-- | fnl/plugins/lsp/mason.fnl | 11 | ||||
-rw-r--r-- | fnl/plugins/lsp/null-ls.fnl | 43 | ||||
-rw-r--r-- | fnl/plugins/lsp/servers.fnl | 29 |
7 files changed, 186 insertions, 0 deletions
diff --git a/fnl/plugins/lsp/diagnostics.fnl b/fnl/plugins/lsp/diagnostics.fnl new file mode 100644 index 0000000..1ac2e42 --- /dev/null +++ b/fnl/plugins/lsp/diagnostics.fnl @@ -0,0 +1,33 @@ +;; Handlers for the requests and responses from and to the lsp server. + +(local signs [{:name :DiagnosticSignError :text ""} + {:name :DiagnosticSignWarn :text ""} + {:name :DiagnosticSignHint :text ""} + {:name :DiagnosticSignInfo :text ""}]) + +(fn apply-signs [] + (each [_ sign (ipairs signs)] + (vim.fn.sign_define sign.name {:texthl sign.name :text sign.text :numhl ""}))) + +(local config {:virtual_text false + :signs {:active signs} + :update_in_insert false + :underline true + :severity_sort true + :float {:focusable false + :style :minimal + :border :rounded + :source :always + :header "" + :prefix ""}}) + +(fn setup [] + (apply-signs) + (vim.diagnostic.config config) + (set vim.lsp.handlers.textDocument/hover + (vim.lsp.with {:border :rounded :width 60})) + (set vim.lsp.handlers.textDocument/signatureHelp + (vim.lsp.with vim.lsp.handlers.signature_help + {:border :rounded :width 60}))) + +{: setup} diff --git a/fnl/plugins/lsp/init.fnl b/fnl/plugins/lsp/init.fnl new file mode 100644 index 0000000..bef4141 --- /dev/null +++ b/fnl/plugins/lsp/init.fnl @@ -0,0 +1,5 @@ +;; Lsp plugins. + +[(require :plugins.lsp.lspconfig) + (require :plugins.lsp.mason) + (require :plugins.lsp.null-ls)] diff --git a/fnl/plugins/lsp/keymaps.fnl b/fnl/plugins/lsp/keymaps.fnl new file mode 100644 index 0000000..a7fac89 --- /dev/null +++ b/fnl/plugins/lsp/keymaps.fnl @@ -0,0 +1,23 @@ +;; Key mappings for lsp. + +(fn on-attach [bufnr] (let [opts {:noremap true :silent true}] + (vim.api.nvim_buf_set_keymap bufnr :n :gD + "<cmd>lua vim.lsp.buf.declaration()<CR>" + opts) + (vim.api.nvim_buf_set_keymap bufnr :n :gd + "<cmd>lua vim.lsp.buf.definition()<CR>" + opts) + (vim.api.nvim_buf_set_keymap bufnr :n :gI + "<cmd>lua vim.lsp.buf.implementation()<CR>" + opts) + (vim.api.nvim_buf_set_keymap bufnr :n :gr + "<cmd>lua vim.lsp.buf.references()<CR>" + opts) + (vim.api.nvim_buf_set_keymap bufnr :n :gl + "<cmd>lua vim.diagnostic.open_float()<CR>" + opts) + (vim.api.nvim_buf_set_keymap bufnr :n :gs + "<cmd>lua vim.lsp.buf.signature_help()<CR>" + opts))) + +{: on-attach} diff --git a/fnl/plugins/lsp/lspconfig.fnl b/fnl/plugins/lsp/lspconfig.fnl new file mode 100644 index 0000000..b2ee792 --- /dev/null +++ b/fnl/plugins/lsp/lspconfig.fnl @@ -0,0 +1,42 @@ +;; Setup of lsps. + +(fn on-attach [] + (vim.api.nvim_create_autocmd :LspAttach + {:callback (fn [args] + (let [keymaps (require :plugins.lsp.keymaps) + bufnr (. args :buf)] + (keymaps.on-attach bufnr)))})) + +(fn capabilities [] + (let [cmp-lsp (require :cmp_nvim_lsp)] + (cmp-lsp.default_capabilities (vim.lsp.protocol.make_client_capabilities)))) + +(fn mason-opts [servers] + {:ensure_installed (vim.tbl_keys servers) :automatic_installation true}) + +(fn setup [] + + (let [diagnostics (require :plugins.lsp.diagnostics) + lspconfig (require :lspconfig) + mason-lspconfig (require :mason-lspconfig) + servers (require :plugins.lsp.servers)] + (diagnostics.setup) + (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)))]))) + +{1 :neovim/nvim-lspconfig + :event :BufReadPre + :dependencies [:mason.nvim + :williamboman/mason-lspconfig.nvim + :b0o/SchemaStore.nvim + :hrsh7th/cmp-nvim-lsp] + :config (fn [] + (setup))} diff --git a/fnl/plugins/lsp/mason.fnl b/fnl/plugins/lsp/mason.fnl new file mode 100644 index 0000000..bf57de5 --- /dev/null +++ b/fnl/plugins/lsp/mason.fnl @@ -0,0 +1,11 @@ +;; Mason manages external tooling, e.g. lsp, formatters, and linters. + +(local opts {:ui {:icons {:package_installed " " + :package_pending " " + :package_uninstalled " "}} + :max_concurrent_installers 10}) + +{1 :williamboman/mason.nvim + :cmd :Mason + :keys [{1 :<leader>m 2 :<cmd>Mason<cr> :desc :Mason}] + : opts} diff --git a/fnl/plugins/lsp/null-ls.fnl b/fnl/plugins/lsp/null-ls.fnl new file mode 100644 index 0000000..13dd493 --- /dev/null +++ b/fnl/plugins/lsp/null-ls.fnl @@ -0,0 +1,43 @@ +;; Adds LSP diagnostics and formatting. + +(local mason-opts {:ensure_installed nil + :automatic_installation true + :automatic_setup false}) + +(fn setup [] + (let [null-ls (require :null-ls) + mason-null-ls (require :mason-null-ls)] + (let [formatting null-ls.builtins.formatting + diagnostics null-ls.builtins.diagnostics] + (null-ls.setup {:debug false + :sources [diagnostics.codespell + diagnostics.cpplint + diagnostics.gitlint + diagnostics.hadolint + diagnostics.jsonlint + diagnostics.misspell + diagnostics.ruff + diagnostics.selene + diagnostics.shellcheck + diagnostics.sqlfluff + diagnostics.write_good + diagnostics.yamllint + formatting.fnlfmt + formatting.markdownlint + formatting.prettierd + formatting.ruff + formatting.rustfmt + formatting.shellharden + formatting.shfmt + formatting.sqlfluff + formatting.stylua + formatting.terraform_fmt]})) + (mason-null-ls.setup mason-opts))) + +{1 :jose-elias-alvarez/null-ls.nvim + :dependencies [:mason.nvim + :jayp0521/mason-null-ls.nvim + :nvim-lua/plenary.nvim] + :event :BufReadPre + :config (fn [] + (setup))} diff --git a/fnl/plugins/lsp/servers.fnl b/fnl/plugins/lsp/servers.fnl new file mode 100644 index 0000000..2403c1a --- /dev/null +++ b/fnl/plugins/lsp/servers.fnl @@ -0,0 +1,29 @@ +;; List of lsp that should be automatically installed and supported. + +{: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 {}} |