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

vscode converter fails to convert snippets with visual placeholder #18

Closed smjonas closed 1 year ago

smjonas commented 1 year ago
    Thanks for your quick response.

The fix resolve the issue in the example. However, it seems the fix breaks a lot of snippet conversion. The example below works as expected before

snippet if "if control flow"
        if ${1:<condition>}
        "
                ${2:${VISUAL}}
        "
        endif

snippet ife "if else control flow"
        if ${1:<condition>}
        "
                ${2}
        "
        else
        "
                ${3}
        "
        endif

snippet func "function definition"
        function ${1:<function name>}(${2:<arguments>})
        "
                ${3:${VISUAL}}
        "
        endfunction

after the fix, it is only converted to the snippet below, note the if and func snippet disappear

{
  "ife": {
    "prefix": "ife",
    "description": "\"if else control flow\"",
    "body": [
      "if ${1:<condition>}",
      "\"",
      "\t$2",
      "\"",
      "else",
      "\"",
      "\t$3",
      "\"",
      "endif",
      ""
    ]
  }
}

If you would like to see more detail, my snippets can be found at https://github.com/flotisable/FlotisableVimSnippets. Clone the repo, and update the snippet-converter.nvim submodule, then run make convert. The converted difference between previous version and the fix can then be seen with git diff

Originally posted by @flotisable in https://github.com/smjonas/snippet-converter.nvim/issues/16#issuecomment-1374965251

smjonas commented 1 year ago

The reason why the snippets were not converted seems to be because the converter ignores visual placeholder nodes.

smjonas commented 1 year ago

@flotisable This should now be fixed on the latest main. Your example is now converted to:

{
  "if": {
    "prefix": "if",
    "description": "\"if control flow\"",
    "body": [
      "if ${1:<condition>}",
      "\"",
      "\t${2:$TM_SELECTED_TEXT}",
      "\"",
      "endif",
      ""
    ]
  },
  "ife": {
    "prefix": "ife",
    "description": "\"if else control flow\"",
    "body": [
      "if ${1:<condition>}",
      "\"",
      "\t$2",
      "\"",
      "else",
      "\"",
      "\t$3",
      "\"",
      "endif",
      ""
    ]
  },
  "func": {
    "prefix": "func",
    "description": "\"function definition\"",
    "body": [
      "function ${1:<function name>}(${2:<arguments>})",
      "\"",
      "\t${3:$TM_SELECTED_TEXT}",
      "\"",
      "endfunction",
      ""
    ]
  }
}