rewrite-docs icon indicating copy to clipboard operation
rewrite-docs copied to clipboard

Expand cursor documentation

Open mike-solomon opened this issue 1 year ago • 1 comments

From Slack:

Q: I have a case where I have one line in a method and need to insert say 5-6 lines replacing it. When I do it using visitMethodDecl I get the error that expected a template which will replace 1 statement with 1 but created 6 ..What is the workaround for it ?

Answer: Read this thread

From Tim:

one option is to return a block of statements { a; b; c; }.. and then call RemoveUnneededBlock right after

it's a creative way to solve this that I've used in the past as well.. works well enough for the code you already have most likely

the other option is to look up to the block that the variable declaration that you have is defined within, and replace the statements within that block with a new or mapped collection

both of those end up with the same result: your variable declaration replaced by multiple statements, but each only replacing one element of the LST with another

here's an example where I call RemoveUnneededBlock after a replacement

To help, we should expand on getCursor, updateCursor, and new Cursor as well as provide examples.

mike-solomon avatar Feb 06 '24 15:02 mike-solomon

@timtebeek When you have time, would you mind assisting with examples here?

Specifically:

  • I am not sure when you'd use the different cursor options (getCursor, updateCursor, new Cursor).
    • For these, it would be swell to have an example with them.
  • I'd love an example of some code that returns a block of statements and then calls the remove unneeded block to have some context as to why someone might do that.

Once I have some examples and more context, I'm happy to update the doc accordingly. ^_^

mike-solomon avatar Feb 07 '24 18:02 mike-solomon