vscode-powershell icon indicating copy to clipboard operation
vscode-powershell copied to clipboard

Code refactoring such as inline or extract as function

Open perXautomatik opened this issue 1 year ago • 1 comments

Prerequisites

  • [X] I have written a descriptive issue title.
  • [X] I have searched all issues to ensure it has not already been reported.

Summary

Add code refactoring features to improve code maintainability and readability. Specifically, allow users to inline variables or extract code blocks into separate functions.

Proposed Design

Inline Variable Refactoring: Provide an option to inline variables directly where they are used. When selecting a variable, the user can trigger the refactoring action to replace all occurrences of that variable with its value. This helps reduce clutter and makes the code more concise. Extract as Function Refactoring: Allow users to select a code block (e.g., a series of statements) and extract it into a separate function. The user can specify the function name, parameters, and return type. The extracted function should be added to the script/module, and the original code replaced with a function call. This promotes code reusability and modularization.

note there might be possibility to include the module FriedrichWeinmann/Refactor / Refactor

perXautomatik avatar Jun 27 '24 05:06 perXautomatik

Thanks for your submission!

As of today we (sort of) have an API for this, and @SeeminglyScience has written refactors for it you should check out. https://github.com/SeeminglyScience/EditorServicesCommandSuite

In the future, I would like to adjust this API so these contributions can be accessed via the quick fix "lightbulb" and be more intuitive. There may already be a dupe issue for this, will reference if I find it.

JustinGrote avatar Jun 27 '24 08:06 JustinGrote