From 6a3c173766f981349483956294412cd0057c82e9 Mon Sep 17 00:00:00 2001 From: Oliver Davies <oliver@oliverdavies.uk> Date: Sun, 9 Jan 2022 22:10:30 +0000 Subject: [PATCH] refactor(nvim): use `fmta` for formatting --- .../lua/opdavies/snippets/javascript.lua | 6 +-- .../files/lua/opdavies/snippets/php.lua | 37 +++++++++++-------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/roles/neovim/files/lua/opdavies/snippets/javascript.lua b/roles/neovim/files/lua/opdavies/snippets/javascript.lua index 728923b..46dc178 100644 --- a/roles/neovim/files/lua/opdavies/snippets/javascript.lua +++ b/roles/neovim/files/lua/opdavies/snippets/javascript.lua @@ -1,9 +1,9 @@ local luasnip = require "luasnip" -local snippet = luasnip.s +local fmta = require("luasnip.extras.fmt").fmta local insert = luasnip.insert_node -local text = luasnip.text_node +local snippet = luasnip.snippet return { - snippet({ trig = "log", dscr = "console.log" }, { text "console.log(", insert(1, "value"), text ");" }), + snippet({ trig = "log", dscr = "console.log" }, fmta("console.log(<>);", { insert(1, "value") })), } diff --git a/roles/neovim/files/lua/opdavies/snippets/php.lua b/roles/neovim/files/lua/opdavies/snippets/php.lua index 32f48c0..5759cf5 100644 --- a/roles/neovim/files/lua/opdavies/snippets/php.lua +++ b/roles/neovim/files/lua/opdavies/snippets/php.lua @@ -1,23 +1,30 @@ local luasnip = require "luasnip" -local snippet = luasnip.s +local fmta = require("luasnip.extras.fmt").fmta local choice = luasnip.choice_node local insert = luasnip.insert_node +local snippet = luasnip.snippet 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 { "", "}" }, - }), + snippet( + "test", + fmta( + [[ + /** @test */ + public function <><>(): void { + <> + } + ]], + { + choice(1, { + text "test", + text "it", + text "should", + }), + insert(2), + insert(0), + } + ) + ), }