This is a VS Code extension that adds a "SiFive test" button to the right-click context menu when editing JSON and JSON5 files. This extension allows users to validate the content of their JSON and JSON5 files directly from the editor. If the content is valid, it prints the key-value pairs to the debug console; otherwise, it displays an error message indicating the issue.
- Context Menu Integration: Adds a
SiFive test
option to the right-click context menu for .json and .json5 files. - JSON and JSON5 Support: Validates both JSON and JSON5 file formats.
- Error Handling: Displays error messages in a modal dialog if the content is invalid.
- Debug Logging: Prints key-value pairs of valid JSON/JSON5 content to the debug console.
- Node.js and npm: v20+ recommended
- Visual Studio Code
- esbuild Problem Matchers (VS Code extension): Allows you to see compilation errors directly in VS Code, facilitating easier debugging during development.
- JSON5 syntax (VS Code extension): (Optional) Adds syntax highlighting of JSON5 files in VS Code.
-
Clone the Repository
git clone https://github.com/andyhsu10/sifive-json-vscode-extension.git cd sifive-json-vscode-extension
-
Install Dependencies
npm install
-
Compile the extension
npm run compile
To test and run the extension in Visual Studio Code:
-
Open the Extension Project in VS Code
code .
-
Start Debugging
- Press
F5
to launch the extension in a new Extension Development Host window.
- Press
-
Test the Extension
- In the new window, open or create a
.json
or.json5
file. You can find some sample files under the foldersamples
. - Right-click anywhere in the editor to bring up the context menu.
- Click on SiFive test.
- If the JSON is valid:
- An information message will appear:
JSON is valid. Key-value pairs logged to debug console.
- Key-value pairs will be printed in the Debug Console.
- An information message will appear:
- If the JSON is invalid:
- An error message will appear detailing the parsing error.
- In the new window, open or create a
Screen.Recording.2024-10-03.at.00.21.27.mp4
- Support for JSONC: Extend validation support to include JSON with Comments (
.jsonc
) files. - Error Highlighting: Integrate with the editor to highlight the exact location of syntax errors within the JSON file.
- Formatting Features: Add options to format and beautify JSON content directly from the context menu.
- Configuration Settings: Allow users to customize extension behavior through VS Code settings, such as enabling/disabling certain features.
- Performance Optimization: Improve the parsing and validation performance for large JSON files.