visual_studio_code.rst 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. Alternatively, `clangd <https://open-vsx.org/extension/llvm-vs-code-extensions/vscode-clangd>`_
  11. can be used instead.
  12. - When using the clangd extension, run ``scons compiledb=yes``.
  13. - From the Visual Studio Code's main screen open the Godot root folder with
  14. **File > Open Folder...**.
  15. - Press :kbd:`Ctrl + Shift + P` to open the command prompt window and enter *Configure Task*.
  16. .. figure:: img/vscode_configure_task.png
  17. :align: center
  18. - Select the **Create tasks.json file from template** option.
  19. .. figure:: img/vscode_create_tasksjson.png
  20. :align: center
  21. - Then select **Others**.
  22. .. figure:: img/vscode_create_tasksjson_others.png
  23. :align: center
  24. - If there is no such option as **Create tasks.json file from template** available, either delete the file if it already exists in your folder or create a ``.vscode/tasks.json`` file manually. See `Tasks in Visual Studio Code <https://code.visualstudio.com/docs/editor/tasks#_custom-tasks>`_ for more details on tasks.
  25. - Within the ``tasks.json`` file find the ``"tasks"`` array and add a new section to it:
  26. .. code-block:: js
  27. :caption: .vscode/tasks.json
  28. {
  29. "label": "build",
  30. "group": "build",
  31. "type": "shell",
  32. "command": "scons",
  33. "args": [
  34. // enable for debugging with breakpoints
  35. "dev_build=yes",
  36. ],
  37. "problemMatcher": "$msCompile"
  38. }
  39. .. figure:: img/vscode_3_tasks.json.png
  40. :figclass: figure-w480
  41. :align: center
  42. An example of a filled out ``tasks.json``.
  43. Arguments can be different based on your own setup and needs. See
  44. :ref:`doc_introduction_to_the_buildsystem` for a full list of arguments.
  45. Debugging the project
  46. ---------------------
  47. To run and debug the project you need to create a new configuration in the ``launch.json`` file.
  48. - Press :kbd:`Ctrl + Shift + D` to open the Run panel.
  49. - If ``launch.json`` file is missing you will be prompted to create a new one.
  50. .. figure:: img/vscode_1_create_launch.json.png
  51. :align: center
  52. - Select **C++ (GDB/LLDB)**. There may be another platform-specific option here. If selected,
  53. adjust the configuration example provided accordingly.
  54. - Within the ``launch.json`` file find the ``"configurations"`` array and add a new section to it:
  55. .. tabs::
  56. .. code-tab:: js LinuxBSD
  57. {
  58. "name": "Launch Project",
  59. "type": "lldb",
  60. "request": "launch",
  61. // Change to godot.linuxbsd.editor.dev.x86_64.llvm for llvm-based builds.
  62. "program": "${workspaceFolder}/bin/godot.linuxbsd.editor.dev.x86_64",
  63. // Change the arguments below for the project you want to test with.
  64. // To run the project instead of editing it, remove the "--editor" argument.
  65. "args": [ "--editor", "--path", "path-to-your-godot-project-folder" ],
  66. "stopAtEntry": false,
  67. "cwd": "${workspaceFolder}",
  68. "environment": [],
  69. "externalConsole": false,
  70. "preLaunchTask": "build"
  71. }
  72. .. code-tab:: js LinuxBSD_gdb
  73. {
  74. "name": "Launch Project",
  75. "type": "cppdbg",
  76. "request": "launch",
  77. // Change to godot.linuxbsd.editor.dev.x86_64.llvm for llvm-based builds.
  78. "program": "${workspaceFolder}/bin/godot.linuxbsd.editor.dev.x86_64",
  79. // Change the arguments below for the project you want to test with.
  80. // To run the project instead of editing it, remove the "--editor" argument.
  81. "args": [ "--editor", "--path", "path-to-your-godot-project-folder" ],
  82. "stopAtEntry": false,
  83. "cwd": "${workspaceFolder}",
  84. "environment": [],
  85. "externalConsole": false,
  86. "setupCommands":
  87. [
  88. {
  89. "description": "Enable pretty-printing for gdb",
  90. "text": "-enable-pretty-printing",
  91. "ignoreFailures": true
  92. },
  93. {
  94. "description": "Load custom pretty-printers for Godot types.",
  95. "text": "source ${workspaceRoot}/misc/utility/godot_gdb_pretty_print.py"
  96. }
  97. ],
  98. "preLaunchTask": "build"
  99. }
  100. .. code-tab:: js Windows
  101. {
  102. "name": "Launch Project",
  103. "type": "cppvsdbg",
  104. "request": "launch",
  105. "program": "${workspaceFolder}/bin/godot.windows.editor.dev.x86_64.exe",
  106. // Change the arguments below for the project you want to test with.
  107. // To run the project instead of editing it, remove the "--editor" argument.
  108. "args": [ "--editor", "--path", "path-to-your-godot-project-folder" ],
  109. "stopAtEntry": false,
  110. "cwd": "${workspaceFolder}",
  111. "environment": [],
  112. "console": "internalConsole",
  113. "visualizerFile": "${workspaceFolder}/platform/windows/godot.natvis",
  114. "preLaunchTask": "build"
  115. }
  116. .. code-tab:: js Mac
  117. {
  118. "name": "Launch Project",
  119. "type": "lldb",
  120. "request": "custom",
  121. "targetCreateCommands": [
  122. "target create ${workspaceFolder}/bin/godot.macos.editor.dev.x86_64"
  123. ],
  124. // Change the arguments below for the project you want to test with.
  125. // To run the project instead of editing it, remove the "--editor" argument.
  126. "processCreateCommands": [
  127. "process launch -- --editor --path path-to-your-godot-project-folder"
  128. ]
  129. }
  130. .. figure:: img/vscode_2_launch.json.png
  131. :figclass: figure-w480
  132. :align: center
  133. An example of a filled out ``launch.json``.
  134. .. note::
  135. Due to sporadic performance issues, it is recommended to use LLDB over GDB on Unix-based systems.
  136. Make sure that the `CodeLLDB extension <https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb>`_
  137. is installed.
  138. If you encounter issues with lldb, you may consider using gdb (see the LinuxBSD_gdb configuration).
  139. Do note that lldb may work better with LLVM-based builds. See :ref:`doc_compiling_for_linuxbsd` for further information.
  140. The name under ``program`` depends on your build configuration,
  141. e.g. ``godot.linuxbsd.editor.dev.x86_64`` for 64-bit LinuxBSD platform with
  142. ``target=editor`` and ``dev_build=yes``.
  143. Configuring Intellisense
  144. ------------------------
  145. For the C/C++ extension:
  146. To fix include errors you may be having, you need to configure some settings in the ``c_cpp_properties.json`` file.
  147. - First, make sure to build the project since some files need to be generated.
  148. - Edit the C/C++ Configuration file either with the UI or with text:
  149. .. figure:: img/vscode_edit_configurations.webp
  150. :align: center
  151. - Add an include path for your platform, for example, ``${workspaceFolder}/platform/windows``.
  152. - Add defines for the editor ``TOOLS_ENABLED``, debug builds ``DEBUG_ENABLED``, and tests ``TESTS_ENABLED``.
  153. - Make sure the compiler path is configured correctly to the compiler you are using. See :ref:`doc_introduction_to_the_buildsystem` for further information on your platform.
  154. - The ``c_cpp_properties.json`` file should look similar to this for Windows:
  155. .. code-block:: js
  156. :caption: .vscode/c_cpp_properties.json
  157. {
  158. "configurations": [
  159. {
  160. "name": "Win32",
  161. "includePath": [
  162. "${workspaceFolder}/**",
  163. "${workspaceFolder}/platform/windows"
  164. ],
  165. "defines": [
  166. "_DEBUG",
  167. "UNICODE",
  168. "_UNICODE",
  169. "TOOLS_ENABLED",
  170. "DEBUG_ENABLED",
  171. "TESTS_ENABLED"
  172. ],
  173. "windowsSdkVersion": "10.0.22621.0",
  174. "compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.39.33519/bin/Hostx64/x64/cl.exe",
  175. "cStandard": "c17",
  176. "cppStandard": "c++17",
  177. "intelliSenseMode": "windows-msvc-x64"
  178. }
  179. ],
  180. "version": 4
  181. }
  182. - Alternatively, you can use the scons argument ``compiledb=yes`` and set the compile commands setting ``compileCommands`` to ``compile_commands.json``, found in the advanced section of the C/C++ Configuration UI.
  183. - This argument can be added to your build task in ``tasks.json`` since it will need to be run whenever files are added or moved.
  184. If you run into any issues, ask for help in one of
  185. `Godot's community channels <https://godotengine.org/community>`__.
  186. .. tip::
  187. To get linting on class reference XML files, install the
  188. `vscode-xml extension <https://marketplace.visualstudio.com/items?itemName=redhat.vscode-xml>`__.