feat(vim): add csharp snippets

This add most of the snippets I used to have. It implements a custom
env_namespace for adding in the namespace of the file based on where it in the
file tree.
This commit is contained in:
Ade Attwood 2024-12-30 09:41:35 +00:00
parent 1a9492c0ef
commit bbdcd42b27
14 changed files with 108 additions and 1 deletions

View file

@ -66,7 +66,7 @@ local function parse_snippet_file(file_path)
end
local snippets = {}
local paths = vim.split(vim.fn.glob "~/.config/nvim/snippets/**/*.snippet", "\n")
local paths = vim.split(vim.fn.glob(vim.fn.stdpath("config") .. "/snippets/**/*.snippet"), "\n")
for paths_index = 1, #paths do
local file = paths[paths_index]
local snippet = parse_snippet_file(file)
@ -96,3 +96,12 @@ end
for filetype, snippets_to_add in pairs(snippets) do
ls.add_snippets(filetype, snippets_to_add)
end
ls.env_namespace("AA", {
vars= {
NAMESPACE = function ()
local file_path = vim.fn.fnamemodify(vim.fn.expand("%:h"), ":~:.")
return string.gsub(file_path, "[\\/]", ".");
end
}
})

View file

@ -0,0 +1,9 @@
# name: New class
# key: class
# contributor: Ade Attwood <code@adeattwood.co.uk>
# filetypes: cs
# --
${public} class $TM_FILENAME_BASE
{
$0
}

View file

@ -0,0 +1,6 @@
# name: Parameter doc block comment
# key: debugger
# contributor: Ade Attwood <code@adeattwood.co.uk>
# filetypes: cs
# --
System.Diagnostics.Debugger.Break();

View file

@ -0,0 +1,9 @@
# name: Parameter doc block comment
# key: enum
# contributor: Ade Attwood <code@adeattwood.co.uk>
# filetypes: cs
# --
${public} enum $TM_FILENAME_BASE
{
$0
}

View file

@ -0,0 +1,6 @@
# name: exception doc block comment
# key: <exception
# contributor: Ade Attwood <code@adeattwood.co.uk>
# filetypes: cs
# --
<exception cref="$1">$0</exception>

View file

@ -0,0 +1,10 @@
# name: New test case
# key: it
# contributor: Ade Attwood <code@adeattwood.co.uk>
# filetypes: cs
# --
[Fact]
public void ${1}()
{
$0
}

View file

@ -0,0 +1,6 @@
# name: Write text to the console
# key: log
# contributor: Ade Attwood <code@adeattwood.co.uk>
# filetypes: cs
# --
Console.WriteLine($0);

View file

@ -0,0 +1,6 @@
# name: Full boilerplare class for the current file
# key: namespace
# contributor: Ade Attwood <code@adeattwood.co.uk>
# filetypes: cs
# --
namespace ${AA_NAMESPACE};

View file

@ -0,0 +1,11 @@
# name: Full boilerplare class for the current file
# key: nclass
# contributor: Ade Attwood <code@adeattwood.co.uk>
# filetypes: cs
# --
namespace ${AA_NAMESPACE};
${public} class $TM_FILENAME_BASE
{
$0
}

View file

@ -0,0 +1,6 @@
# name: Parameter doc block comment
# key: <param
# contributor: Ade Attwood <code@adeattwood.co.uk>
# filetypes: cs
# --
<param name="${1:parameterName}">$0</param>"

View file

@ -0,0 +1,6 @@
# name: A public prop getter and setter
# key: prop
# contributor: Ade Attwood <code@adeattwood.co.uk>
# filetypes: cs
# --
public ${1:int} ${2:MyProperty} { get; set; }$0

View file

@ -0,0 +1,9 @@
# name: A public prop getter and setter
# key: pub
# contributor: Ade Attwood <code@adeattwood.co.uk>
# filetypes: cs
# --
public ${1:int} ${2:Name}($3)
{
$0
}

View file

@ -0,0 +1,6 @@
# name: Returns doc block comment
# key: <returns
# contributor: Ade Attwood <code@adeattwood.co.uk>
# filetypes: cs
# --
<returns>$0</returns>"

View file

@ -0,0 +1,8 @@
# name: Summary doc block comment
# key: ///
# contributor: Ade Attwood <code@adeattwood.co.uk>
# filetypes: cs
# --
/// <summary>
/// $0
/// </summary>