visual_studio_code.rst 6.0 KB

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