refactor(nvim): manage Neovim with Home Manager
This commit is contained in:
parent
83c43d07df
commit
5630466780
42 changed files with 5 additions and 0 deletions
10
config/neovim/lua/opdavies/snippets/ft/javascript.lua
Normal file
10
config/neovim/lua/opdavies/snippets/ft/javascript.lua
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
local fmta = require("luasnip.extras.fmt").fmta
|
||||
local ls = require "luasnip"
|
||||
|
||||
local i = ls.insert_node
|
||||
|
||||
local M = {
|
||||
log = fmta("console.log(<>);", { i(1, "value") }),
|
||||
}
|
||||
|
||||
return M
|
||||
27
config/neovim/lua/opdavies/snippets/ft/lua.lua
Normal file
27
config/neovim/lua/opdavies/snippets/ft/lua.lua
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
local ls = require "luasnip"
|
||||
|
||||
local fmt = require("luasnip.extras.fmt").fmt
|
||||
local rep = require("luasnip.extras").rep
|
||||
|
||||
local f, i = ls.function_node, ls.insert_node
|
||||
|
||||
return {
|
||||
pcall = fmt(
|
||||
[[
|
||||
local status_ok, {} = pcall(require, "{}")
|
||||
if not status_ok then
|
||||
return
|
||||
end
|
||||
]],
|
||||
{ i(1), rep(1) }
|
||||
),
|
||||
|
||||
req = fmt([[local {} = require "{}"]], {
|
||||
f(function(import_name)
|
||||
local parts = vim.split(import_name[1][1], ".", true)
|
||||
|
||||
return parts[#parts] or ""
|
||||
end, { 1 }),
|
||||
i(1),
|
||||
}),
|
||||
}
|
||||
18
config/neovim/lua/opdavies/snippets/ft/markdown.lua
Normal file
18
config/neovim/lua/opdavies/snippets/ft/markdown.lua
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
local fmt = require("luasnip.extras.fmt").fmt
|
||||
local ls = require "luasnip"
|
||||
|
||||
local i = ls.insert_node
|
||||
|
||||
local M = {
|
||||
frontmatter = fmt(
|
||||
[[
|
||||
---
|
||||
title: {}
|
||||
---
|
||||
{}
|
||||
]],
|
||||
{ i(1), i(0) }
|
||||
),
|
||||
}
|
||||
|
||||
return M
|
||||
87
config/neovim/lua/opdavies/snippets/ft/php.lua
Normal file
87
config/neovim/lua/opdavies/snippets/ft/php.lua
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
local fmta = require("luasnip.extras.fmt").fmta
|
||||
local ls = require "luasnip"
|
||||
|
||||
local c = ls.choice_node
|
||||
local f = ls.function_node
|
||||
local i = ls.insert_node
|
||||
local t = ls.text_node
|
||||
|
||||
local M = {
|
||||
|
||||
drupalclass = fmta(
|
||||
[[
|
||||
<<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace <>;
|
||||
|
||||
final class <> {
|
||||
|
||||
<>
|
||||
|
||||
}]],
|
||||
{
|
||||
f(function()
|
||||
local filepath = vim.fn.expand "%:h"
|
||||
local filepath_parts = vim.fn.split(filepath, "/")
|
||||
|
||||
if not vim.tbl_contains(filepath_parts, "src") then
|
||||
return ""
|
||||
end
|
||||
|
||||
local namespace_parts = { "Drupal" }
|
||||
|
||||
local is_test_file = vim.tbl_contains(filepath_parts, "tests")
|
||||
if is_test_file then
|
||||
table.insert(namespace_parts, "Tests")
|
||||
end
|
||||
|
||||
-- Find and add the module name.
|
||||
for k, v in ipairs(filepath_parts) do
|
||||
if v == "src" then
|
||||
if is_test_file then
|
||||
table.insert(namespace_parts, filepath_parts[k - 2])
|
||||
else
|
||||
table.insert(namespace_parts, filepath_parts[k - 1])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Add the rest of the namespace.
|
||||
local namespace = vim.split(filepath, "src/")
|
||||
local final_part = (namespace[2] or ""):gsub("/", "\\")
|
||||
table.insert(namespace_parts, final_part)
|
||||
|
||||
return table.concat(namespace_parts, "\\")
|
||||
end),
|
||||
f(function()
|
||||
return vim.fn.expand "%:t:r"
|
||||
end),
|
||||
i(0),
|
||||
}
|
||||
),
|
||||
|
||||
func = fmta("function <>(<>)<> {\n <>\n}<>", { i(1), i(2), i(3), i(4), i(0) }),
|
||||
|
||||
met = fmta(
|
||||
[[
|
||||
<> function <>(<>)<> {
|
||||
<>
|
||||
}<>
|
||||
]],
|
||||
{ c(1, { t "public", t "protected", t "private" }), i(2), i(3), i(4), i(5), i(0) }
|
||||
),
|
||||
|
||||
test = fmta(
|
||||
[[
|
||||
/** @test */
|
||||
public function <><>(): void {
|
||||
<>
|
||||
}<>
|
||||
]],
|
||||
{ c(1, { t "test", t "it", t "should" }), i(2), i(3), i(0) }
|
||||
),
|
||||
}
|
||||
|
||||
return M
|
||||
22
config/neovim/lua/opdavies/snippets/ft/rst.lua
Normal file
22
config/neovim/lua/opdavies/snippets/ft/rst.lua
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
local ls = require "luasnip"
|
||||
|
||||
local i = ls.insert_node
|
||||
local f = ls.function_node
|
||||
|
||||
local fill_line = function(char)
|
||||
return function()
|
||||
local row = vim.api.nvim_win_get_cursor(0)[1]
|
||||
local lines = vim.api.nvim_buf_get_lines(0, row - 2, row, false)
|
||||
return string.rep(char, #lines[1])
|
||||
end
|
||||
end
|
||||
|
||||
local M = {
|
||||
link = { ".. _", i(1), ":" },
|
||||
|
||||
head = f(fill_line "=", {}),
|
||||
sub = f(fill_line "-", {}),
|
||||
subsub = f(fill_line "^", {}),
|
||||
}
|
||||
|
||||
return M
|
||||
Loading…
Add table
Add a link
Reference in a new issue