Open closest
A VS Code extension that opens the closest package.json or barrel file to the currently open file.
Note: This extension was entirely AI-generated.
Features
- Open closest package.json: Navigate up the directory hierarchy from your current file to find and open the nearest
package.json file
- Open closest barrel file: Find and open the nearest barrel file (
index.ts, index.tsx, index.js, index.jsx, index.mdx, or custom)
Commands
Open closest package.json - Opens the closest package.json file to the active editor
Open closest barrel file - Opens the closest barrel file to the active editor
Access these commands via:
- Command Palette:
Cmd+Shift+P (Mac) or Ctrl+Shift+P (Windows/Linux) and search for the command name
Configuration
You can customize which files are considered "barrel files" by adding to your VS Code settings:
"openClosest.barrelFileNames": [
"index.ts",
"index.tsx",
"index.js",
"index.jsx",
"index.mdx"
]
The extension will search for these files in the order specified.
How it works
When you run either command:
- The extension checks the current directory of the open file for matching files
- If not found, it checks the parent directory
- It continues moving up the directory tree until it finds a matching file
- The search stops at the workspace root boundary
- If a file is found, it opens in the editor
- If no file is found, an error message is displayed
Requirements
Development
Building
npm run esbuild
Running the extension
- Press
F5 to launch a VS Code Extension Development Host
- In the development window, open the command palette (
Cmd+Shift+P / Ctrl+Shift+P)
- Run "Open closest package.json" or "Open closest barrel file"
Debugging
- Set breakpoints in the code
- Run the extension with
F5
- Use the VS Code debugger as normal
License
MIT
| |