Vscode Style Snippets #59
-
Been trying for two days to get some vscode style snippets working with cmp completion. Tried luasnip, vsnip, lots of things. Is there a preferred way to make it work with lsp-zero? I assume I am doing something utterly wrong at this point :-). lsp.setup_nvim_cmp({
preselect = 'none',
experimental = { native_menu = false, ghost_text = false },
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end,
},
completion = 'menu, meunone, noinsert, noselect',
formatting = {
format = lspkind.cmp_format({
mode = "symbol_text",
maxwidth = 50,
ellipsis_char = '...',
menu = ({
nvim_lsp = '(LSP)',
emoji = '(Emoji)',
path = '(Path)',
calc = '(Calc)',
cmp_tabnine = '(Tabnine)',
vsnip = '(Snippet)',
luasnip = '(Snippet)',
buffer = '(Buffer)',
tmux = '(TMUX)',
copilot = '(Copilot)',
treesitter = '(TreeSitter)',
})
}),
},
sources = {
{ name = 'treesitter' },
{ name = 'vsnip ' },
{ name = 'path' },
{ name = 'nvim_lsp', keyword_length = 3 },
{ name = 'buffer', keyword_length = 3 },
{ name = 'luasnip', keyword_length = 2 },
{ name = 'nvim_lua' },
{ name = 'spell' },
{ name = 'emoji' },
{ name = 'calc' },
},
window = {
completion = {
border = border('Function'),
winhighlight = "Normal:CmpPmenu,CursorLine:PmenuSel,Search:None",
},
documentation = {
border = border('Function')
}
}
}) is my current setup inside lsp-zero.lua. {
'VonHeikemen/lsp-zero.nvim',
requires = {
-- LSP Support --
{ 'neovim/nvim-lspconfig' },
{ 'williamboman/mason.nvim' },
{ 'williamboman/mason-lspconfig.nvim' },
-- Autocompletion --
{ 'hrsh7th/nvim-cmp' },
{ 'hrsh7th/cmp-buffer' },
{ 'hrsh7th/cmp-path' },
{ 'saadparwaiz1/cmp_luasnip' },
{ 'hrsh7th/cmp-nvim-lsp' },
{ 'hrsh7th/cmp-nvim-lua' },
{ 'ray-x/cmp-treesitter' },
{ 'hrsh7th/cmp-cmdline' },
{ 'saadparwaiz1/cmp_luasnip' },
{ 'hrsh7th/cmp-calc' },
{ 'f3fora/cmp-spell' },
{ 'hrsh7th/cmp-emoji' },
{'hrsh7th/vim-vsnip'},
{'hrsh7th/vim-vsnip-integ'},
-- Snippets --
{
'L3MON4D3/LuaSnip',
config = function()
require('plugins.support.luasnip').setup()
end
},
{ 'rafamadriz/friendly-snippets' },
-- Additional Servers --
{ 'simrat39/rust-tools.nvim' },
{ 'jose-elias-alvarez/typescript.nvim' },
},
config = function()
require('plugins.lsp.lsp-zero')
end,
},
with a luasnip config of local M = {}
local ls = require "luasnip"
local s = ls.snippet
local t = ls.text_node
local types = require "luasnip.util.types"
local function create_snippets()
ls.snippets = {
all = {
s("ttt", t "Testing Luasnip"),
},
lua = {
ls.parser.parse_snippet("lm", "local M = {}\n\nfunction M.setup()\n $1 \nend\n\nreturn M"),
-- s("lm", { t { "local M = {}", "", "function M.setup()", "" }, i(1, ""), t { "", "end", "", "return M" } }),
},
python = {},
}
end
function M.setup()
ls.config.set_config {
history = true,
updateevents = "TextChanged,TextChangedI",
enable_autosnippets = true,
ext_opts = {
[types.choiceNode] = {
active = {
virt_text = { { "<-", "Error" } },
},
},
},
}
require("luasnip/loaders/from_vscode").lazy_load({ paths = '../../../snippets/' })
require("luasnip.loaders.from_snipmate").lazy_load()
ls.filetype_extend("all", { "_" })
create_snippets()
end
return M Any nudge in the right direction would be immensely helpful. Really appreciate all of your hard work. It has gotten me able to use nvim as a daily driver. Just need my snippets back :D |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Got it figured out. {
"name": "quasar",
"version": "1.0.0",
"description": "Quasar Code Snippets",
"contributes": {
"snippets": [
{
"language": "javascript",
"path": "./quasar.json"
},
{
"language": "typescript",
"path": "./quasar.json"
},
{
"language": "vue",
"path": "./quasar.json"
},
{
"language": "css",
"path": "./quasar.json"
},
{
"language": "scss",
"path": "./quasar.json"
},
{
"language": "sass",
"path": "./quasar.json"
},
{
"language": "html",
"path": "./quasar.json"
},
{
"language": "vue-html",
"path": "./quasar.json"
}
]
}
}
Needed this, and require("luasnip.loaders.from_vscode").lazy_load { paths = { "./snippets/quasar" } } Can delete or mark answered :D |
Beta Was this translation helpful? Give feedback.
-
By the way If you really want customize nvim-cmp, I suggest you change the preset from local lsp = require('lsp-zero')
lsp.preset('lsp-compe')
lsp.setup()
vim.opt.completeopt = {'menu', 'menuone', 'noselect'}
local cmp = require('cmp')
local cmp_config = lsp.defaults.cmp_config({
---
-- Add your nvim-cmp config here
---
})
cmp.setup(cmp_config) |
Beta Was this translation helpful? Give feedback.
-
Once again, you save the day. Using this I was able to get it working exactly how I want, well this and the under the hood section. I really hope you and the other contributors of your caliber realize the help you give to us on our journey. One day I will repay the favor to those who come next. |
Beta Was this translation helpful? Give feedback.
Got it figured out.