1 -> Refactor-Extract code extraction
In the editor, you can extract code blocks or expressions in functions and class methods into new methods/functions, constants, interfaces, variables, or type aliases. Accurately and conveniently extract the selected region code from the current scope to improve encoding efficiency. Select the code block to be extracted, right-click Refactor, and select the type to be extracted.
illustrate
The Refactor-Extract code extracts the code to a Type Alias (Type Alias) feature that is supported only by TS language.
Methods/Functions can be extracted by selecting code blocks or complete statements:
In the ArkTS language, you can extract component call code blocks as @builder decorator decoration methods, and component property call expressions can be extracted as @styles or @Extend decorator decoration methods.
How to use: Select the component or attribute to be extracted, right-click Refactor, and select Extract Method..., the private attribute of the component can be extracted as a method for @Extend decoration, and the general attribute can be extracted as a method for @styles or @Extend decoration.
Constant allows you to select a single-line expression for extraction:
Interface allows you to select the arguments of an object for extraction:
Selected expressions can be extracted as variables:
2 -> Refactor-Convert transcoding
The editor provides the Convert refactoring capability and supports high-frequency conversion operations such as Convert between named imports and namespace imports, assisting in efficient code refactoring and improving code quality.
3 -> Refactor-Rename code rename
Code editing supports the Rename function, which can quickly change the names of variables, methods, object properties, and other related identifiers, as well as the names of files and modules, and synchronize them to the location where they are referenced in the entire project.
How to use: Select the identifier (variable, class, interface, custom component, etc.) to be renamed, right-click Refactor, and select Rename... (or use the shortcut key Shift+F6), enter a new identifier name in the pop-up box, select the replacement range in the scope, and click Refactor to complete the renaming.
Code editing allows you to filter and filter for reference locations that don't require a rename. In Rename....In the pop-up preview window, click Preview, select the option that does not require Rename, click Exclude/Remove in the right-click menu to filter/delete, and click Do Refactor in the lower left corner to re-execute the Rename operation.
illustrate
If there is a C++ API call in the ArkTS file, the function name involved in the C++ file will also be renamed when you use Rename to rename it.
4 -> Move File
Right-click the file, select Refactor > Move File..., and enter or click in the pop-up window....Select the specified directory and click Refactor to move the current file to the directory. Select Search for references to find and update references to the file in the project. Select Open in editor to view the moved files in the editor.
5 -> Safe Delete
The editor supports the Safe Delete feature, which helps you safely delete identifier objects (variables, functions, classes, etc.) in your code or delete specified files. Before deleting, the editor will search the code for references to the object, and if there are references, the editor will prompt you to make the necessary checks and adjustments.
How to use: Select the identifier object to be deleted in the editor or select the file to be deleted in the project directory, right-click Refactor, select Safe Delete, click OK to automatically check the current object is referenced in the code, click View Usages to view the specific code content used, and click Delete Anyway will directly delete the definition of the object.
Top comments (0)