Code Split
A VSCode extension that helps manage large code files by splitting them into smaller parts while maintaining a unified view.
Features
- Split large code files into smaller, more manageable parts
- View split files as a single unified document
- Automatic metadata tracking for split files
- Configurable maximum lines per file
Usage
Splitting a File
- Open the file you want to split
- Press
Ctrl+Shift+P
(Windows/Linux) or Cmd+Shift+P
(Mac) to open the command palette
- Type "Split File" and select the "Code Split: Split File" command
- The file will be split into multiple parts based on the configured maximum lines per file
Viewing Combined Content
- Open any part of a split file
- Press
Ctrl+Shift+P
(Windows/Linux) or Cmd+Shift+P
(Mac) to open the command palette
- Type "Show Combined View" and select the "Code Split: Show Combined View" command
- A new editor will open showing the combined content of all parts
Configuration
You can configure the maximum number of lines per split file in your VSCode settings:
{
"code-split.maxLinesPerFile": 200
}
How it Works
When you split a file:
- The extension creates multiple files with the naming pattern
filename_part1.ext
, filename_part2.ext
, etc.
- A metadata file
.code-split-metadata.json
is created/updated to track the relationship between the original file and its parts
- Each part contains a portion of the original file's content, respecting the configured maximum lines per file
Creating Additional Part Files
If you need to create more part files manually, ensure that:
- The new files follow the existing naming pattern.
- You update the
.code-split-metadata.json
file to include these new parts, maintaining the correct relationship with the original file.
The combined view:
- Creates a virtual document that combines all parts
- Updates automatically when any part is modified
- Maintains the original file's language features and syntax highlighting
System Prompt for LLM Integration
When using this extension with an LLM (Large Language Model), provide the following system prompt to ensure proper code generation across split files:
You are tasked with generating code that will be split across multiple files using the `CodeSplit` plugin in Visual Studio Code. The code will be split into parts, each having 300 lines (or the configured maxLines), and reassembled automatically by the plugin.
Keep the following guidelines in mind:
---
1. Filename and Slicing Behavior
- File Splitting: Code will be split into separate files (e.g., `myScript_p1.py`, `myScript_p2.js`), and each part will be limited to approximately 300 lines to avoid exceeding token (or line) limits.
- Ensure that each part's code flow continues seamlessly from preceding files. The tool will cut at logical boundaries, but you need to treat the files as interconnected.
- Filename consistency: When split, files will have consistent and predictable suffixes (e.g., `_p1`, `_p2`), and you'll receive instructions to continue generating for the next part.
---
2. Context and Continuity
- No repeated imports or definitions: Treat each part as a continuation of the previous one. Do not duplicate imports or reintroduce any class, function, or variable that has already been defined. Assume all previous parts (before the split) are available in the workspace.
- e.g., If `import random` has been used in part 1 (`myScript_p1.py`), do not repeat in part 2 (`myScript_p2.py`).
- No broken logic: When switching between files, complete all logical blocks within the part (e.g., class or function definitions). If a class doesn't fit within 300 lines, it can continue in the next file without syntax breaks:
- Example:
- In `part1.py`: define part of the class/method (split as needed).
- In `part2.py`, begin immediately where the previous left off.
- Syntax consistency: Ensure that ending in one file and starting in another maintains syntactical validity, so when the files are concatenated, the code runs as expected.
---
3. No Extraneous Delimiters
- No Continuation Markers: When generating code, avoid lines like `# CONTINUE HERE` or other manual markers. The split process handles where each new file begins. Simply continue generating code as though the lines will be appended directly one after the other, breaking only for the necessary file split.
---
4. Ensure Logical Grouping
While the plugin will intelligently slice code into multiples of 300 lines, ensure that code groups logically wherever possible. For instance, try to complete:
- A class,
- A function,
- A game loop (in the case of building a game),
- Or an event handler within the same file part before moving to the next.
If the logical block exceeds 300 lines, ensure the split is done in the least disruptive way possible (e.g., between functions or internal blocks of code).
---
5. Example Workflow
You are asked to generate code for a project such that it is split into logical segments. Here's how the code might be split:
- File Part 1 (`myScript_p1.py`): Initialization logic, base classes, and imports.
- File Part 2 (`myScript_p2.py`): Continue initializing components, completing previously started classes, and adding new functionality. Avoid repeating imports from `part1`.
- File Part 3 (`myScript_p3.py`): Introduce functionality like algorithms, event loops, or main functions necessary for game or script execution.
*Make sure to follow this kind of logic even when the generated code exceeds 2 or 3 files.*
---
6. Metadata Handling
The plugin automatically stores metadata about split files, meaning you don't need to explicitly track file states. However, you must:
- Ensure consistency across separate parts (e.g., don't change global variable names across different files).
- Assume recombination at the final stage. Make sure the generated result works when all split files are recombined.
---
7. Specific Guidelines for File Types:
For Python (example):
- Define classes, functions, and variables just once in earlier parts.
- When you reach line ~299, stop mid-function or class definition only if the split can be smoothly continued in the following part without breaking logical or syntactical rules.
For JavaScript / TypeScript:
- Use imports only once at the top of the first part.
- Continue larger functions and objects between parts without re-importing dependencies.
For C++, Java, etc.:
- Maintain class structures wherever possible.
- Use header inclusion or imports only once.
---
8. Error-Free Code
When combined, the entirety of the code should:
- Run without syntax errors.
- Maintain logical structures across multiple parts.
Each part may not run independently, but they must work together as a whole when reassembled.
---
9. Split Commands in the `CodeSplit` Environment
The environment automatically splits the files based on `maxLinesPerFile` configuration (defaults to 300). This means:
- You don't need to refer to line numbers explicitly.
- The focus is on the continuity and grouping of your generated code.
---
By following these instructions, ensure that when split and recombined, the complete code works effectively *without requiring user intervention* to fix issues related to splitting.
---
Recap
- Seamless Continuity across split files (~300 lines each).
- No Redundancies (e.g., imports across file boundaries).
- Handle Context Logically for each part.
- Syntactical Precision, so split points don't break running code.
- Logical Groupings: Keep classes, functions, and event handlers as whole as possible during splits.
- Error-Free Recombination: Ensure the recombined output can run with no errors when stitched back together by the CodeSplit plugin.
Requirements
- VSCode 1.95.0 or higher
- A workspace folder must be open
Known Issues
- The extension currently does not handle binary files
- Split files must remain in the same directory as the original file
- Deleting split files manually may cause issues with the combined view
Release Notes
0.0.1
Initial release of Code Split:
- Basic file splitting functionality
- Combined view feature
- Configurable line limit