A VSCode extension that collapses all outermost code blocks (functions, arrays, objects) while keeping their inner content expanded. This helps you get a quick overview of your code structure while maintaining access to the implementation details.
- Collapses outermost code blocks (defined by {}, [], or () pairs)
- Preserves inner content expansion
- Handles nested blocks correctly
- Skips blocks within string literals and comments
- Works with any file type
- Configurable ignore patterns:
- If a block's start line matches an ignore pattern (e.g., a class definition), that block is not collapsed.
- Instead, its immediate child blocks (e.g., methods inside a class) are collapsed, while their inner content remains expanded.
Suppose you have this code and the ignore pattern is ^class:
class MyClass {
methodOne() {
// ...
}
methodTwo() {
// ...
}
}- The class block is not collapsed.
- Both
methodOneandmethodTwoblocks are collapsed. - Code inside those methods remains expanded.
You can configure which lines to ignore using regular expressions in your VSCode settings:
{
"outerBlockCollapse.ignorePatterns": [
"^@", // Ignore lines starting with @
"^\\s*import ", // Ignore import statements
"^class" // Ignore class definitions (collapses methods inside instead)
]
}By default, the extension ignores lines starting with @ (common for decorators). You can add more patterns in your settings.json or through the Settings UI.
- Download the latest
.vsixfile from the releases - Open VSCode
- Press
Ctrl+Shift+X(Windows/Linux) orCmd+Shift+X(Mac) to open the Extensions view - Click on the "..." (More Actions) menu
- Select "Install from VSIX..."
- Choose the downloaded .vsix file
You can collapse outer blocks in two ways:
- Windows/Linux: Press
Ctrl+K Ctrl+0 - Mac: Press
Cmd+K Cmd+0
- Open any code file
- Open the command palette (
Ctrl+Shift+P/Cmd+Shift+P) - Type "Collapse Outer Blocks" and select the command
- The outermost blocks will be collapsed while inner content remains expanded
The keyboard shortcut was chosen to be similar to VSCode's built-in "Fold All" (Ctrl+K Ctrl+0), making it intuitive for users familiar with VSCode's folding shortcuts.
- Node.js (v14 or higher)
- npm or yarn
- VSCode (for testing)
Clone the repository:
git clone <your-repo-url>
cd outer-block-collapseInstall dependencies:
yarn installBuild the extension:
yarn run compile- Press F5 in VSCode to launch a new Extension Development Host window
- Open a file with some nested blocks
- Use the command palette to run "Collapse Outer Blocks"
- Make changes to the code and press F5 to reload
Install vsce globally:
npm install -g @vscode/vscePackage the extension:
vsce packageThis will create a .vsix file in your directory that can be installed in VSCode.
outer-block-collapse/
├── package.json # Extension manifest
├── tsconfig.json # TypeScript configuration
├── README.md # This file
└── src/
└── extension.ts # Extension source code
MIT
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests (if available)
- Submit a pull request
- The extension currently doesn't handle language-specific block markers (like Python's indentation)
- Block detection is based on character matching and might not handle all edge cases in comments or strings