astro-openvscode-inspector
v1.5.0
Published
VSCode inspector integration for Astro DevToolbar - Open files directly from browser. Cross-platform support for Windows, macOS, and Linux
Maintainers
Readme
Astro VSCode Inspector
A seamless integration between Astro's DevToolbar and VSCode that allows you to open files directly from your browser during development.
Features
- 🎯 Click to open - Click on any component to open it in VSCode
- 🖱️ Smart tooltip - Hover to see component information with beautiful floating tooltips
- 🎨 Visual highlighting - Clear visual feedback when hovering over components
- ⚡ Automatic detection - Finds inspector elements up to 20 levels deep
- 🔄 Auto-close - Inspector mode automatically closes after opening a file
- 🌍 Cross-platform - Works on Windows, macOS, and Linux
Installation
# requirements
npm install @react-dev-inspector/babel-plugin vite npm install astro-openvscode-inspectorDependencies
This package requires: vite @react-dev-inspector/babel-plugin
Usage
Add the integration to your astro.config.mjs:
import { defineConfig } from "astro/config";
import astroVSCodeInspector from "astro-openvscode-inspector";
import { loadEnv } from "vite";
const { PROJECT_FOLDER } = loadEnv(process.env.NODE_ENV, process.cwd(), "");
export default defineConfig({
integrations: [
react(
isDev
? { babel: { plugins: ["@react-dev-inspector/babel-plugin"] } }
: {},
),
isDev && astroVSCodeInspector({ projectFolder: PROJECT_FOLDER }),
],
});Environment Variables
Make sure to set the project folder path in your .env:
Windows:
PUBLIC_PROJECT_FOLDER=C:/Users/username/project
# or
PUBLIC_PROJECT_FOLDER=C:\\Users\\username\\projectmacOS/Linux:
PUBLIC_PROJECT_FOLDER=/Users/username/projectThe library automatically detects your operating system and handles path formatting correctly.
How it works
- Click the VSCode icon in the Astro DevToolbar
- Hover over components to see detailed tooltips with file information
- Click on any component to open the corresponding file in VSCode at the exact line
- Inspector mode automatically deactivates after opening a file
Platform Support
✅ Windows - Fully supported with automatic path normalization
✅ macOS - Fully supported with automatic OS detection
✅ Linux - Fully supported
The library automatically detects your operating system and formats paths correctly for the vscode:// protocol handler.
Troubleshooting
VS Code doesn't open when clicking
- Make sure VS Code is installed and the
codecommand is available - Verify that
PUBLIC_PROJECT_FOLDERis set correctly in your.envfile - Check browser console for error messages
- Ensure the path format matches your OS (see Environment Variables section)
Wrong file or path errors
- Windows: Use forward slashes (
C:/Users/...) or escaped backslashes (C:\\Users\\...) - macOS/Linux: Use absolute paths starting with
/(e.g.,/Users/...or/home/...)
Inspector not working
- Make sure you have the
@react-dev-inspector/babel-plugininstalled and configured - Check that the integration is only enabled in development mode
- Verify that your components have the inspector data attributes
