From c372e473d2a57f320eeab0043d848e233c2a42e8 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sun, 29 Sep 2024 21:56:55 +0200 Subject: [PATCH] added snippets for csharp --- init.lua | 17 +++-- snippets/cs.lua | 172 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 183 insertions(+), 6 deletions(-) create mode 100644 snippets/cs.lua diff --git a/init.lua b/init.lua index 13c80fda..a8962770 100644 --- a/init.lua +++ b/init.lua @@ -802,16 +802,21 @@ require('lazy').setup({ end return 'make install_jsregexp' end)(), + + config = function() + require('luasnip.loaders.from_lua').load { paths = { '~/.config/nvim/snippets/' } } + end, dependencies = { + -- `friendly-snippets` contains a variety of premade snippets. -- See the README about individual language/framework/plugin snippets: -- https://github.com/rafamadriz/friendly-snippets - -- { - -- 'rafamadriz/friendly-snippets', - -- config = function() - -- require('luasnip.loaders.from_vscode').lazy_load() - -- end, - -- }, + --{ + -- 'rafamadriz/friendly-snippets', + -- config = function() + -- require('luasnip.loaders.from_vscode').lazy_load() + -- end, + --}, }, }, 'saadparwaiz1/cmp_luasnip', diff --git a/snippets/cs.lua b/snippets/cs.lua new file mode 100644 index 00000000..ca68e3bc --- /dev/null +++ b/snippets/cs.lua @@ -0,0 +1,172 @@ +local ls = require 'luasnip' +local s = ls.snippet +local t = ls.text_node +local i = ls.insert_node +local f = ls.function_node +local c = ls.choice_node +local d = ls.dynamic_node +local r = ls.restore_node +local fmt = require('luasnip.extras.fmt').fmt + +return { + + s( + 'cww', + fmt('Console.WriteLine({});{}', { + i(1, ''), + i(0), + }) + ), + + s( + 'cw', + fmt('Console.Write({});{}', { + i(1, ''), + i(0), + }) + ), + + s( + 'do', + fmt( + [[ +do +{{ +{}}} while ({}); +{}]], + { + i(2), + i(1), + i(0), + } + ) + ), + + s( + 'while', + fmt( + [[ +while ({}) +{{ +{}}} +{}]], + { + i(1), + i(2), + i(0), + } + ) + ), + + s( + 'fo', + fmt( + [[ +for (int {} = 0; {} < {}; {}++) +{{ +{}}} +{}]], + { + i(2, 'i'), + f(function(args) + return args[1][1] + end, { 2 }), + i(1, '1'), + f(function(args) + return args[1][1] + end, { 2 }), + i(3), + i(0), + } + ) + ), + + s( + 'forr', + fmt( + [[ +for (int {} = {} - 1; {} >= 0; {}--) +{{ +{}}} +{}]], + { + i(2, 'i'), + i(1, 'length'), + f(function(args) + return args[1][1] + end, { 2 }), + f(function(args) + return args[1][1] + end, { 2 }), + i(3), + i(0), + } + ) + ), + + s('cc', t 'Console.Clear();'), + + s('crk', t 'Console.ReadKey(true);'), + + s('crl', t 'Console.ReadLine();'), + + s( + 'foreach', + fmt( + [[ +foreach ({}) +{{ +{}}}{}]], + { + i(1), + i(2), + i(0), + } + ) + ), + + s( + 'cla', + fmt( + [[ +class {} +{{ +{}}} + ]], + { + i(1, 'ClassName'), + i(0), + } + ) + ), + + s( + 'inter', + fmt( + [[ +interface {} +{{ +{}}} + ]], + { + i(1, 'IInterfaceName'), + i(0), + } + ) + ), + + s( + 'enu', + fmt( + [[ +enum {} +{{ +{}}} + ]], + { + i(1, 'EnumName'), + i(0), + } + ) + ), +}