Wanting Cursor to detect when a file referenced in an import statement doesn't exist and prompt "File X not found. Create it?"
I'll create a VS Code extension that detects missing imported files and offers to create them automatically.
This extension automatically detects when you're importing files that don't exist yet and offers to create them with appropriate templates - exactly what was requested in that Cursor forum thread about suggesting file creation from import paths.
-
Create a new VS Code extension project:
npm init vscode-extension # Choose TypeScript when prompted
-
Replace the files with those from the artifacts:
- Replace
src/extension.ts
with the "Import Path File Creator Extension" artifact - Replace
package.json
with the "package.json for Import Path File Creator" artifact
- Replace
-
Install dependencies and build:
npm install npm run compile
-
Test the extension:
- Press F5 in VS Code/Cursor to launch with the extension
- Try writing an import statement for a non-existent file like:
import styles from './About.module.scss'
- Save the file
- You'll get a notification offering to create the missing file
-
Package for distribution (optional):
npm install -g vsce vsce package code --install-extension import-file-creator-0.0.1.vsix
The extension:
- Monitors your code files for import statements
- Detects when imported files don't exist
- Offers to create them with appropriate templates based on file type
- Automatically creates any necessary directories
- Opens the newly created file for editing
This should solve the exact problem mentioned in the forum thread where users want Cursor to detect missing imported files and offer to create them.
=======
README.md:
A VS Code/Cursor extension that detects missing files in import statements and offers to create them with appropriate templates.
This extension solves a common pain point when coding: writing import statements for files that don't exist yet. Instead of having to manually create these files, this extension will:
- Automatically detect when you import a file that doesn't exist
- Offer to create the file for you with an appropriate template
- Open the newly created file so you can start editing it immediately
- Import Detection: Identifies missing files from ES6 imports, CommonJS requires, and CSS imports
- Smart Path Resolution: Handles various import path formats and automatically adds extensions when needed
- Contextual Templates: Creates files with appropriate starter code based on file type and context
- Directory Creation: Automatically creates any missing directories in the import path
- Multiple Language Support: Works with JavaScript, TypeScript, React, Vue, CSS, and more
-
Clone this repository or create the files from scratch:
git clone https://github.com/yourusername/import-file-creator.git cd import-file-creator
-
Install dependencies:
npm install
-
Build the extension:
npm run compile
-
To test in development mode:
- Press F5 in VS Code with this project open
- This launches a new Extension Development Host window with the extension loaded
-
To install for regular use:
- Package the extension:
vsce package
- Install the generated .vsix file:
code --install-extension import-file-creator-0.0.1.vsix
- Package the extension:
The extension works automatically:
-
Write an import statement for a file that doesn't exist yet:
import { Button } from './components/Button';
-
Save the file
-
The extension will detect that
./components/Button.js
(or similar) doesn't exist and show a notification:File not found: components/Button.js. Create it?
-
Click "Create File" to generate the file with an appropriate template
-
The file will be created and opened for editing
The extension creates appropriate templates for:
- React components (.jsx, .tsx)
- TypeScript files (.ts)
- JavaScript modules (.js)
- CSS and SCSS files (.css, .scss, .module.css)
- JSON files (.json)
- Vue components (.vue)
Currently, the extension works with minimal configuration. Future versions may include settings for customizing templates.
- Node modules and absolute imports are not processed
- Some complex import path formats might not be correctly resolved
- The extension currently uses predefined templates rather than user-customizable ones
Contributions are welcome! This extension addresses a specific pain point in development workflows and can be expanded to support more file types and customization options.
MIT
Note: This extension is not officially affiliated with Cursor or VSCode.