visual_studio_code.rst 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. .. tabs::
  27. .. code-tab:: js LinuxBSD
  28. {
  29. "label": "build",
  30. "group": "build",
  31. "type": "shell",
  32. "command": "scons",
  33. "args": [
  34. "-j",
  35. "$(nproc)",
  36. // enable for debugging with breakpoints
  37. "dev_build=yes",
  38. ],
  39. "problemMatcher": "$msCompile"
  40. }
  41. .. code-tab:: js Windows
  42. {
  43. "label": "build",
  44. "group": "build",
  45. "type": "shell",
  46. "command": "scons",
  47. "args": [
  48. // Use this when your default shell is Command Prompt (cmd.exe).
  49. "-j %NUMBER_OF_PROCESSORS%",
  50. // Use this when your default shell is PowerShell.
  51. "-j $env:NUMBER_OF_PROCESSORS",
  52. "dev_build=yes",
  53. ],
  54. "problemMatcher": "$msCompile"
  55. }
  56. .. figure:: img/vscode_3_tasks.json.png
  57. :figclass: figure-w480
  58. :align: center
  59. An example of a filled out ``tasks.json``.
  60. Arguments can be different based on your own setup and needs. See
  61. :ref:`doc_introduction_to_the_buildsystem` for a full list of arguments.
  62. Debugging the project
  63. ---------------------
  64. To run and debug the project you need to create a new configuration in the ``launch.json`` file.
  65. - Press :kbd:`Ctrl + Shift + D` to open the Run panel.
  66. - If ``launch.json`` file is missing you will be prompted to create a new one.
  67. .. figure:: img/vscode_1_create_launch.json.png
  68. :align: center
  69. - Select **C++ (GDB/LLDB)**. There may be another platform specific option here. If selected,
  70. adjust the configuration example provided accordingly.
  71. - Within the ``launch.json`` file find the ``"configurations"`` array and add a new section to it:
  72. .. tabs::
  73. .. code-tab:: js LinuxBSD
  74. {
  75. "name": "Launch Project",
  76. "type": "lldb",
  77. "request": "launch",
  78. // Change to godot.linuxbsd.tools.64.llvm for llvm-based builds.
  79. "program": "${workspaceFolder}/bin/godot.linuxbsd.editor.dev.x86_64",
  80. // Change the arguments below for the project you want to test with.
  81. // To run the project instead of editing it, remove the "--editor" argument.
  82. "args": [ "--editor", "--path", "path-to-your-godot-project-folder" ],
  83. "stopAtEntry": false,
  84. "cwd": "${workspaceFolder}",
  85. "environment": [],
  86. "externalConsole": false,
  87. "preLaunchTask": "build"
  88. }
  89. .. code-tab:: js LinuxBSD_gdb
  90. {
  91. "name": "Launch Project",
  92. "type": "cppdbg",
  93. "request": "launch",
  94. // Change to godot.linuxbsd.tools.64.llvm for llvm-based builds.
  95. "program": "${workspaceFolder}/bin/godot.linuxbsd.editor.dev.x86_64",
  96. // Change the arguments below for the project you want to test with.
  97. // To run the project instead of editing it, remove the "--editor" argument.
  98. "args": [ "--editor", "--path", "path-to-your-godot-project-folder" ],
  99. "stopAtEntry": false,
  100. "cwd": "${workspaceFolder}",
  101. "environment": [],
  102. "externalConsole": false,
  103. "setupCommands":
  104. [
  105. {
  106. "description": "Enable pretty-printing for gdb",
  107. "text": "-enable-pretty-printing",
  108. "ignoreFailures": true
  109. }
  110. ],
  111. "preLaunchTask": "build"
  112. }
  113. .. code-tab:: js Windows
  114. {
  115. "name": "Launch Project",
  116. "type": "cppvsdbg",
  117. "request": "launch",
  118. "program": "${workspaceFolder}/bin/godot.windows.editor.dev.x86_64.exe",
  119. // Change the arguments below for the project you want to test with.
  120. // To run the project instead of editing it, remove the "--editor" argument.
  121. "args": [ "--editor", "--path", "path-to-your-godot-project-folder" ],
  122. "stopAtEntry": false,
  123. "cwd": "${workspaceFolder}",
  124. "environment": [],
  125. "console": "internalConsole",
  126. "visualizerFile": "${workspaceFolder}/platform/windows/godot.natvis",
  127. "preLaunchTask": "build"
  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. ``platform=editor`` and ``dev_build=yes``.
  142. If you run into any issues, ask for help in one of
  143. `Godot's community channels <https://godotengine.org/community>`__.
  144. .. tip::
  145. To get linting on class reference XML files, install the
  146. `vscode-xml extension <https://marketplace.visualstudio.com/items?itemName=redhat.vscode-xml>`__.