VSCode extension for wrap #2985
Replies: 4 comments 1 reply
-
I've asked Copilot:
Response: Certainly! Creating a Visual Studio Code (VS Code) extension to wrap selected Python code with a class is a useful idea. While I can't directly create an extension for you, I can guide you on how to achieve this. Here are some steps you can follow:
While there isn't an existing extension that directly wraps Python code with a class, you can explore existing extensions like the "Python Try-Except Wrapper", which allows wrapping selected Python code in a try-except block². You can use this as a reference or inspiration for your custom class-wrapping extension. Remember to adapt the steps above to your specific requirements, and feel free to get creative with your extension! 🚀 Source: Conversation with Bing, 2024-04-04 |
Beta Was this translation helpful? Give feedback.
-
I didn't find a repo for "python try-except wrapper" extension, but you can download vsix from here: https://marketplace.visualstudio.com/items?itemName=HarshaSurampudi.python-try-except-wrapper and unpack it to see the sources. There is compiled .ts inside. |
Beta Was this translation helpful? Give feedback.
-
The code interesting to us: const editor = vscode.window.activeTextEditor;
if (editor) {
const selection = editor.selection;
const selectedText = editor.document.getText(selection);
// Find existing indentation
const firstLine = editor.document.lineAt(selection.start.line);
const existingIndent = firstLine.text.substring(0, firstLine.firstNonWhitespaceCharacterIndex);
// Apply indentation to the try-except block
const indentedText = selectedText
.split("\n")
.map((line) => `\t${line}`)
.join("\n");
const wrappedText = `${existingIndent}try:\n${indentedText}\n${existingIndent}catch Exception as e:\n${existingIndent}\tprint(e)`;
editor.edit((editBuilder) => {
editBuilder.replace(selection, wrappedText);
});
} |
Beta Was this translation helpful? Give feedback.
-
Is there anyone here who can make or suggest how to make an extension for VSCode that will allow you to wrap controls in other controls as in Flutter?
A lot of time is wasted on such simple actions.
Example:
Right click on
ft.Container
selectwrap with widget
etc.After complete wrap:
Flutter example:
Beta Was this translation helpful? Give feedback.
All reactions