VS Code WebSocket Extension
This extension allows you to open prompt and alert popups in VS Code using websockets.
Features
- Show alert popup
- Show prompt popup
Recommended Usage
Use together with the vscode-websocket-alerts package.
const { alert, prompt } = require('vscode-websocket-alerts');
let x = prompt('Enter a number');
alert(`You entered: ${x}`);
Manual Usage
- Install the extension.
- Connect to the WebSocket server:
const WebSocket = require('ws');
// Connect to the WebSocket server
const ws = new WebSocket('ws://localhost:8121');
- Send a command when the connection is open:
ws.on('open', () => {
const alertMessage = { command: 'extension.showAlert', args: { message: 'Hello from Node.js!' } };
ws.send(JSON.stringify(alertMessage));
const promptMessage = {
command: 'extension.showPrompt',
args: {
promptText: 'Please enter something:',
callbackId: 1 // Assuming callback handling if needed
}
};
ws.send(JSON.stringify(promptMessage));
});
- Handle responses from the WebSocket server:
ws.on('message', (data) => {
const response = JSON.parse(data);
console.log('Response from VS Code extension:', response);
});
- Enjoy!
| |