visual_studio_code.rst 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 X11
  66. {
  67. "name": "Launch Project",
  68. "type": "lldb",
  69. "request": "launch",
  70. // Change to godot.x11.tools.64.llvm for llvm-based builds.
  71. "program": "${workspaceFolder}/bin/godot.x11.tools.64",
  72. // Change the arguments below for the project you want to test with.
  73. // To run the project instead of editing it, remove the "--editor" argument.
  74. "args": [ "--editor", "--path", "path-to-your-godot-project-folder" ],
  75. "stopAtEntry": false,
  76. "cwd": "${workspaceFolder}",
  77. "environment": [],
  78. "externalConsole": false,
  79. "preLaunchTask": "build"
  80. }
  81. .. code-tab:: js X11_gdb
  82. {
  83. "name": "Launch Project",
  84. "type": "cppdbg",
  85. "request": "launch",
  86. // Change to godot.x11.tools.64.llvm for llvm-based builds.
  87. "program": "${workspaceFolder}/bin/godot.x11.tools.64",
  88. // Change the arguments below for the project you want to test with.
  89. // To run the project instead of editing it, remove the "--editor" argument.
  90. "args": [ "--editor", "--path", "path-to-your-godot-project-folder" ],
  91. "stopAtEntry": false,
  92. "cwd": "${workspaceFolder}",
  93. "environment": [],
  94. "externalConsole": false,
  95. "setupCommands":
  96. [
  97. {
  98. "description": "Enable pretty-printing for gdb",
  99. "text": "-enable-pretty-printing",
  100. "ignoreFailures": true
  101. }
  102. ],
  103. "preLaunchTask": "build"
  104. }
  105. .. code-tab:: js Windows
  106. {
  107. "name": "Launch Project",
  108. "type": "cppvsdbg",
  109. "request": "launch",
  110. "program": "${workspaceFolder}/bin/godot.windows.tools.64.exe",
  111. // Change the arguments below for the project you want to test with.
  112. // To run the project instead of editing it, remove the "--editor" argument.
  113. "args": [ "--editor", "--path", "path-to-your-godot-project-folder" ],
  114. "stopAtEntry": false,
  115. "cwd": "${workspaceFolder}",
  116. "environment": [],
  117. "console": "internalConsole",
  118. "visualizerFile": "${workspaceFolder}/platform/windows/godot.natvis",
  119. "preLaunchTask": "build"
  120. }
  121. .. figure:: img/vscode_2_launch.json.png
  122. :figclass: figure-w480
  123. :align: center
  124. An example of a filled out ``launch.json``.
  125. .. note::
  126. Due to sporadic performance issues, it is recommended to use LLDB over GDB on Unix-based systems.
  127. Make sure that the `CodeLLDB extension <https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb>`_
  128. is installed.
  129. If you encounter issues with lldb, you may consider using gdb (see the X11_gdb configuration).
  130. Do note that lldb may work better with llvm-based builds. See :ref:`doc_compiling_for_x11` for further information.
  131. The name under ``program`` depends on your build configuration,
  132. e.g. ``godot.x11.tools.64`` for 64-bit X11 platform with ``tools`` enabled.
  133. If you run into any issues, ask for help in one of
  134. `Godot's community channels <https://godotengine.org/community>`__.