visual_studio_code.rst 6.0 KB

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