Git Product home page Git Product logo

Comments (2)

ScottMorse avatar ScottMorse commented on September 28, 2024 1

Yes, the transformations work with normal snippets. I'll use a smaller example (the React useState hook) to demonstrate some of the nuances I'm experiencing:

If I use this regular VSCode snippet...

{
  "use state": {
    "scope": "javascript,typescript,javascriptreact,typescriptreact",
    "prefix": "usestate",
    "body": ["const [${1}, set${1/(.*)/${1:/capitalize}/}] = useState(${2});"],
    "description": "useState"
  }
}

... I can get the casing I want by first inserting the snippet, entering my text for variable $1, and then hitting Tab to get to variable $2. The capitalize transform isn't applied until I hit Tab.

If I use this Cursorless snippet...

{
  "useState": {
    "definitions": [
      {
        "scope": {
          "langIds": [
            "javascript",
            "javascriptreact",
            "typescript",
            "typescriptreact"
          ]
        },
        "body": [
          "const [${name}, set${name/(.*)/${1:/capitalize}/}] = useState(${initialValue})"
        ],
        "variables": {
          "name": {
            "formatter": "camelCase"
          }
        }
      }
    ]
  }
}

... I can add useState, useStateTest.name to insertion_snippets_single_phrase.csv and use the snippet without error, but the capitalize transform is not applied whether or not I include the initial phrase or not, so "snippet usestate hello world" will insert const [helloWorld, sethelloWorld] = useState(), and if I use only "snippet usestate" and then enter $name manually, the capitalize transform will not be applied even after I use the Tab key. I also tested this without the formatter configured for $name.

If I try making my Cursorless snippet this...

{
  "useState": {
    "definitions": [
      {
        "scope": {
          "langIds": [
            "javascript",
            "javascriptreact",
            "typescript",
            "typescriptreact"
          ]
        },
        "body": [
          "const [${1}, set${1/(.*)/${1:/capitalize}/}] = useState(${initialValue})"
        ],
        "variables": {
          "1": {
            "formatter": "camelCase"
          }
        }
      }
    ]
  }
}

... I cannot use the initial phrase for variable $1, as it seems that entries such as useState, useState.1 or useState, useState[1], etc. do not work for insertion_snippets_single_phrase.csv. However, I can simply use "snippet usestate" without a phrase and use the Tab key to get a successful capitalize after manually entering $1. This has been my current workaround in general for snippets where I need transformations, using numbered variables and not using the initial phrase (or using the initial phrase for a different variable that doesn't need transformation).

This is purely speculation, but perhaps the issue has to do with VSCode requiring the explicit Tab press to apply the transformation, and perhaps Cursorless cannot currently trigger this with the initial phrase. I'm not sure why in my second code block above, the Cursorless snippet using $name, I cannot get the capitalize even with manual entry of $name plus a Tab press, though.

from cursorless.

pokey avatar pokey commented on September 28, 2024

does this work with regular vscode snippets? we just vendored in their snippet parser

from cursorless.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.