Skip to content

Commit 62f6fc8

Browse files
committed
jedi: fix code completion for Color and Icon
The pybricks.parameters.Color and Icon types were not working with Jedi for code completion since the constants were never assigned a value.
1 parent d2b1b21 commit 62f6fc8

File tree

4 files changed

+210
-43
lines changed

4 files changed

+210
-43
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
## Unreleased
66

7+
### Fixed
8+
- Fixed Jedi code completion for `Color` and `Icon` classes in `pybricks.parameters`.
9+
710
## 3.2.0b4 - 2022-10-21
811

912
### Added

jedi/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
## Unreleased
66

7+
### Fixed
8+
- Fixed code completion for `Color` and `Icon` classes in `pybricks.parameters`.
9+
710
## 1.2.0 - 2022-10-21
811

912
### Added
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
import json
2+
3+
import pytest
4+
from pybricks_jedi import CompletionItem, complete
5+
6+
7+
def _create_snippet(class_name: str) -> str:
8+
"""
9+
Creates a code snippet::
10+
11+
from pybricks.parameters import {class_name}
12+
{class_name}.
13+
14+
Args:
15+
line: The value substituted for ``{class_name}``
16+
"""
17+
return "\n".join(
18+
(f"from pybricks.parameters import {class_name}", f"{class_name}.")
19+
)
20+
21+
22+
ENUMS = [
23+
pytest.param(
24+
"Button",
25+
[
26+
"BEACON",
27+
"BLUETOOTH",
28+
"CENTER",
29+
"DOWN",
30+
"LEFT",
31+
"LEFT_DOWN",
32+
"LEFT_MINUS",
33+
"LEFT_PLUS",
34+
"LEFT_UP",
35+
"RIGHT",
36+
"RIGHT_DOWN",
37+
"RIGHT_MINUS",
38+
"RIGHT_PLUS",
39+
"RIGHT_UP",
40+
"UP",
41+
],
42+
),
43+
pytest.param(
44+
"Color",
45+
[
46+
"BLACK",
47+
"BLUE",
48+
"BROWN",
49+
"CYAN",
50+
"GRAY",
51+
"GREEN",
52+
"MAGENTA",
53+
"NONE",
54+
"ORANGE",
55+
"RED",
56+
"VIOLET",
57+
"WHITE",
58+
"YELLOW",
59+
],
60+
),
61+
pytest.param("Direction", ["CLOCKWISE", "COUNTERCLOCKWISE"]),
62+
pytest.param(
63+
"Icon",
64+
[
65+
"ARROW_DOWN",
66+
"ARROW_LEFT",
67+
"ARROW_LEFT_DOWN",
68+
"ARROW_LEFT_UP",
69+
"ARROW_RIGHT",
70+
"ARROW_RIGHT_DOWN",
71+
"ARROW_RIGHT_UP",
72+
"ARROW_UP",
73+
"CIRCLE",
74+
"CLOCKWISE",
75+
"COUNTERCLOCKWISE",
76+
"DOWN",
77+
"EMPTY",
78+
"EYE_LEFT",
79+
"EYE_LEFT_BLINK",
80+
"EYE_LEFT_BROW",
81+
"EYE_LEFT_BROW_UP",
82+
"EYE_RIGHT",
83+
"EYE_RIGHT_BLINK",
84+
"EYE_RIGHT_BROW",
85+
"EYE_RIGHT_BROW_UP",
86+
"FALSE",
87+
"FULL",
88+
"HAPPY",
89+
"HEART",
90+
"LEFT",
91+
"PAUSE",
92+
"RIGHT",
93+
"SAD",
94+
"SQUARE",
95+
"TRIANGLE_DOWN",
96+
"TRIANGLE_LEFT",
97+
"TRIANGLE_RIGHT",
98+
"TRIANGLE_UP",
99+
"TRUE",
100+
"UP",
101+
],
102+
),
103+
pytest.param("Port", ["A", "B", "C", "D", "E", "F", "S1", "S2", "S3", "S4"]),
104+
pytest.param("Side", ["BACK", "BOTTOM", "FRONT", "LEFT", "RIGHT", "TOP"]),
105+
pytest.param("Stop", ["BRAKE", "COAST", "HOLD"]),
106+
]
107+
108+
109+
@pytest.mark.parametrize("class_name,members", ENUMS)
110+
def test_get_parameter_class_member_completion(class_name: str, members: list[str]):
111+
112+
code = _create_snippet(class_name)
113+
completions: list[CompletionItem] = json.loads(
114+
complete(code, 2, len(class_name) + 2)
115+
)
116+
assert [c["insertText"] for c in completions] == members
117+
118+
119+
def test_get_parameter_color_completion():
120+
code = "\n".join(["from pybricks.parameters import Color", "Color.RED."])
121+
completions: list[CompletionItem] = json.loads(complete(code, 2, 11))
122+
assert [c["insertText"] for c in completions] == [
123+
"BLACK",
124+
"BLUE",
125+
"BROWN",
126+
"CYAN",
127+
"GRAY",
128+
"GREEN",
129+
"h",
130+
"MAGENTA",
131+
"NONE",
132+
"ORANGE",
133+
"RED",
134+
"s",
135+
"v",
136+
"VIOLET",
137+
"WHITE",
138+
"YELLOW",
139+
]

0 commit comments

Comments
 (0)