[关闭]
@smilence 2020-03-07T13:27:58.000000Z 字数 1956 阅读 1285

Appendix: How to debug Ruby in VS Code

Ruby SDE-Foundations


  1. Search Ruby in Extensions Marketplace in and install that (the 5th icon in left vertical bar)
  2. gem install ruby-debug-ide in any terminal
  3. Click on the bug icon (4th icon) in left bar, and click on the link to "create a launch.json file"
  4. Paste the following into the json file:
  1. {
  2. // Use IntelliSense to learn about possible attributes.
  3. // Hover to view descriptions of existing attributes.
  4. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  5. "version": "0.2.0",
  6. "configurations": [
  7. {
  8. "name": "RSpec - active spec file only",
  9. "type": "Ruby",
  10. "request": "launch",
  11. "program": "/usr/local/bin/rspec",
  12. "args": ["${file}"],
  13. },
  14. {
  15. "name": "Debug Local File",
  16. "type": "Ruby",
  17. "request": "launch",
  18. "cwd":"${workspaceRoot}",
  19. "program": "${file}"
  20. },
  21. ]
  22. }
  1. {
  2. "launch": {
  3. // Use IntelliSense to learn about possible attributes.
  4. // Hover to view descriptions of existing attributes.
  5. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  6. "version": "0.2.0",
  7. "configurations": [
  8. {
  9. "name": "Debug RSpec",
  10. "type": "Ruby",
  11. "request": "launch",
  12. "program": "/Users/april/.rbenv/shims/rspec",
  13. "args": [
  14. "${file}"
  15. ],
  16. },
  17. {
  18. "name": "Debug Ruby",
  19. "type": "Ruby",
  20. "request": "launch",
  21. "cwd": "${workspaceRoot}",
  22. "program": "${file}"
  23. },
  24. {
  25. "type": "node",
  26. "request": "launch",
  27. "name": "Debug JavaScript",
  28. "skipFiles": [
  29. "<node_internals>/**"
  30. ],
  31. "program": "${file}"
  32. }
  33. ],
  34. "window.zoomLevel": 2
  35. },
  36. "editor.fontFamily": "FiraCode-Retina",
  37. "editor.fontLigatures": true,
  38. "window.zoomLevel": 3,
  39. "atomKeymap.promptV3Features": true,
  40. "editor.multiCursorModifier": "ctrlCmd",
  41. "editor.formatOnPaste": true
  42. }

The above steps you only have to do it once, next time you can just select the config "Debug Local File" or from dropdown menu when you open the launch.json
5. Add a breakpoint somewhere in your ruby file (click on the left of the line you want to start debugging with, and there will be red dot), Open the ruby / Rspec file you want to debug on, and then click on the bug icon on left bar
6. Make sure your code has an example rather than just definition, such as p foo(), and then click on the green arrow next to "DEBUG AND RUN" or press F5. Then you can start doing things like "next" "step" "continue"

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注