visual_studio_code.rst 8.4 KB

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