Monday, September 27, 2021

Debugging in VS Code

I have a debug environment set in PhpStorm, but since I started using VS Code for ES6 version of Qedy, I was lazy to fire up the other IDE just to debug a problem.

One day I was fed up by only using debugger statement, so I decided to set up debugging in VS Code as well.

JavaScript

I installed “Debugger for Microsoft Edge” extension by Microsoft.

I wanted to attach the debugger to my Edge Dev I'm already using, but most tutorials expect to launch a new browser every time.

Launch Edge with --remote-debugging-port=9222

Brilliant idea are conditions for keyboard shortcuts, I can use F5 for both Debug/Restart (when: inDebugMode && debugState == 'stopped') and Debug/Continue (when: debugState == 'stopped').

PHP

I installed “PHP Debug” extension by Xdebug.

settings.json

  1. "php.validate.executablePath": "C:/php/php.exe",

launch.json

  1. {
  2. "version": "0.2.0",
  3. "configurations": [
  4. {
  5. "name": "PHP",
  6. "type": "php",
  7. "request": "launch",
  8. "port": 9003
  9. }, {
  10. "name": "Edge",
  11. "request": "attach",
  12. "type": "edge",
  13. "runtimeExecutable": "dev",
  14. "port": 9222,
  15. "webRoot": "${workspaceFolder}/src/js",
  16. }
  17. ]
  18. }
Tuesday, September 15, 2020

Colored text in VS Code Terminal

Most terminals allow to print colored text and the default Terminal in VS Code (based on PowerShell) is no exception.

  1. console.error("\033[91m" + ev.stack + "\033[0m");

asdf

  1. SyntaxError: Octal escape sequences are not allowed in strict mode.

asdf

  1. console.error("\x1B[91m" + ev.stack + "\x1B[0m");

asdf

Tuesday, April 28, 2020

VS Code and Node.js

Install Node.js from official web.

Nodemon

Install nodemon:

  1. npm install -g nodemon

launch.json

  1. { "configurations": [ { "console": "integratedTerminal", "internalConsoleOptions": "neverOpen", "name": "nodemon", "program": "${workspaceFolder}/qetrix.js", "request": "launch", "restart": true, "runtimeExecutable": "nodemon", "skipFiles": [ "<node_internals>/**" ], "type": "pwa-node" } ] }

When I debugged the router and module init, I wanted to run it immediately after nodemon restarted, so simply I added a HTTP GET call right into server.listen function:

  1. http.get("http://127.0.0.1:3000/subject");

In VS Code you don't even need to hunt for extensions, “Node Debug” is already built-in.

I have to admit, it's quite joyous to work like that. I really like the simplicity of PHP and this isn't actually that far off.

asdf