cursorless icon indicating copy to clipboard operation
cursorless copied to clipboard

Nested snippets requiring multiple `tab`s to proceed

Open MartinRykfors opened this issue 3 years ago • 3 comments

I have the following two snippets defined (python):

# comprehension
[| for | in |]
# if inline
| if | else |

Running snippet comprehension snippet if inline gives

[| if | else | for | in |]

Saying tab makes the point move to the next hole, but it requires two tabs to leave the first snippet and enter the second hole of the second snippet.

air tab bat tab cap tab drum tab each results in

[a if b else cd for e in |]

air tab bat tab cap tab tab drum tab each results in

[a if b else c for d in e]

Snippet definitions:

{
  "ifInlineStatement": {
    "definitions": [
      {
        "scope": {
          "langIds": [
            "python"
          ]
        },
        "body": [
          "$val1 if $condition else $val2"
        ]
      }
    ],
    "description": "Inline if statement",
    "variables": {
      "val1": {
        "wrapperScopeType": "value"
      }
    },
    "insertionScopeTypes": [
      "statement"
    ]
  }
}
{
  "listComprehension": {
    "definitions": [
      {
        "scope": {
          "langIds": [
            "python"
          ]
        },
        "body": [
          "[$transformation for $var in $iterable]"
        ]
      }
    ]
  }
}

MartinRykfors avatar Jun 22 '23 15:06 MartinRykfors

Not saying this is an ideal solution, but what happens if you replace $val2 with $0 in your inline if snippet?

pokey avatar Jun 22 '23 19:06 pokey

Changing it to $0 makes it leave the snippet the first time you say tab as expected.

MartinRykfors avatar Jun 25 '23 16:06 MartinRykfors

The VSCode behaviour here where it injects an implicit $0 even if you have a snippet hole at the end of the snippet seems undesirable. We should detect this situation and use $0 for the final snippet hole

pokey avatar Jun 25 '23 17:06 pokey