Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snippet migrator improperly handles multiple snippets in the same file #2836

Closed
pokey opened this issue Feb 6, 2025 · 1 comment · Fixed by #2838
Closed

Snippet migrator improperly handles multiple snippets in the same file #2836

pokey opened this issue Feb 6, 2025 · 1 comment · Fixed by #2838
Assignees
Labels
bug Something isn't working

Comments

@pokey
Copy link
Member

pokey commented Feb 6, 2025

Input:

{
  "mobxConstructor": {
    "definitions": [
      {
        "scope": {
          "langIds": [
            "typescript",
            "javascript",
            "typescriptreact",
            "javascriptreact"
          ]
        },
        "body": [
          "constructor($parameters) {",
          "\tmakeAutoObservable(this);",
          "}"
        ]
      }
    ],
    "description": "Constructor using makeAutoObservable",
    "insertionScopeTypes": [
      "namedFunction"
    ]
  },
  "constantDeclaration": {
    "definitions": [
      {
        "scope": {
          "langIds": [
            "typescript",
            "javascript",
            "typescriptreact",
            "javascriptreact"
          ]
        },
        "body": [
          "const $name = ${value/^([^;]*);?$/$1/};"
        ],
        "variables": {
          "name": {
            "formatter": "camelCase"
          }
        }
      }
    ],
    "description": "Constant variable declaration",
    "insertionScopeTypes": [
      "statement"
    ],
    "variables": {
      "value": {
        "wrapperScopeType": "statement"
      }
    }
  },
  "constantDeclarationWithType": {
    "definitions": [
      {
        "scope": {
          "langIds": [
            "typescript",
            "javascript",
            "typescriptreact",
            "javascriptreact"
          ]
        },
        "body": [
          "const $name: $type = ${value/^([^;]*);?$/$1/};"
        ],
        "variables": {
          "name": {
            "formatter": "camelCase"
          }
        }
      }
    ],
    "description": "Constant variable declaration with type",
    "insertionScopeTypes": [
      "statement"
    ],
    "variables": {
      "value": {
        "wrapperScopeType": "statement"
      }
    }
  },
  "letDeclaration": {
    "definitions": [
      {
        "scope": {
          "langIds": [
            "typescript",
            "javascript",
            "typescriptreact",
            "javascriptreact"
          ]
        },
        "body": [
          "let $name = ${value/^([^;]*);?$/$1/};"
        ],
        "variables": {
          "name": {
            "formatter": "camelCase"
          }
        }
      }
    ],
    "description": "Let variable declaration",
    "insertionScopeTypes": [
      "statement"
    ],
    "variables": {
      "value": {
        "wrapperScopeType": "statement"
      }
    }
  },
  "letDeclarationWithType": {
    "definitions": [
      {
        "scope": {
          "langIds": [
            "typescript",
            "javascript",
            "typescriptreact",
            "javascriptreact"
          ]
        },
        "body": [
          "let $name: $type = ${value/^([^;]*);?$/$1/};"
        ],
        "variables": {
          "name": {
            "formatter": "camelCase"
          }
        }
      }
    ],
    "description": "Let variable declaration with type",
    "insertionScopeTypes": [
      "statement"
    ],
    "variables": {
      "value": {
        "wrapperScopeType": "statement"
      }
    }
  }
}

Output:

name: letDeclarationWithType
description: Let variable declaration with type
phrase: let type
insertionScope: statement

$value.wrapperPhrase: let type
$value.wrapperScope: statement
---

language: typescript | javascript | typescriptreact | javascriptreact
-
constructor($parameters) {
    makeAutoObservable(this);
}
---

language: typescript | javascript | typescriptreact | javascriptreact

$name.insertionFormatter: PRIVATE_CAMEL_CASE
-
const $name = ${value/^([^;]*);?$/$1/};
---

language: typescript | javascript | typescriptreact | javascriptreact

$name.insertionFormatter: PRIVATE_CAMEL_CASE
-
const $name: $type = ${value/^([^;]*);?$/$1/};
---

language: typescript | javascript | typescriptreact | javascriptreact

$name.insertionFormatter: PRIVATE_CAMEL_CASE
-
let $name = ${value/^([^;]*);?$/$1/};
---

language: typescript | javascript | typescriptreact | javascriptreact

$name.insertionFormatter: PRIVATE_CAMEL_CASE
-
let $name: $type = ${value/^([^;]*);?$/$1/};
---

Note how for all fields other than language (eg name, description, etc) it just takes the value from the final snippet and puts them at the top of the file.

@AndreasArvidsson
Copy link
Member

Good catch. Looks like we didn't have a example of multiple difference snippet names in the same file.

