Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"cmake.generator": "Ninja",
"python.formatting.provider": "black",
"python.analysis.extraPaths": [
"client/python"
"client/python/projectairsim/src"
]
}
}
87 changes: 87 additions & 0 deletions tools/update_blocks_vscode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/usr/bin/env python3
# Copyright (C) 2025 IAMAI CONSULTING CORP
#
# MIT License.

"""Add Project AirSim Python debugging settings to UE-generated Blocks VS Code files."""

import argparse
import json
from pathlib import Path


PYTHON_CONFIGS = [
{
"name": "Python: current script (cwd = script folder)",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"console": "integratedTerminal",
"justMyCode": False,
},
{
"name": "Project AirSim: hello_drone.py",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}\\..\\..\\client\\python\\example_user_scripts\\hello_drone.py",
"cwd": "${workspaceFolder}\\..\\..\\client\\python\\example_user_scripts",
"console": "integratedTerminal",
"justMyCode": False,
},
]

PYTHON_EXTRA_PATH = "../../client/python/projectairsim/src"


def write_json(path: Path, data: dict) -> None:
path.write_text(json.dumps(data, indent=2) + "\n", encoding="utf-8")


def update_launch_json(vscode_dir: Path) -> None:
launch_path = vscode_dir / "launch.json"
launch = json.loads(launch_path.read_text(encoding="utf-8"))
configurations = launch.setdefault("configurations", [])

by_name = {config.get("name"): index for index, config in enumerate(configurations)}
for config in PYTHON_CONFIGS:
existing_index = by_name.get(config["name"])
if existing_index is None:
configurations.append(config)
else:
configurations[existing_index] = config

write_json(launch_path, launch)


def update_settings_json(vscode_dir: Path) -> None:
settings_path = vscode_dir / "settings.json"
if settings_path.exists():
settings = json.loads(settings_path.read_text(encoding="utf-8"))
else:
settings = {}

extra_paths = settings.setdefault("python.analysis.extraPaths", [])
if PYTHON_EXTRA_PATH not in extra_paths:
extra_paths.append(PYTHON_EXTRA_PATH)

write_json(settings_path, settings)


def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument(
"--blocks-dir",
type=Path,
default=Path(__file__).resolve().parents[1] / "unreal" / "Blocks",
help="Path to the Blocks Unreal project directory.",
)
args = parser.parse_args()

vscode_dir = args.blocks_dir.resolve() / ".vscode"
update_launch_json(vscode_dir)
update_settings_json(vscode_dir)


if __name__ == "__main__":
main()
8 changes: 8 additions & 0 deletions unreal/Blocks/blocks_genprojfiles_vscode.bat
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,12 @@ Unreal engine's root folder path, ex. C:\Program Files\Epic Games\UE_5.0
echo !s! >> .vscode\airsimlaunch.json
)
move .vscode\airsimlaunch.json .vscode\launch.json

REM Add Project AirSim Python debugging entries to UE-generated VS Code files.
where python >nul 2>nul
if !ERRORLEVEL! == 0 (
python "%~dp0..\..\tools\update_blocks_vscode.py" --blocks-dir "%~dp0."
) else (
echo:WARNING: python was not found, skipping Project AirSim Python VS Code debug configuration.
)
)
13 changes: 12 additions & 1 deletion unreal/Blocks/blocks_genprojfiles_vscode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,15 @@ else
# Fix UE's generated game target binary names from UnrealGame to the project name in launch.json
sed -i "s/UnrealGame-/$PROJECT_NAME-/g" .vscode/launch.json
sed -i "s/UnrealGame\"/$PROJECT_NAME\"/g" .vscode/launch.json
fi

# Add Project AirSim Python debugging entries to UE-generated VS Code files.
if command -v python3 >/dev/null 2>&1
then
python3 "$SCRIPTDIR/../../tools/update_blocks_vscode.py" --blocks-dir "$SCRIPTDIR"
elif command -v python >/dev/null 2>&1
then
python "$SCRIPTDIR/../../tools/update_blocks_vscode.py" --blocks-dir "$SCRIPTDIR"
else
echo "WARNING: python was not found, skipping Project AirSim Python VS Code debug configuration."
fi
fi
Loading