From 702183612a176f2ef24aefce6e0bcd31774d9edf Mon Sep 17 00:00:00 2001 From: Tristan Russell Date: Thu, 27 Nov 2025 20:30:41 -0500 Subject: [PATCH] feat: Added luasnip completions chore: Moved completion configuration to its own file --- after/plugin/cmp.lua | 72 ++++++++++++++++++++++++++++++++++++++++++++ after/plugin/lsp.lua | 29 ------------------ lua/truss/lazy.lua | 6 ++++ 3 files changed, 78 insertions(+), 29 deletions(-) create mode 100644 after/plugin/cmp.lua diff --git a/after/plugin/cmp.lua b/after/plugin/cmp.lua new file mode 100644 index 0000000..9235a5a --- /dev/null +++ b/after/plugin/cmp.lua @@ -0,0 +1,72 @@ +local cmp = require("cmp") + +cmp.setup({ + snippet = { + -- REQUIRED - you must specify a snippet engine + expand = function(args) + require('luasnip').lsp_expand(args.body) -- For `luasnip` users. + --vim.snippet.expand(args.body) -- For native neovim snippets (Neovim v0.10+) + end, + }, + window = { + -- completion = cmp.config.window.bordered(), + -- documentation = cmp.config.window.bordered(), + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.select_prev_item(cmp_select), + [''] = cmp.mapping.select_next_item(cmp_select), + [''] = cmp.mapping.confirm({ select = true }), + [''] = cmp.mapping.complete(), + }), + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'luasnip' }, -- For luasnip users. + { name = 'buffer' }, + { + name = 'path', + option = { + pathMappings = { + ['@'] = '${folder}/src', + -- ['/'] = '${folder}/src/public/', + -- ['~@'] = '${folder}/src', + -- ['/images'] = '${folder}/src/images', + -- ['/components'] = '${folder}/src/components', + }, + }, + }, + }), + completion = { + completeopt = 'menu,menuone,noinsert', + }, +}) + +-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore). +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', + option = { + ignore_cmds = { 'Man', '!' } + } + } + }) +}) + + -- Set up lspconfig. +local capabilities = require('cmp_nvim_lsp').default_capabilities() +-- Replace with each lsp server you've enabled. +--require('lspconfig')[''].setup { +-- capabilities = capabilities +--} diff --git a/after/plugin/lsp.lua b/after/plugin/lsp.lua index d185592..a83f222 100644 --- a/after/plugin/lsp.lua +++ b/after/plugin/lsp.lua @@ -1,34 +1,5 @@ require("mason").setup() -local cmp = require('cmp') -local cmp_select = {behavior = cmp.SelectBehavior.Select} -cmp.setup({ - snippet = { - expand = function(args) - require('luasnip').lsp_expand(args.body) - end, - }, - mapping = cmp.mapping.preset.insert({ - [''] = cmp.mapping.select_prev_item(cmp_select), - [''] = cmp.mapping.select_next_item(cmp_select), - [''] = cmp.mapping.confirm({ select = true }), - [''] = cmp.mapping.complete(), - }), - sources = cmp.config.sources( - { - { name = 'nvim_lsp' }, - { name = 'luasnip' } - }, - { - { name = 'buffer' }, - { name = 'path' }, - { name = 'cmdline' } - }), - completion = { - completeopt = 'menu,menuone,noinsert', - }, -}) - vim.lsp.enable("lua_ls") vim.lsp.config("lua_ls", { on_init = function(client) diff --git a/lua/truss/lazy.lua b/lua/truss/lazy.lua index 71fc91c..9c21b9f 100644 --- a/lua/truss/lazy.lua +++ b/lua/truss/lazy.lua @@ -37,6 +37,12 @@ require("lazy").setup({ { -- LSP Configuration tool 'neovim/nvim-lspconfig' }, + { -- Snippet engine? + "L3MON4D3/LuaSnip", + version = "v2.4", -- Replace by the latest released major (first number of latest release) + -- install jsregexp (optional!). + build = "make install_jsregexp" + }, { -- Code completion 'hrsh7th/nvim-cmp' },