Auto Fold is a Visual Studio Code extension that automatically folds and unfolds code sections, particularly import statements, based on user interactions and configurations. It supports JavaScript, TypeScript, and other languages.
Features
Automatically folds import statements when a document is opened.
Unfolds or folds import sections based on text editor selection changes.
Provides two methods for folding imports:
String Search Imports: Manually searches for import statements in JavaScript/TypeScript files.
Folding Range Imports: Uses VS Code's folding range provider for more accurate folding.
Configuration Options
The extension provides the following configuration options:
auto-fold.fold/unfold-imports-when-focus/blur
Type: boolean
Default: true
Description: When the import section is focused, it unfolds all imports. When the import section is blurred, it folds all imports.
auto-fold.enable-str-search-imports-for-js
Type: boolean
Default: true
Description: Enables string search for imports in JavaScript files. This is useful when VS Code's default folding behavior does not work as expected.
How to Use
Install the extension from the VS Code marketplace or clone this repository and build it locally.
Open a JavaScript or TypeScript file with import statements.
The extension will automatically fold the import statements based on the configuration.
Modify the settings in your VS Code settings.json file to customize the behavior: