visual_studio_code.rst 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. .. _doc_configuring_an_ide_vscode:
  2. Visual Studio Code
  3. ==================
  4. `Visual Studio Code <https://code.visualstudio.com>`_ is a free cross-platform code editor
  5. by `Microsoft <https://microsoft.com>`_ (not to be confused with :ref:`doc_configuring_an_ide_vs`).
  6. Importing the project
  7. ---------------------
  8. - Make sure the C/C++ extension is installed. You can find instructions in
  9. the `official documentation <https://code.visualstudio.com/docs/languages/cpp>`_.
  10. - From the Visual Studio Code's main screen open the Godot root folder with
  11. **File > Open Folder...**.
  12. - Press :kbd:`Ctrl + Shift + P` to open the command prompt window and enter *Configure Task*.
  13. .. figure:: img/vscode_configure_task.png
  14. :align: center
  15. - Select the **Create tasks.json file from template** option.
  16. .. figure:: img/vscode_create_tasksjson.png
  17. :align: center
  18. - Then select **Others**.
  19. .. figure:: img/vscode_create_tasksjson_others.png
  20. :align: center
  21. - Within the ``tasks.json`` file find the ``"tasks"`` array and add a new section to it:
  22. .. tabs::
  23. .. code-tab:: js Linux/X11
  24. {
  25. "label": "build",
  26. "group": "build",
  27. "type": "shell",
  28. "command": "scons",
  29. "args": [
  30. "-j $(nproc)"
  31. ],
  32. "problemMatcher": "$msCompile"
  33. }
  34. .. code-tab:: js Windows
  35. {
  36. "label": "build",
  37. "group": "build",
  38. "type": "shell",
  39. "command": "scons",
  40. "args": [
  41. // Use this when your default shell is Command Prompt (cmd.exe).
  42. "-j %NUMBER_OF_PROCESSORS%",
  43. // Use this when your default shell is PowerShell.
  44. "-j $env:NUMBER_OF_PROCESSORS"
  45. ],
  46. "problemMatcher": "$msCompile"
  47. }
  48. .. figure:: img/vscode_3_tasks.json.png
  49. :figclass: figure-w480
  50. :align: center
  51. An example of a filled out ``tasks.json``.
  52. Arguments can be different based on your own setup and needs. See
  53. :ref:`doc_introduction_to_the_buildsystem` for a full list of arguments.
  54. Debugging the project
  55. ---------------------
  56. To run and debug the project you need to create a new configuration in the ``launch.json`` file.
  57. - Press :kbd:`Ctrl + Shift + D` to open the Run panel.
  58. - If ``launch.json`` file is missing you will be prompted to create a new one.
  59. .. figure:: img/vscode_1_create_launch.json.png
  60. :align: center
  61. - Select **C++ (GDB/LLDB)**. There may be another platform specific option here. If selected,
  62. adjust the configuration example provided accordingly.
  63. - Within the ``launch.json`` file find the ``"configurations"`` array and add a new section to it:
  64. .. tabs::
  65. .. code-tab:: js Linux/X11
  66. {
  67. "name": "Launch Project",
  68. "type": "cppdbg",
  69. "request": "launch",
  70. "program": "${workspaceFolder}/bin/godot.x11.tools.64",
  71. // Change the arguments below for the project you want to test with.
  72. // To run the project instead of editing it, remove the "--editor" argument.
  73. "args": [ "--editor", "--path", "path-to-your-godot-project-folder" ],
  74. "stopAtEntry": false,
  75. "cwd": "${workspaceFolder}",
  76. "environment": [],
  77. "externalConsole": true,
  78. "MIMode": "gdb",
  79. "setupCommands": [
  80. {
  81. "description": "Enable pretty-printing for gdb",
  82. "text": "-enable-pretty-printing",
  83. "ignoreFailures": true
  84. }
  85. ],
  86. "preLaunchTask": "build"
  87. }
  88. .. code-tab:: js Windows
  89. {
  90. "name": "Launch Project",
  91. "type": "cppvsdbg",
  92. "request": "launch",
  93. "program": "${workspaceFolder}/bin/godot.windows.tools.64.exe",
  94. // Change the arguments below for the project you want to test with.
  95. // To run the project instead of editing it, remove the "--editor" argument.
  96. "args": [ "--editor", "--path", "path-to-your-godot-project-folder" ],
  97. "stopAtEntry": false,
  98. "cwd": "${workspaceFolder}",
  99. "environment": [],
  100. "console": "internalConsole",
  101. "visualizerFile": "${workspaceFolder}/platform/windows/godot.natvis",
  102. "preLaunchTask": "build"
  103. }
  104. .. figure:: img/vscode_2_launch.json.png
  105. :figclass: figure-w480
  106. :align: center
  107. An example of a filled out ``launch.json``.
  108. The name under ``program`` depends on your build configuration,
  109. e.g. ``godot.x11.tools.64`` for 64-bit X11 platform with ``tools`` enabled.
  110. If you run into any issues, ask for help in one of
  111. `Godot's community channels <https://godotengine.org/community>`__.