CodeLifter
CodeLifter is a Visual Studio Code extension that allows you to quickly copy the contents of selected files or directories into memory (clipboard). You can configure the extension to apply filters, such as excluding test files, copying only code files, or copying all files, depending on your needs.
Objective
When using an LLM model like ChatGPT, it is important to be able to provide context about code files that are relevant to a question you want to ask. So, being able to easily copy the contents of several or specific files from the IDE into the clipboard, and in addition to that, have the relative path of each file included, is extremely helpful.
This extension allows you to select one or many files and/or folders and define what types of files you want copied into memory.
the format will look like this:
-- relative/path --
contents of the file
contents of the file
contents of the file
contents of the file
-- relative/path/to/file --
contents of the file
contents of the file
contents of the file
contents of the file
-- relative/path/to/file --
contents of the file
contents of the file
contents of the file
contents of the file
You simply copy this into the clipboard and you can easily paste it in the ChatGPT message and you fire your question away.
This is an extremely helpful way to use ChatGPT for coding questions.
Features
- Copy Files Excluding Tests: Copies the contents of all selected files, excluding those identified as test files.
- Copy Only Test Files: Copies the contents of all selected test files.
- Copy Only Code Files: Copies the contents of all selected code files (e.g.,
.ts
, .js
, .cs
), excluding non-code files like HTML or CSS.
- Copy All Files: Copies the contents of all selected files without applying any filters.
- Progress Bar and Notifications: The extension includes a progress bar during file copying operations and a toast notification that disappears after a few seconds.
Configuration
You can customize the behavior of CodeLifter through your workspace or user settings.json
file. The following settings allow you to control which commands are visible in the context menu and define the file filters.
Visibility Settings
Control the visibility of each command in the context menu by modifying the following settings in your settings.json
file:
{
"codelifter.showCopyFilesExcludingTests": true, // Show/Hide "Copy Files Excluding Tests" command
"codelifter.showCopyOnlyTests": true, // Show/Hide "Copy Only Test Files" command
"codelifter.showCopyOnlyCodeFiles": true, // Show/Hide "Copy Only Code Files" command
"codelifter.showCopyAllFiles": true // Show/Hide "Copy All Files" command
}
File Filter Settings
The extension comes with default filters, but you can customize these by defining your own filters in the settings.json
file. Below are the default filters provided:
{
"codelifter.filters": {
"excludeTests": {
"description": "Exclude test files",
"includeExtensions": ["*.ts", "*.js", "*.cs"], // Include only code files
//"includeExtensions": ["*"], // Include all files
"excludePatterns": [
"*.test.ts",
"*.spec.ts",
"*.test.js",
"*.spec.js",
"*.e2e-test.js",
"*.e2e-spec.js",
"*.e2e-test.ts",
"*.e2e-spec.ts",
] // Exclude test files
},
"onlyTests": {
"description": "Only test files",
"includeExtensions": [
"*.test.ts",
"*.spec.ts",
"*.test.js",
"*.spec.js",
"*.e2e-test.js",
"*.e2e-spec.js",
"*.e2e-test.ts",
"*.e2e-spec.ts",
], // Include only test files
"excludePatterns": [] // No exclusions
},
"onlyCode": {
"description": "Only code files",
"includeExtensions": ["*.ts", "*.js", "*.cs"], // Include only code files
"excludePatterns": [
"*.html",
"*.scss",
"*.css",
"*.test.ts",
"*.spec.ts",
"*.test.js",
"*.spec.js",
"*.e2e-test.js",
"*.e2e-spec.js",
"*.e2e-test.ts",
"*.e2e-spec.ts",
] // Exclude non-code files, including test files if desired. Optionally don't exclude test files.
},
"allFiles": {
"description": "All files",
"includeExtensions": ["*"], // Include all files
"excludePatterns": [] // No exclusions
}
}
}
You can override these filters by customizing the codelifter.filters
settings in your settings.json
.
Usage
Right-click on a file or folder in the Explorer panel to access the CodeLifter commands:
- Copy Files Excluding Tests: Copies contents excluding test files.
- Copy Only Test Files: Copies contents of test files only.
- Copy Only Code Files: Copies contents of code files only.
- Copy All Files: Copies contents of all selected files.
Customize visibility: Use the visibility settings in settings.json
to show or hide specific commands.
Customize filters: Modify the default filters or add your own custom filters in settings.json
.
Example Configuration
Here’s an example configuration in settings.json
to customize which commands are visible and adjust file filters:
{
"codelifter.showCopyFilesExcludingTests": true,
"codelifter.showCopyOnlyTests": false,
"codelifter.showCopyOnlyCodeFiles": true,
"codelifter.showCopyAllFiles": true,
"codelifter.filters": {
"excludeTests": {
"description": "Exclude test files",
"includeExtensions": ["*"],
"excludePatterns": ["*.test.ts", "*.spec.ts", "*.test.js", "*.spec.js"]
},
"onlyTests": {
"description": "Only test files",
"includeExtensions": ["*.test.ts", "*.spec.ts", "*.test.js", "*.spec.js"],
"excludePatterns": []
},
"onlyCode": {
"description": "Only code files",
"includeExtensions": ["*.ts", "*.js", "*.cs"],
"excludePatterns": ["*.html", "*.scss", "*.css"]
},
"allFiles": {
"description": "All files",
"includeExtensions": ["*"],
"excludePatterns": []
}
}
}
License
This extension is licensed under the MIT License. See the LICENSE file for more details.
Contributing
Contributions are welcome! If you encounter issues or have suggestions for improvement, feel free to open an issue or submit a pull request.
Thank you for using CodeLifter! If you find this extension useful, please consider leaving a review in the Visual Studio Code Marketplace.