Skip to content

Commit b181406

Browse files
committed
Resolve an issue where custom debug configurations were being inadvertently overwritten in VSCode's launch.json // Resolve platformio#4810
1 parent dc16f80 commit b181406

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

HISTORY.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Unlock the true potential of embedded software development with
1717
PlatformIO's collaborative ecosystem, embracing declarative principles,
1818
test-driven methodologies, and modern toolchains for unrivaled success.
1919

20-
6.1.12 (2023-??-??)
20+
6.1.12 (2024-??-??)
2121
~~~~~~~~~~~~~~~~~~~
2222

2323
* Added support for Python 3.12

platformio/project/integration/tpls/vscode/.vscode/launch.json.tpl

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
% import codecs
21
% import json
32
% import os
43
%
@@ -47,9 +46,14 @@
4746
% return data
4847
% end
4948
%
50-
% def _contains_external_configurations(launch_config):
49+
% def _contains_custom_configurations(launch_config):
50+
% pio_config_names = [
51+
% c["name"]
52+
% for c in get_pio_configurations()
53+
% ]
5154
% return any(
5255
% c.get("type", "") != "platformio-debug"
56+
% or c.get("name", "") in pio_config_names
5357
% for c in launch_config.get("configurations", [])
5458
% )
5559
% end
@@ -59,10 +63,14 @@
5963
% return launch_config
6064
% end
6165
%
66+
% pio_config_names = [
67+
% c["name"]
68+
% for c in get_pio_configurations()
69+
% ]
6270
% external_configurations = [
63-
% config
64-
% for config in launch_config["configurations"]
65-
% if config.get("type", "") != "platformio-debug"
71+
% c
72+
% for c in launch_config["configurations"]
73+
% if c.get("type", "") != "platformio-debug" or c.get("name", "") not in pio_config_names
6674
% ]
6775
%
6876
% launch_config["configurations"] = external_configurations
@@ -73,11 +81,11 @@
7381
% launch_config = {"version": "0.2.0", "configurations": []}
7482
% launch_file = os.path.join(project_dir, ".vscode", "launch.json")
7583
% if os.path.isfile(launch_file):
76-
% with codecs.open(launch_file, "r", encoding="utf8") as fp:
84+
% with open(launch_file, "r", encoding="utf8") as fp:
7785
% launch_data = _remove_comments(fp.readlines())
7886
% try:
7987
% prev_config = json.loads(launch_data)
80-
% if _contains_external_configurations(prev_config):
88+
% if _contains_custom_configurations(prev_config):
8189
% launch_config = _remove_pio_configurations(prev_config)
8290
% end
8391
% except:
@@ -91,9 +99,9 @@
9199
%
92100
// AUTOMATICALLY GENERATED FILE. PLEASE DO NOT MODIFY IT MANUALLY
93101
//
94-
// PIO Unified Debugger
102+
// PlatformIO Debugging Solution
95103
//
96-
// Documentation: https://docs.platformio.org/page/plus/debugging.html
97-
// Configuration: https://docs.platformio.org/page/projectconf/section_env_debug.html
104+
// Documentation: https://docs.platformio.org/en/latest/plus/debugging.html
105+
// Configuration: https://docs.platformio.org/en/latest/projectconf/sections/env/options/debug/index.html
98106

99107
{{ json.dumps(get_launch_configuration(), indent=4, ensure_ascii=False) }}

0 commit comments

Comments
 (0)