-
Hello, I wrote an auto-import code for missing imports. s(
{name = "React: useState", trig = "rehs"},
{
d(
0,
function()
vim.schedule(
function()
ls_auto_import.import(
{
{source = "react", default_modules = {}, modules = {"useState"}}
}
)
end
)
return sn(
1,
fmt(
[[
const [<>, use<>] = useState<<<>>>(<>);
]],
{
i(1),
f(ls_utils.capitalize_first_char, {1}),
i(2),
i(3)
},
fmtopt
)
)
end
)
}
) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi :) This is a bit cumbersome, and I think we should shift some stuff around s.t. lines can be added/removed in the I'll update here once I get to that :) |
Beta Was this translation helpful? Give feedback.
-
I made it to a plugin. |
Beta Was this translation helpful? Give feedback.
Hi :)
You'd have to store the cursor-position using an extmark, insert text (which will shift the extmark with the text) and then query the new position of the extmark, and set the cursor on top of it (and then delete the extmark to avoid clutter ;) )
This is a bit cumbersome, and I think we should shift some stuff around s.t. lines can be added/removed in the
resolveExpandParams
-callback as long as they're before/after the line with the trigger.I'll update here once I get to that :)