Hopefully this works better:
#2838

github-merge-queue bot pushed a commit that referenced this issue Feb 10, 2025
… one file and noop phrase (#2838)

Fixes #2836
Fixes #2840

Input
```json
{
  "mobxConstructor": {
    "definitions": [
      {
        "scope": {
          "langIds": [
            "typescript",
            "javascript",
            "typescriptreact",
            "javascriptreact"
          ]
        },
        "body": [
          "constructor($parameters) {",
          "\tmakeAutoObservable(this);",
          "}"
        ]
      }
    ],
    "description": "Constructor using makeAutoObservable",
    "insertionScopeTypes": [
      "namedFunction"
    ]
  },
  "constantDeclaration": {
    "definitions": [
      {
        "scope": {
          "langIds": [
            "typescript",
            "javascript",
            "typescriptreact",
            "javascriptreact"
          ]
        },
        "body": [
          "const $name = ${value/^([^;]*);?$/$1/};"
        ],
        "variables": {
          "name": {
            "formatter": "camelCase"
          }
        }
      }
    ],
    "description": "Constant variable declaration",
    "insertionScopeTypes": [
      "statement"
    ],
    "variables": {
      "value": {
        "wrapperScopeType": "statement"
      }
    }
  },
  "constantDeclarationWithType": {
    "definitions": [
      {
        "scope": {
          "langIds": [
            "typescript",
            "javascript",
            "typescriptreact",
            "javascriptreact"
          ]
        },
        "body": [
          "const $name: $type = ${value/^([^;]*);?$/$1/};"
        ],
        "variables": {
          "name": {
            "formatter": "camelCase"
          }
        }
      }
    ],
    "description": "Constant variable declaration with type",
    "insertionScopeTypes": [
      "statement"
    ],
    "variables": {
      "value": {
        "wrapperScopeType": "statement"
      }
    }
  },
  "letDeclaration": {
    "definitions": [
      {
        "scope": {
          "langIds": [
            "typescript",
            "javascript",
            "typescriptreact",
            "javascriptreact"
          ]
        },
        "body": [
          "let $name = ${value/^([^;]*);?$/$1/};"
        ],
        "variables": {
          "name": {
            "formatter": "camelCase"
          }
        }
      }
    ],
    "description": "Let variable declaration",
    "insertionScopeTypes": [
      "statement"
    ],
    "variables": {
      "value": {
        "wrapperScopeType": "statement"
      }
    }
  },
  "letDeclarationWithType": {
    "definitions": [
      {
        "scope": {
          "langIds": [
            "typescript",
            "javascript",
            "typescriptreact",
            "javascriptreact"
          ]
        },
        "body": [
          "let $name: $type = ${value/^([^;]*);?$/$1/};"
        ],
        "variables": {
          "name": {
            "formatter": "camelCase"
          }
        }
      }
    ],
    "description": "Let variable declaration with type",
    "insertionScopeTypes": [
      "statement"
    ],
    "variables": {
      "value": {
        "wrapperScopeType": "statement"
      }
    }
  }
}
```

Output
```
name: mobxConstructor
description: Constructor using makeAutoObservable
language: typescript | javascript | typescriptreact | javascriptreact
insertionScope: namedFunction
-
constructor($parameters) {
    makeAutoObservable(this);
}
---

name: constantDeclaration
description: Constant variable declaration
language: typescript | javascript | typescriptreact | javascriptreact
insertionScope: statement

$name.insertionFormatter: PRIVATE_CAMEL_CASE
$value.wrapperScope: statement
-
const $name = ${value/^([^;]*);?$/$1/};
---

name: constantDeclarationWithType
description: Constant variable declaration with type
language: typescript | javascript | typescriptreact | javascriptreact
insertionScope: statement

$name.insertionFormatter: PRIVATE_CAMEL_CASE
$value.wrapperScope: statement
-
const $name: $type = ${value/^([^;]*);?$/$1/};
---

name: letDeclaration
description: Let variable declaration
language: typescript | javascript | typescriptreact | javascriptreact
insertionScope: statement

$name.insertionFormatter: PRIVATE_CAMEL_CASE
$value.wrapperScope: statement
-
let $name = ${value/^([^;]*);?$/$1/};
---

name: letDeclarationWithType
description: Let variable declaration with type
language: typescript | javascript | typescriptreact | javascriptreact
insertionScope: statement

$name.insertionFormatter: PRIVATE_CAMEL_CASE
$value.wrapperScope: statement
-
let $name: $type = ${value/^([^;]*);?$/$1/};
---

```

---------

Co-authored-by: Pokey Rule <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants