add home manager configs
This commit is contained in:
83
radish/home/common/neovim/luasnippets/typescriptreact.lua
Normal file
83
radish/home/common/neovim/luasnippets/typescriptreact.lua
Normal file
@@ -0,0 +1,83 @@
|
||||
local ls = require("luasnip")
|
||||
local fmt = require("luasnip.extras.fmt").fmt
|
||||
local s = ls.snippet
|
||||
local sn = ls.snippet_node
|
||||
local i = ls.insert_node
|
||||
local f = ls.function_node
|
||||
local d = ls.dynamic_node
|
||||
|
||||
return {
|
||||
s(
|
||||
{ trig = "fc", desc = "React.FC" },
|
||||
fmt(
|
||||
[[
|
||||
import React from "react"
|
||||
|
||||
interface {props_name} {{
|
||||
{prop_types}
|
||||
}}
|
||||
|
||||
const {component_name}: React.FC<{props_name}> = ({props}) => {{
|
||||
return (
|
||||
{markup}
|
||||
)
|
||||
}}
|
||||
|
||||
export default {component_name}
|
||||
]],
|
||||
{
|
||||
props_name = i(3, "Props"),
|
||||
prop_types = i(2),
|
||||
component_name = d(1, function()
|
||||
local filename = vim.api.nvim_buf_get_name(0)
|
||||
local component_name
|
||||
|
||||
if filename == "index.tsx" then
|
||||
component_name = vim.fs.basename(vim.fs.dirname(filename))
|
||||
else
|
||||
component_name = vim.fs.basename(filename):match("(.+)%.tsx")
|
||||
end
|
||||
|
||||
return sn(nil, i(1, component_name))
|
||||
end),
|
||||
props = f(function(prop_types)
|
||||
local props = {}
|
||||
|
||||
for _, prop in ipairs(prop_types[1]) do
|
||||
local parts = vim.split(prop, ":", { plain = true, trimempty = true })
|
||||
local name = parts[1]
|
||||
if name then
|
||||
table.insert(props, vim.trim(name))
|
||||
end
|
||||
end
|
||||
|
||||
return "{ " .. table.concat(props, ", ") .. " }"
|
||||
end, { 2 }),
|
||||
markup = i(0),
|
||||
},
|
||||
{
|
||||
repeat_duplicates = true,
|
||||
}
|
||||
)
|
||||
),
|
||||
s(
|
||||
{ trig = "t", desc = "<tag>" },
|
||||
fmt(
|
||||
[[
|
||||
<{tag}>
|
||||
{children}
|
||||
</{closing_tag}>
|
||||
]],
|
||||
{
|
||||
tag = i(1, "div"),
|
||||
closing_tag = f(function(tag)
|
||||
return vim.split(tag[1][1], " ")[1]
|
||||
end, { 1 }),
|
||||
children = i(0),
|
||||
},
|
||||
{
|
||||
repeat_duplicates = true,
|
||||
}
|
||||
)
|
||||
),
|
||||
}
|
||||
Reference in New Issue
Block a user