Skip to content

Commit c411043

Browse files
dentraagners
andauthored
Adds support cpp to vscode (esphome#1828)
Co-authored-by: Stefan Agner <stefan@agner.ch>
1 parent 93f8ee7 commit c411043

File tree

5 files changed

+58
-26
lines changed

5 files changed

+58
-26
lines changed

.devcontainer/devcontainer.json

+31-6
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,56 @@
22
"name": "ESPHome Dev",
33
"context": "..",
44
"dockerFile": "../docker/Dockerfile.dev",
5-
"postCreateCommand": "mkdir -p config && pip3 install -e .",
6-
"runArgs": ["--privileged", "-e", "ESPHOME_DASHBOARD_USE_PING=1"],
5+
"postCreateCommand": [
6+
"script/devcontainer-post-create"
7+
],
8+
"runArgs": [
9+
"--privileged",
10+
"-e",
11+
"ESPHOME_DASHBOARD_USE_PING=1"
12+
],
713
"appPort": 6052,
814
"extensions": [
15+
// python
916
"ms-python.python",
1017
"visualstudioexptteam.vscodeintellicode",
11-
"redhat.vscode-yaml"
18+
// yaml
19+
"redhat.vscode-yaml",
20+
// cpp
21+
"ms-vscode.cpptools",
22+
// editorconfig
23+
"editorconfig.editorconfig",
1224
],
1325
"settings": {
14-
"python.pythonPath": "/usr/local/bin/python",
26+
"python.languageServer": "Pylance",
27+
"python.pythonPath": "/usr/bin/python3",
1528
"python.linting.pylintEnabled": true,
1629
"python.linting.enabled": true,
1730
"python.formatting.provider": "black",
1831
"editor.formatOnPaste": false,
1932
"editor.formatOnSave": true,
2033
"editor.formatOnType": true,
2134
"files.trimTrailingWhitespace": true,
22-
"terminal.integrated.shell.linux": "/bin/bash",
35+
"terminal.integrated.defaultProfile.linux": "/bin/bash",
2336
"yaml.customTags": [
2437
"!secret scalar",
2538
"!lambda scalar",
2639
"!include_dir_named scalar",
2740
"!include_dir_list scalar",
2841
"!include_dir_merge_list scalar",
2942
"!include_dir_merge_named scalar"
30-
]
43+
],
44+
"files.exclude": {
45+
"**/.git": true,
46+
"**/.DS_Store": true,
47+
"**/*.pyc": {
48+
"when": "$(basename).py"
49+
},
50+
"**/__pycache__": true
51+
},
52+
"files.associations": {
53+
"**/.vscode/*.json": "jsonc"
54+
},
55+
"C_Cpp.clang_format_path": "/usr/bin/clang-format-11",
3156
}
3257
}

.editorconfig

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ insert_final_newline = true
77
charset = utf-8
88

99
# python
10-
[*.{py}]
10+
[*.py]
1111
indent_style = space
1212
indent_size = 4
1313

@@ -25,4 +25,10 @@ indent_size = 2
2525
[*.{yaml,yml}]
2626
indent_style = space
2727
indent_size = 2
28-
quote_type = single
28+
quote_type = single
29+
30+
# JSON
31+
[*.json]
32+
indent_style = space
33+
indent_size = 2
34+

docker/Dockerfile.dev

+1-13
Original file line numberDiff line numberDiff line change
@@ -1,13 +1 @@
1-
FROM esphome/esphome-base-amd64:3.4.0
2-
3-
COPY . .
4-
5-
RUN apt-get update \
6-
&& apt-get install -y --no-install-recommends \
7-
python3-wheel \
8-
net-tools \
9-
&& apt-get clean \
10-
&& rm -rf /var/lib/apt/lists/*
11-
12-
WORKDIR /workspaces
13-
ENV SHELL /bin/bash
1+
FROM esphome/esphome-lint:1.1

script/bump-docker-base-version.py

-5
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ def write_version(version: str):
2828
r"ARG BUILD_FROM=esphome/esphome-base-amd64:.*",
2929
f"ARG BUILD_FROM=esphome/esphome-base-amd64:{version}",
3030
)
31-
sub(
32-
"docker/Dockerfile.dev",
33-
r"FROM esphome/esphome-base-amd64:.*",
34-
f"FROM esphome/esphome-base-amd64:{version}",
35-
)
3631
sub(
3732
"docker/Dockerfile.lint",
3833
r"FROM esphome/esphome-lint-base:.*",

script/devcontainer-post-create

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
set -e
4+
# set -x
5+
6+
mkdir -p config
7+
pip3 install -e .
8+
9+
cpp_json=.vscode/c_cpp_properties.json
10+
if [ ! -f $cpp_json ]; then
11+
echo "Initializing PlatformIO..."
12+
pio init --ide vscode --silent
13+
sed -i "/\\/workspaces\/esphome\/include/d" $cpp_json
14+
else
15+
echo "Cpp environment already configured. To reconfigure it you could run one the following commands:"
16+
echo " pio init --ide vscode -e livingroom8266"
17+
echo " pio init --ide vscode -e livingroom32"
18+
fi

0 commit comments

Comments
 (0)