Visual Studio Code

Visual Studio Code <https://code.visualstudio.com&gt; _是 Microsoft <https://microsoft.com&gt; _推出的免费跨平台代码编辑器(不要与 Visual Studio 混淆).

导入项目

  • 确保C/C++扩展已经安装. 你可以在 官方文件 中找到说明.

  • 现在在VS Code中打开克隆的godot文件夹 文件 > 打开文件夹… .

  • 按Ctrl + Shift + P打开命令提示符窗口, 然后输入 Configure Task.

../../../_images/vscode_configure_task.png

  • 选择从模板中创建tasks.json文件选项.

../../../_images/vscode_create_tasksjson.png

  • 然后选择 “其他”.

../../../_images/vscode_create_tasksjson_others.png

  • tasks.json 文件中找到 "tasks" 数组, 并在其中添加一个新部分:

Linux/X11

Windows

  1. {
  2. "label": "build",
  3. "group": "build",
  4. "type": "shell",
  5. "command": "scons",
  6. "args": [
  7. "-j $(nproc)"
  8. ],
  9. "problemMatcher": "$msCompile"
  10. }
  1. {
  2. "label": "build",
  3. "group": "build",
  4. "type": "shell",
  5. "command": "scons",
  6. "args": [
  7. // Use this when your default shell is Command Prompt (cmd.exe).
  8. "-j %NUMBER_OF_PROCESSORS%",
  9. // Use this when your default shell is PowerShell.
  10. "-j $env:NUMBER_OF_PROCESSORS"
  11. ],
  12. "problemMatcher": "$msCompile"
  13. }

../../../_images/vscode_3_tasks.json.png

填好了 tasks.json 的一个例子.

参数可以根据你自己的设置和需要而不同. 参见 构建系统介绍 以获取完整的参数列表.

调试项目

为了构建项目, 我们需要配置文件 launch.json.

  • 按Ctrl + Shift + D打开 运行 面板.

  • 如果缺少 launch.json 文件, 系统会提示你创建一个新的文件.

../../../_images/vscode_1_create_launch.json.png

  • 选择 C++ (GDB/LLDB) . 这里可能还有其他特定平台的选项. 如果选择了, 请相应调整所提供的配置示例.

  • launch.json 文件中找到 "configurations" 数组, 并添加一个新部分:

X11

X11_gdb

Windows

  1. {
  2. "name": "Launch Project",
  3. "type": "lldb",
  4. "request": "launch",
  5. // Change to godot.x11.tools.64.llvm for llvm-based builds.
  6. "program": "${workspaceFolder}/bin/godot.x11.tools.64",
  7. // Change the arguments below for the project you want to test with.
  8. // To run the project instead of editing it, remove the "--editor" argument.
  9. "args": [ "--editor", "--path", "path-to-your-godot-project-folder" ],
  10. "stopAtEntry": false,
  11. "cwd": "${workspaceFolder}",
  12. "environment": [],
  13. "externalConsole": false,
  14. "preLaunchTask": "build"
  15. }
  1. {
  2. "name": "Launch Project",
  3. "type": "cppdbg",
  4. "request": "launch",
  5. // Change to godot.x11.tools.64.llvm for llvm-based builds.
  6. "program": "${workspaceFolder}/bin/godot.x11.tools.64",
  7. // Change the arguments below for the project you want to test with.
  8. // To run the project instead of editing it, remove the "--editor" argument.
  9. "args": [ "--editor", "--path", "path-to-your-godot-project-folder" ],
  10. "stopAtEntry": false,
  11. "cwd": "${workspaceFolder}",
  12. "environment": [],
  13. "externalConsole": false,
  14. "setupCommands":
  15. [
  16. {
  17. "description": "Enable pretty-printing for gdb",
  18. "text": "-enable-pretty-printing",
  19. "ignoreFailures": true
  20. }
  21. ],
  22. "preLaunchTask": "build"
  23. }
  1. {
  2. "name": "Launch Project",
  3. "type": "cppvsdbg",
  4. "request": "launch",
  5. "program": "${workspaceFolder}/bin/godot.windows.tools.64.exe",
  6. // Change the arguments below for the project you want to test with.
  7. // To run the project instead of editing it, remove the "--editor" argument.
  8. "args": [ "--editor", "--path", "path-to-your-godot-project-folder" ],
  9. "stopAtEntry": false,
  10. "cwd": "${workspaceFolder}",
  11. "environment": [],
  12. "console": "internalConsole",
  13. "visualizerFile": "${workspaceFolder}/platform/windows/godot.natvis",
  14. "preLaunchTask": "build"
  15. }

../../../_images/vscode_2_launch.json.png

填写好的 launch.json 的例子.

注解

由于偶然的性能问题,建议在基于Unix的系统上使用LLDB而不是GDB。确保 CodeLLDB extension 已经安装。

如果遇到lldb的问题,你可以考虑使用gdb,参阅X11_gdb配置。

请注意,lldb可能在基于llvm的构建中工作得更好。参阅 为 X11 平台编译(Linux、*BSD 操作系统) 以了解更多信息。

program [程序]下的名称取决于你的构建配置, 例如启用 tools 的64位X11平台 godot.x11.tools.64 .

如果遇到问题, 也可在 Godot 社区论坛 中寻求帮助.