smjonas / snippet-converter.nvim

Bundle snippets from multiple sources and convert them to your format of choice.
Mozilla Public License 2.0
170 stars 4 forks source link

SnipMate -> vsnip: support conversion of Vimscript code #20

Open flotisable opened 1 year ago

flotisable commented 1 year ago

With latest converter, some snippets become empty when converting from Snipmate to vim-vsnip. Below is an example:

version 1

snippet class "Moose class"
    package ${1:`Filename( '', '<package name>')`};

    use Moose;

    ${0:${VISUAL}}

    no Moose;
    1;

Putting this snippet to a file and perform the conversion, the converted vim-vsnip snippets will be

{}
smjonas commented 1 year ago

In the UI, you can see the reason why this is currently not supported: image

While I could just take the contents from the "`" block in the SnipMate snippet and directly copy it during the conversion to Vimscript, this won't always work: In your example, Filename is a special function that's only available in SnipMate.

It should be possible to detect this and convert the Filename part to equivalent Vimscript code though which seems like a good enhancement. Are there any other errors when you run :ConvertSnippets [template_name] (no headless=true) or is this the same issue in all of your snippets that could not be converted?

flotisable commented 1 year ago

Oh, I do not aware of the error message since I write script to do the conversion with headless set to true.

I have checked all errors when performing the conversion are all because of not support of vim script conversion. But the conversion can successfully convert the snippets without issue before with commit 059fb3d081a334853896d535534aaf0a53aced4f, not sure why.

If this is current behavior now, is it possible to use the transformation feature to convert the Filename function to an equivalent vimscript code before it is supported officially?

smjonas commented 1 year ago

If this is current behavior now, is it possible to use the transformation feature to convert the Filename function to an equivalent vimscript code before it is supported officially?

Yes it should be possible by recursively iterating over all elements within the body of the snippet and checking whether the node type equals require("snippet_converter.core.node_type").VIMSCRIPT_CODE, then replacing any occurrences of Filename with equivalent Vimscript code. Let me see if I can provide you with a code example for the transform function in the next days / weeks.