diff --git a/lib/ide.nix b/lib/ide.nix index 72d745d..6f43993 100644 --- a/lib/ide.nix +++ b/lib/ide.nix @@ -90,6 +90,7 @@ let enable = true; type = "nerdcommenter"; }; + snippets.vsnip.enable = true; shortcuts = { enable = true; }; diff --git a/modules/completion/default.nix b/modules/completion/default.nix index 3bf65a3..3c98735 100644 --- a/modules/completion/default.nix +++ b/modules/completion/default.nix @@ -79,7 +79,7 @@ in if cmp.visible() then cmp.select_prev_item() elseif vim.fn['vsnip#available'](-1) == 1 then - feedkeys("(vsnip-jump-prev)", "") + feedkey("(vsnip-jump-prev)", "") end end, { 'i', 's' }) }, diff --git a/modules/snippets/default.nix b/modules/snippets/default.nix index 3842661..8098856 100644 --- a/modules/snippets/default.nix +++ b/modules/snippets/default.nix @@ -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}" + ''; + }; } diff --git a/modules/snippets/vsnip.nix b/modules/snippets/vsnip.nix deleted file mode 100644 index 1b1b3e2..0000000 --- a/modules/snippets/vsnip.nix +++ /dev/null @@ -1,17 +0,0 @@ -{ pkgs, config, lib, ... }: - -with lib; -with builtins; - -let - cfg = config.vim.snippets.vsnip; -in -{ - options.vim.snippets.vsnip = { - enable = mkEnableOption "Enable vim-vsnip"; - }; - - config = mkIf cfg.enable { - vim.startPlugins = with pkgs.neovimPlugins; [ vim-vsnip ]; - }; -} diff --git a/snippets/global.json b/snippets/global.json new file mode 100644 index 0000000..7e97107 --- /dev/null +++ b/snippets/global.json @@ -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" + } +} diff --git a/snippets/scala.json b/snippets/scala.json new file mode 100644 index 0000000..7ccfa53 --- /dev/null +++ b/snippets/scala.json @@ -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" + } +}