From ce64d00f3eaa75b1ae915bc1a0d1b2d1f642c2e7 Mon Sep 17 00:00:00 2001 From: Fernando Araoz Date: Thu, 23 Jan 2025 22:58:22 -0500 Subject: [PATCH] feat(nvim): continue fennel rewrite pt.6? --- config/nvim/fnl/plugins/editor.fnl | 1 + config/nvim/fnl/plugins/lsp.fnl | 159 +++++++++++++++++++++++++++++ 2 files changed, 160 insertions(+) create mode 100644 config/nvim/fnl/plugins/lsp.fnl diff --git a/config/nvim/fnl/plugins/editor.fnl b/config/nvim/fnl/plugins/editor.fnl index 2468629..4a4ab5b 100644 --- a/config/nvim/fnl/plugins/editor.fnl +++ b/config/nvim/fnl/plugins/editor.fnl @@ -98,4 +98,5 @@ autocomplete comments mini + "tpope/vim-sleuth" ; Detect tabstop and shiftwidth automatically ] diff --git a/config/nvim/fnl/plugins/lsp.fnl b/config/nvim/fnl/plugins/lsp.fnl new file mode 100644 index 0000000..66cea74 --- /dev/null +++ b/config/nvim/fnl/plugins/lsp.fnl @@ -0,0 +1,159 @@ +(fn disable-formatting [client] + (set client.server_capabilities.documentFormattingProvider false) + (set client.server_capabilities.documentRangeFormattingProvider false)) + + +(local lazydev + {1 :folke/lazydev.nvim + :ft :lua + :opts {:library [{:path :luvit-meta/library :words ["vim%.uv"]}]}}) + +(local luvit-meta {1 "Bilal2453/luvit-meta" + :lazy true}) + +(local lspconfig {1 :neovim/nvim-lspconfig + :config (fn [] + ((. (require :lspconfig) :gleam :setup) {}) + ((. (require :lspconfig) :ts_ls :setup) {:on_attach (fn [client + bufnr] + (disable-formatting client))}) + ((. (require :lspconfig) :eslint :setup) {:on_attach (fn [client + bufnr] + (vim.api.nvim_create_autocmd :BufWritePre + {:buffer bufnr + :command :EslintFixAll}))}) + (vim.api.nvim_create_autocmd :LspAttach + {:callback (fn [event] + (fn map [keys + func + desc + mode] + (set-forcibly! mode + (or mode + :n)) + (vim.keymap.set mode + keys + func + {:buffer event.buf + :desc (.. "LSP: " + desc)})) + + (map :gd + (. (require :telescope.builtin) + :lsp_definitions) + "[G]oto [D]efinition") + (map :gr + (. (require :telescope.builtin) + :lsp_references) + "[G]oto [R]eferences") + (map :gI + (. (require :telescope.builtin) + :lsp_implementations) + "[G]oto [I]mplementation") + (map :D + (. (require :telescope.builtin) + :lsp_type_definitions) + "Type [D]efinition") + (map :ds + (. (require :telescope.builtin) + :lsp_document_symbols) + "[D]ocument [S]ymbols") + (map :ws + (. (require :telescope.builtin) + :lsp_dynamic_workspace_symbols) + "[W]orkspace [S]ymbols") + (map :rn + vim.lsp.buf.rename + "[R]e[n]ame") + (map :ca + vim.lsp.buf.code_action + "[C]ode [A]ction" + [:n + :x]) + (map :gD + vim.lsp.buf.declaration + "[G]oto [D]eclaration") + (local client + (vim.lsp.get_client_by_id event.data.client_id)) + (when (and client + (client.supports_method vim.lsp.protocol.Methods.textDocument_documentHighlight)) + (local highlight-augroup + (vim.api.nvim_create_augroup :kickstart-lsp-highlight + {:clear false})) + (vim.api.nvim_create_autocmd [:CursorHold + :CursorHoldI] + {:buffer event.buf + :callback vim.lsp.buf.document_highlight + :group highlight-augroup}) + (vim.api.nvim_create_autocmd [:CursorMoved + :CursorMovedI] + {:buffer event.buf + :callback vim.lsp.buf.clear_references + :group highlight-augroup}) + (vim.api.nvim_create_autocmd :LspDetach + {:callback (fn [event2] + (vim.lsp.buf.clear_references) + (vim.api.nvim_clear_autocmds {:buffer event2.buf + :group :kickstart-lsp-highlight})) + :group (vim.api.nvim_create_augroup :kickstart-lsp-detach + {:clear true})})) + (when (and client + (client.supports_method vim.lsp.protocol.Methods.textDocument_inlayHint)) + (map :th + (fn [] + (vim.lsp.inlay_hint.enable (not (vim.lsp.inlay_hint.is_enabled {:bufnr event.buf})))) + "[T]oggle Inlay [H]ints")) + (local opts + {:buffer event.buf}) + (vim.keymap.set :n + :gh + (fn [] + (vim.diagnostic.open_float)) + {:buffer event.buf + :desc "[h] Open floating diagnostic"})) + :group (vim.api.nvim_create_augroup :kickstart-lsp-attach + {:clear true})}) + (var capabilities + (vim.lsp.protocol.make_client_capabilities)) + (set capabilities + (vim.tbl_deep_extend :force capabilities + ((. (require :cmp_nvim_lsp) + :default_capabilities)))) + (local servers + {:astro {} + :clojure_lsp {} + :gopls {} + :lua_ls {:settings {:Lua {:completion {:callSnippet :Replace}}}} + :tailwindcss {} + :ts_ls {} + :zls {}}) + ((. (require :mason) :setup)) + (local ensure-installed + (vim.tbl_keys (or servers {}))) + (vim.list_extend ensure-installed [:stylua]) + ((. (require :mason-tool-installer) :setup) {:ensure_installed ensure-installed}) + ((. (require :mason-lspconfig) :setup) {:handlers [(fn [server-name] + (local server + (or (. servers + server-name) + {})) + (set server.capabilities + (vim.tbl_deep_extend :force + {} + capabilities + (or server.capabilities + {}))) + ((. (require :lspconfig) + server-name + :setup) server))]})) + :dependencies [{1 :williamboman/mason.nvim :config true} + :williamboman/mason-lspconfig.nvim + :WhoIsSethDaniel/mason-tool-installer.nvim + {1 :j-hui/fidget.nvim :opts {}} + :hrsh7th/cmp-nvim-lsp]}) + +[ + lazydev + luvit-meta + lspconfig + ]