Is there a way I can define a custom refactoring in Visual Studio Code?
Asked Answered
Z

0

9

It is possible to define custom snippets of code that VS Code can auto complete. These can even use place-holders so that one can fill in the blanks as required.

/* Before */

//=

/* After (for example) */

// [title]
//===============================

What I'm looking for is somewhat the next step up from that, where it can take a selection and replace it with a place-holder that contains that original code (having embedded place-holders is a plus too).

/* Before */
some.code();
where.I = am;
doing = stuff;

/* After (for example) */
some('surrounding code which contains the original code', () => {
  some.code();
  where.I = am;
  doing = stuff;
});

The above is just an example of what I want to achieve - the surrounding code could take any form.

Zarah answered 19/7, 2022 at 16:27 Comment(3)
Great question! You could write a node.js script and hook into selected text. Take a look here: code.visualstudio.com/docs/editor/…. There might be a better way and if you find it let me know!Crossman
That appears to be the documentation for creating debug configurations, which isn't especially related. Can you give a bit more of a concrete example?Zarah
Sadly no @OokerZarah

© 2022 - 2024 — McMap. All rights reserved.