diff --git a/roles/neovim/files/after/plugin/luasnip.lua b/roles/neovim/files/after/plugin/luasnip.lua index a5442fa..169b32d 100644 --- a/roles/neovim/files/after/plugin/luasnip.lua +++ b/roles/neovim/files/after/plugin/luasnip.lua @@ -7,46 +7,18 @@ if vim.g.snippets ~= "luasnip" then return end --- Create a new snippet. -local s = luasnip.s +local javascript = require "opdavies.snippets.javascript" +local markdown = require "opdavies.snippets.markdown" +local php = require "opdavies.snippets.php" --- Different node types. -local c = luasnip.choice_node -local i = luasnip.insert_node -local t = luasnip.text_node - -local snippets = {} - --- Snippets for both JavaScript and TypeScript. -local js_ts = { - s({ trig = "log", dscr = "console.log" }, { t "console.log(", i(1, "value"), t ");" }), +local snippets = { + js = javascript, + markdown = markdown, + php = php, + typescript = javascript, + vue = javascript, } -snippets.js = js_ts - -snippets.markdown = { - s( - { trig = "frontmatter", dscr = "Document frontmatter" }, - { t { "---", "tags: " }, i(1, "value"), t { "", "---", "" }, i(0) } - ), -} - -snippets.php = { - s({ trig = "test", dscr = "Test block" }, { - t { "/* @test **/", "" }, - t "public function ", - c(1, { t "test", t "it", t "should" }), -- The test method name prefix. - i(2), -- The test method name. - t { "(): void {", "" }, - t " ", - i(0), -- The method body. - t { "", "}" }, - }), -} - -snippets.typescript = js_ts -snippets.vue = js_ts - luasnip.snippets = snippets vim.cmd [[ diff --git a/roles/neovim/files/lua/opdavies/snippets/javascript.lua b/roles/neovim/files/lua/opdavies/snippets/javascript.lua new file mode 100644 index 0000000..728923b --- /dev/null +++ b/roles/neovim/files/lua/opdavies/snippets/javascript.lua @@ -0,0 +1,9 @@ +local luasnip = require "luasnip" +local snippet = luasnip.s + +local insert = luasnip.insert_node +local text = luasnip.text_node + +return { + snippet({ trig = "log", dscr = "console.log" }, { text "console.log(", insert(1, "value"), text ");" }), +} diff --git a/roles/neovim/files/lua/opdavies/snippets/markdown.lua b/roles/neovim/files/lua/opdavies/snippets/markdown.lua new file mode 100644 index 0000000..5af4391 --- /dev/null +++ b/roles/neovim/files/lua/opdavies/snippets/markdown.lua @@ -0,0 +1,14 @@ +local luasnip = require "luasnip" +local snippet = luasnip.s + +local insert = luasnip.insert_node +local text = luasnip.text_node + +return { + snippet({ trig = "frontmatter", dscr = "Document frontmatter" }, { + text { "---", "tags: " }, + insert(1, "value"), + text { "", "---", "" }, + insert(0), + }), +} diff --git a/roles/neovim/files/lua/opdavies/snippets/php.lua b/roles/neovim/files/lua/opdavies/snippets/php.lua new file mode 100644 index 0000000..32f48c0 --- /dev/null +++ b/roles/neovim/files/lua/opdavies/snippets/php.lua @@ -0,0 +1,23 @@ +local luasnip = require "luasnip" +local snippet = luasnip.s + +local choice = luasnip.choice_node +local insert = luasnip.insert_node +local text = luasnip.text_node + +return { + snippet({ trig = "test", dscr = "Test block" }, { + text { "/* @test **/", "" }, + text "public function ", + choice(1, { + text "test", + text "it", + text "should", + }), + insert(2), -- The method name. + text { "(): void {", "" }, + text " ", + insert(0), -- The method body. + text { "", "}" }, + }), +}