Skip to content

Commit

Permalink
vsnip snippets and configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
gvolpe committed Apr 6, 2024
1 parent 0268c6a commit 7634fd5
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 22 deletions.
1 change: 1 addition & 0 deletions lib/ide.nix
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ let
enable = true;
type = "nerdcommenter";
};
snippets.vsnip.enable = true;
shortcuts = {
enable = true;
};
Expand Down
2 changes: 1 addition & 1 deletion modules/completion/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ in
if cmp.visible() then
cmp.select_prev_item()
elseif vim.fn['vsnip#available'](-1) == 1 then
feedkeys("<Plug>(vsnip-jump-prev)", "")
feedkey("<Plug>(vsnip-jump-prev)", "")
end
end, { 'i', 's' })
},
Expand Down
26 changes: 22 additions & 4 deletions modules/snippets/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
{ ... }:
{ pkgs, config, lib, ... }:

with lib;

let
cfg = config.vim.snippets.vsnip;
in
{
imports = [
./vsnip.nix
];
options.vim.snippets.vsnip = {
enable = mkEnableOption "Enable vim-vsnip";
dataDir = mkOption {
default = builtins.toPath ../../snippets;
description = "Directory for the snippet files";
type = types.str;
};
};

config = mkIf cfg.enable {
vim.startPlugins = with pkgs.neovimPlugins; [ vim-vsnip ];

vim.configRC = ''
let g:vsnip_snippet_dir = "${cfg.dataDir}"
'';
};
}
17 changes: 0 additions & 17 deletions modules/snippets/vsnip.nix

This file was deleted.

