diff --git a/fnl/cmp-setup.fnl b/fnl/cmp-setup.fnl new file mode 100644 index 0000000..5939a06 --- /dev/null +++ b/fnl/cmp-setup.fnl @@ -0,0 +1,46 @@ +;; Autocompletion and Snippets with nvim-cmp and luasnip +(let + [cmp (require :cmp) + luasnip (require :luasnip) + vscode-snips (require :luasnip.loaders.from_vscode) + ] + (vscode-snips.lazy_load) + (luasnip.config.setup) + (cmp.setup + {:snippet {:expand #(luasnip $1)} + :mapping (cmp.mapping.preset.insert + {: (cmp.mapping.select_next_item) + : (cmp.mapping.select_prev_item) + : (cmp.mapping.scroll_docs -4) + : (cmp.mapping.scroll_docs 4) + : (cmp.mapping.complete) + : (cmp.mapping.confirm {:behavior cmp.ConfirmBehavior.Replace :select true}) + : (cmp.mapping (fn [fallback] + (if (cmp.visible) (cmp.select_prev_item) + (luasnip.expand_or_locally_jumpable) (luasnip.expand_or_jump) + (fallback))) [:i :s]) + : (cmp.mapping (fn [fallback] + (if (cmp.visible) (cmp.select_prev_item) + (luasnip.locally_jumpable -1) (luasnip.jump -1) + (fallback))) [:i :s])}) + :sources (cmp.config.sources + [{:name :nvim_lsp} + {:name :luasnip} + {:name :buffer} + ])}) + (cmp.setup.cmdline ["/" "?"] + {:mapping (cmp.mapping.preset.cmdline) + :sources + [{:name :buffer}] + }) + (cmp.setup.cmdline [":"] + {:mapping (cmp.mapping.preset.cmdline) + :sources (cmp.config.sources + [{:name :path} + {:name :cmdline}])}) + (cmp.setup.filetype [:gitcommit] + {:mapping (cmp.mapping.preset.cmdline) + :sources (cmp.config.sources + [{:name :git} + {:name :buffer}]) + })) diff --git a/fnl/init.fnl b/fnl/init.fnl index dfd32f5..239da39 100644 --- a/fnl/init.fnl +++ b/fnl/init.fnl @@ -1,3 +1,58 @@ -(require :lazy-setup) +;; Package Management via lazy.nvim +(let + [lazy (require :lazy) + lazypath (.. (vim.fn.stdpath "data") "/lazy/lazy.nvim") + ] + (if (not (vim.loop.fs_stat lazypath)) + (vim.fn.system + ["git" + "clone" + "--filter=blob:none" + "https://github.com/folke/lazy.nvim.git" + "--branch=stable" + lazypath])) + (vim.opt.rtp:prepend lazypath) + (lazy.setup + ["https://github.com/rktjmp/hotpot.nvim" + {:url "https://github.com/nvim-telescope/telescope.nvim" + :tag "0.1.2" + :dependencies ["nvim-lua/plenary.nvim"]} + {:url "https://github.com/nvim-telescope/telescope-fzf-native.nvim" + :build (.. "cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release" + " && cmake --build build --config Release" + " && cmake --install build --prefix build" )} + {:url "https://github.com/nvim-treesitter/nvim-treesitter" + :build ":TSUpdate"} + {:url "https://github.com/neovim/nvim-lspconfig" + :dependencies + ["https://github.com/williamboman/mason.nvim" + "williamboman/mason-lspconfig.nvim" + {:url "https://github.com/j-hui/fidget.nvim" + :tag "legacy" + :opts {}} + "folke/neodev.nvim" + ]} + {:url "https://github.com/hrsh7th/nvim-cmp" + :dependencies + ["https://github.com/hrsh7th/cmp-nvim-lsp" + "https://github.com/hrsh7th/cmp-buffer" + "https://github.com/hrsh7th/cmp-path" + "https://github.com/hrsh7th/cmp-cmdline" + "https://github.com/hrsh7th/cmp-cmdline" + ]} + {:url "https://github.com/L3MON4D3/LuaSnip" + :dependencies + [{:url "https://github.com/saadparwaiz1/cmp_luasnip"} + {:url "https://github.com/rafamadriz/friendly-snippets"} + ]} + ])) + +(let [telescope (require :telescope)] + (pcall (telescope.load_extension :fzf))) + +(require :treesitter-setup) +(require :mason-setup) +(require :cmp-setup) + (require :options) (require :custom-keys) diff --git a/fnl/lazy-setup.fnl b/fnl/lazy-setup.fnl deleted file mode 100644 index b3f535c..0000000 --- a/fnl/lazy-setup.fnl +++ /dev/null @@ -1,163 +0,0 @@ -;; Package Management via lazy.nvim -(let - [lazy (require :lazy) - lazypath (.. (vim.fn.stdpath "data") "/lazy/lazy.nvim") - ] - (if (not (vim.loop.fs_stat lazypath)) - (vim.fn.system - ["git" - "clone" - "--filter=blob:none" - "https://github.com/folke/lazy.nvim.git" - "--branch=stable" - lazypath])) - (vim.opt.rtp:prepend lazypath) - (lazy.setup - ["https://github.com/rktjmp/hotpot.nvim" - {:url "https://github.com/nvim-telescope/telescope.nvim" - :tag "0.1.2" - :dependencies ["nvim-lua/plenary.nvim"]} - {:url "https://github.com/nvim-telescope/telescope-fzf-native.nvim" - :build (.. "cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release" - " && cmake --build build --config Release" - " && cmake --install build --prefix build" )} - {:url "https://github.com/nvim-treesitter/nvim-treesitter" - :build ":TSUpdate"} - {:url "https://github.com/neovim/nvim-lspconfig" - :dependencies - ["https://github.com/williamboman/mason.nvim" - "williamboman/mason-lspconfig.nvim" - {:url "https://github.com/j-hui/fidget.nvim" - :tag "legacy" - :opts {}} - "folke/neodev.nvim" - ]} - {:url "https://github.com/hrsh7th/nvim-cmp" - :dependencies - ["https://github.com/hrsh7th/cmp-nvim-lsp" - "https://github.com/hrsh7th/cmp-buffer" - "https://github.com/hrsh7th/cmp-path" - "https://github.com/hrsh7th/cmp-cmdline" - "https://github.com/hrsh7th/cmp-cmdline" - ]} - {:url "https://github.com/L3MON4D3/LuaSnip" - :dependencies - [{:url "https://github.com/saadparwaiz1/cmp_luasnip"} - {:url "https://github.com/rafamadriz/friendly-snippets"} - ]} - ])) - -(let [telescope (require :telescope)] - (pcall (telescope.load_extension :fzf))) - -;; Syntax Highlighting via Treesitter -;; NOTE: if you add a language to treesitter for syntax highlighting or otherwise -;; consider also adding the LSP via Mason below... -(let - [treesitter (require :nvim-treesitter.configs)] - (treesitter.setup - {:ensure_installed [:c :lua :vim :vimdoc :query ; required - :fennel] ; add new languages here - :sync_install false - :auto_install false - :ignore_install [] ; could :ensure_installed :all, then ignore unwanted. - :highlight {:enable true} - :indent {:enable true}})) - -;; Language Server Protocols via Mason -(let - [neodev (require :neodev) - mason (require :mason) - mason-lspconfig (require :mason-lspconfig) - servers - {:lua_ls - {:filetypes [:lua] - :Lua - {:workspace {:checkThirdParty false} } - :telemetry {:enable false} - :diagnostics {:globals - [:vim - ]}} - :fennel_language_server - {:filetypes [:fennel] - :fennel - {:workspace {:library (vim.api.nvim_list_runtime_paths)} - :diagnostics {:globals - [:vim - ]}}} - :bashls {:filetypes [:bash]} - } - on_attach (fn [_ bufnr] - (let - [nmap #(vim.keymap.set :n $1 $2 {:buffer bufnr :desc (.. "LSP: " $3)}) - telescope (require :telescope.builtin) - ] - (nmap :gd vim.lsp.buf.definition "[G]o to [D]efiniton") - (nmap :gr telescope.lsp_references "[G]o to [R]eferences") - (nmap :gI vim.lsp.buf.implementation "[G]o to [I]mplementation") - (vim.api.nvim_buf_create_user_command bufnr "Format" - #(vim.lsp.buf.format) - "Format current buffer with LSP"))) - ] - (neodev.setup) - (mason.setup) - (mason-lspconfig.setup {:ensure_installed (vim.tbl_keys servers)}) - (mason-lspconfig.setup_handlers - [(fn [server_name] (let - [server (. (require :lspconfig) server_name) - cmp-nvim-lsp (require :cmp_nvim_lsp) - settings (. servers server_name) - ] - (server.setup - {:capabilities (cmp-nvim-lsp.default_capabilities (vim.lsp.protocol.make_client_capabilities)) - :on_attach on_attach - :settings settings - :filetypes (or settings.filetypes [])}))) - ])) - -;; Autocompletion and Snippets with nvim-cmp and luasnip -(let - [cmp (require :cmp) - luasnip (require :luasnip) - vscode-snips (require :luasnip.loaders.from_vscode) - ] - (vscode-snips.lazy_load) - (luasnip.config.setup) - (cmp.setup - {:snippet {:expand #(luasnip $1)} - :mapping (cmp.mapping.preset.insert - {: (cmp.mapping.select_next_item) - : (cmp.mapping.select_prev_item) - : (cmp.mapping.scroll_docs -4) - : (cmp.mapping.scroll_docs 4) - : (cmp.mapping.complete) - : (cmp.mapping.confirm {:behavior cmp.ConfirmBehavior.Replace :select true}) - : (cmp.mapping (fn [fallback] - (if (cmp.visible) (cmp.select_prev_item) - (luasnip.expand_or_locally_jumpable) (luasnip.expand_or_jump) - (fallback))) [:i :s]) - : (cmp.mapping (fn [fallback] - (if (cmp.visible) (cmp.select_prev_item) - (luasnip.locally_jumpable -1) (luasnip.jump -1) - (fallback))) [:i :s])}) - :sources (cmp.config.sources - [{:name :nvim_lsp} - {:name :luasnip} - {:name :buffer} - ])}) - (cmp.setup.cmdline ["/" "?"] - {:mapping (cmp.mapping.preset.cmdline) - :sources - [{:name :buffer}] - }) - (cmp.setup.cmdline [":"] - {:mapping (cmp.mapping.preset.cmdline) - :sources (cmp.config.sources - [{:name :path} - {:name :cmdline}])}) - (cmp.setup.filetype [:gitcommit] - {:mapping (cmp.mapping.preset.cmdline) - :sources (cmp.config.sources - [{:name :git} - {:name :buffer}]) - })) diff --git a/fnl/mason-setup.fnl b/fnl/mason-setup.fnl new file mode 100644 index 0000000..289989b --- /dev/null +++ b/fnl/mason-setup.fnl @@ -0,0 +1,51 @@ +;; Language Server Protocols via Mason +(let + [neodev (require :neodev) + mason (require :mason) + mason-lspconfig (require :mason-lspconfig) + servers + {:lua_ls + {:filetypes [:lua] + :Lua + {:workspace {:checkThirdParty false} } + :telemetry {:enable false} + :diagnostics {:globals + [:vim + ]}} + :fennel_language_server + {:filetypes [:fennel] + :fennel + {:workspace {:library (vim.api.nvim_list_runtime_paths)} + :diagnostics {:globals + [:vim + ]}}} + :bashls {:filetypes [:bash]} + } + on_attach (fn [_ bufnr] + (let + [nmap #(vim.keymap.set :n $1 $2 {:buffer bufnr :desc (.. "LSP: " $3)}) + telescope (require :telescope.builtin) + ] + (nmap :gd vim.lsp.buf.definition "[G]o to [D]efiniton") + (nmap :gr telescope.lsp_references "[G]o to [R]eferences") + (nmap :gI vim.lsp.buf.implementation "[G]o to [I]mplementation") + (vim.api.nvim_buf_create_user_command bufnr "Format" + #(vim.lsp.buf.format) + "Format current buffer with LSP"))) + ] + (neodev.setup) + (mason.setup) + (mason-lspconfig.setup {:ensure_installed (vim.tbl_keys servers)}) + (mason-lspconfig.setup_handlers + [(fn [server_name] (let + [server (. (require :lspconfig) server_name) + cmp-nvim-lsp (require :cmp_nvim_lsp) + settings (. servers server_name) + ] + (server.setup + {:capabilities (cmp-nvim-lsp.default_capabilities (vim.lsp.protocol.make_client_capabilities)) + :on_attach on_attach + :settings settings + :filetypes (or settings.filetypes [])}))) + ])) + diff --git a/fnl/treesitter-setup.fnl b/fnl/treesitter-setup.fnl new file mode 100644 index 0000000..77f2177 --- /dev/null +++ b/fnl/treesitter-setup.fnl @@ -0,0 +1,13 @@ +;; Syntax Highlighting via Treesitter +;; NOTE: if you add a language to treesitter for syntax highlighting or otherwise +;; consider also adding the LSP via Mason below... +(let + [treesitter (require :nvim-treesitter.configs)] + (treesitter.setup + {:ensure_installed [:c :lua :vim :vimdoc :query ; required + :fennel] ; add new languages here + :sync_install false + :auto_install false + :ignore_install [] ; could :ensure_installed :all, then ignore unwanted. + :highlight {:enable true} + :indent {:enable true}}))