visual_studio_code.rst 5.1 KB

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