58 changes: 58 additions & 0 deletions snippets/global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"copyright": {
"prefix": "c)",
"body": [
"Copyright (c) ${CURRENT_YEAR} ${0:Author}. All Rights Reserved."
],
"description": "Snippet to put copyright"
},
"diso": {
"prefix": "diso",
"body": [
"${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}T${CURRENT_HOUR}:${CURRENT_MINUTE}:${CURRENT_SECOND}"
],
"description": "ISO date time stamp"
},
"date": {
"prefix": "date",
"body": ["${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}"],
"description": "Put the date in (Y-m-D) format"
},
"dateDMY": {
"prefix": "dateDMY",
"body": ["${CURRENT_DATE}/${CURRENT_MONTH}/${CURRENT_YEAR}"],
"description": "Put date in (DD/MM/YY) format"
},
"dateMDY": {
"prefix": "dateMDY",
"body": ["${CURRENT_MONTH}/${CURRENT_DATE}/${CURRENT_YEAR}"],
"description": "Put the date in (m/D/Y) format"
},
"time": {
"prefix": "time",
"body": ["${CURRENT_HOUR}:${CURRENT_MINUTE}"],
"description": "I give you back the time (H:M)"
},
"timeHMS": {
"prefix": "timeHMS",
"body": ["${CURRENT_HOUR}:${CURRENT_MINUTE}:${CURRENT_SECOND}"],
"description": "I give you back the time (H:M:S)"
},
"datetime": {
"prefix": "datetime",
"body": [
"${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE} ${CURRENT_HOUR}:${CURRENT_MINUTE}"
],
"description": "I give you back the time and date (Y-m-d H:M)"
},
"uuid": {
"prefix": "uuid",
"body": "${VIM:system('uuidgen')}",
"description": "A Version 4 UUID"
},
"Lorem Ipsum": {
"prefix": "lorem",
"body": "Lorem ipsum dolor sit amet, officia excepteur ex fugiat reprehenderit enim labore culpa sint ad nisi Lorem pariatur mollit ex esse exercitation amet. Nisi anim cupidatat excepteur officia. Reprehenderit nostrud nostrud ipsum Lorem est aliquip amet voluptate voluptate dolor minim nulla est proident. Nostrud officia pariatur ut officia. Sit irure elit esse ea nulla sunt ex occaecat reprehenderit commodo officia dolor Lorem duis laboris cupidatat officia voluptate. Culpa proident adipisicing id nulla nisi laboris ex in Lorem sunt duis officia eiusmod. Aliqua reprehenderit commodo ex non excepteur duis sunt velit enim. Voluptate laboris sint cupidatat ullamco ut ea consectetur et est culpa et culpa duis.",
"description": "Lorem Ipsum Paragraph"
}
}
114 changes: 114 additions & 0 deletions snippets/scala.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
{
"case_class": {
"prefix": "case_class",
"body": "case class ${1:CaseClassName}(${2:argName}: ${3:ArgType})",
"description": "Case class with single argument"
},
"case_class_2": {
"prefix": "case_class_2",
"body": [
"case class ${1:CaseClassName}(",
"\t${2:arg1Name}: ${3:Arg1Type},",
"\t${4:arg2Name}: ${5:Arg2Type},",
")"
],
"description": "Case class with two arguments"
},
"enum": {
"prefix": "enum",
"body": [
"enum ${1:Name}:",
"\tcase ${2:Foo}, ${3:Bar}"
],
"description": "Enumeration"
},
"algebra": {
"prefix": "algebra",
"body": [
"trait ${1:Algebra}[F[_]]:",
"\tdef ${2:methodName}: F[${3:returnType}]"
],
"description": "Abstract algebra encoding"
},
"typeclass": {
"prefix": "typeclass",
"body": [
"import cats.effect.Async",
"import cats.syntax.all.*",
"",
"trait ${1:TypeClass}[F[_]]:",
"\tdef ${2:methodName}: F[${3:returnType}]",
"",
"object ${1:TypeClass}:",
"\tdef apply[F[_]: ${1:TypeClass}]: ${1:TypeClass}[F] = summon",
"",
"\tgiven [F[_]: Async]: ${1:TypeClass}[F] with",
"\t\tdef ${2:methodName}: F[${3:returnType}] = ???"
],
"description": "Typeclass encoding"
},
"ioapp": {
"prefix": "app",
"body": [
"import cats.effect.*",
"",
"object ${1:Main} extends IOApp.Simple:",
"\t${2:def run: IO[Unit] =}",
"\t\t${3:IO.println(\"Hello, world!\")}"
],
"description": "Main object extending IOApp.Simple"
},
"def": {
"prefix": "def",
"body": [
"def ${1:methodName}(${2:argName}: ${3:ArgType}): ${4:ReturnType} =",
"\t${5:???}"
],
"description": "Method"
},
"def_short": {
"prefix": "def_short",
"body": "def ${1:methodName}(${2:argName}: ${3:ArgType}): ${4:ReturnType} = ${5:???}",
"description": "Method as one-liner"
},
"for-comprehension": {
"prefix": "forc",
"body": [
"for",
"\t${1:x} <- ${2:IO.pure(1)}",
"yield ${3:()}"
],
"description": "For-comprehension"
},
"ifelse": {
"prefix": "ifelse",
"body": [
"if ${1:condition} then",
"\t${2:\"Foo\"}",
"else",
"\t${3:\"Bar\"}"
],
"description": "Branch based on conditions using if/else"
},
"ifelse_short": {
"prefix": "ifelse_short",
"body": "if ${1:true} then ${2:123} else ${3:\"foo\"}",
"description": "Branch based on conditions using if/else"
},
"test_weaver": {
"prefix": "test_weaver",
"body": [
"import cats.effect.*",
"import weaver.SimpleIOSuite",
"",
"object ${1:SomeTest} extends SimpleIOSuite:",
"\toverride def sharedResource: Resource[IO, String] =",
"\t\tResource.pure(\"test\")",
"",
"\ttest(${2:\"test name\"}) { fixture =>",
"\t\tIO.pure(success)",
"\t}"
],
"description": "Weaver IO test"
}
}

0 comments on commit 7634fd5

Please sign in to comment.