README
Filename-Provider Extension
The "filename-provider" extension automatically adds a file path comment at the top of your files when they are created or saved in Visual Studio Code.
Use case
I build a lot with AI and use a repo flattener to help the AI understand the relationships between files. Including the filename at the top of each file when providing full files is a game changer in helping it stay focused and reference correctly.
Features
- Smart Path Management: Automatically adds file path comments to the top of files
- Duplicate Prevention: Detects existing correct paths and avoids adding duplicates
- Auto-Update on Move: Replaces outdated paths when files are moved or renamed
- Protected File Types: Skips files where comments would break functionality (JSON, YAML, etc.)
- Extensive Language Support: Works with 30+ programming languages
- Framework Ready: Works seamlessly with Next.js, NestJS, and other modern frameworks
How It Works
- On file creation or save, the extension checks the first few lines for an existing path comment
- If the correct path exists: Does nothing (prevents duplicates)
- If an outdated path exists: Replaces it with the current path (handles renames/moves)
- If no path exists: Inserts a new one at the top
Supported Languages
// style comments:
- JavaScript, TypeScript, JSX, TSX
- Java, C, C++, C#, Go, Rust, PHP
- Swift, Kotlin, Dart, Scala
- Objective-C, Objective-C++
# style comments:
- Python, Ruby, Perl, R
- Shell, Bash, Zsh, Fish, PowerShell
- Makefile, Dockerfile, CoffeeScript
/* */ style comments:
- CSS, SCSS, Sass, Less, Stylus
-- style comments:
Protected File Types
The extension automatically skips files where comments would cause issues:
- Config files: JSON, YAML, TOML, INI, .env files
- Markup files: HTML, XML, SVG, Markdown
- Template files: Handlebars, EJS, Pug, Jade
- Special files: package.json, tsconfig.json, README.md, LICENSE, etc.
- Build artifacts: node_modules, dist, build, .next, etc.
Examples
For a TypeScript file in Next.js:
// src/app/page.tsx
export default function Home() {
return <div>Hello World</div>;
}
For a Python file:
# src/utils/helper.py
def process_data():
pass
For a CSS file:
/* styles/main.css */
body {
margin: 0;
}
Edge Cases Handled
- Shebangs: Preserves shebang lines (e.g.,
#!/usr/bin/env node) and adds path below
- File Moves: Automatically updates the path when you move or rename a file
- Multiple Saves: Won't add duplicate paths on repeated saves
- Mixed Comment Styles: Correctly handles different comment syntaxes per language
| |