Skip to content

Commit b89323a

Browse files
authored
Merge pull request #151 from rescript-lang/jsx
Add autocomplete of JSX props without test letter.
2 parents 9947cb3 + e08682f commit b89323a

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

analysis/src/PartialParser.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ let findCompletable text offset =
175175
Some (Clabel (funPath, labelPrefix))
176176
| '@' -> Some (Cdecorator (suffix i))
177177
| 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '.' | '_' -> loop (i - 1)
178+
| ' ' when i = offset - 1 -> (
179+
(* autocomplete with no id: check if inside JSX *)
180+
match findJsxContext text (offset - 1) with
181+
| None -> None
182+
| Some componentName ->
183+
Some (Cjsx (Str.split (Str.regexp_string ".") componentName, "")))
178184
| _ -> if i = offset - 1 then None else Some (mkPath (suffix i))
179185
in
180186
if offset > String.length text || offset = 0 then None else loop (offset - 1)

analysis/tests/src/Jsx.res

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ let d = <M first="abc" />
1010

1111

1212
//^com <M second="abc" f
13+
14+
//^com let e = <M

analysis/tests/src/expected/Jsx.res.txt

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,31 @@ Definition tests/src/Jsx.res 5:9
22
{"uri": "Jsx.res", "range": {"start": {"line": 2, "character": 6}, "end": {"line": 2, "character": 10}}}
33

44
Complete tests/src/Jsx.res 7:2
5-
[]
5+
[{
6+
"label": "key",
7+
"kind": 4,
8+
"tags": [],
9+
"detail": "string",
10+
"documentation": null
11+
}, {
12+
"label": "first",
13+
"kind": 4,
14+
"tags": [],
15+
"detail": "string",
16+
"documentation": null
17+
}, {
18+
"label": "fun",
19+
"kind": 4,
20+
"tags": [],
21+
"detail": "option<string>",
22+
"documentation": null
23+
}, {
24+
"label": "second",
25+
"kind": 4,
26+
"tags": [],
27+
"detail": "option<string>",
28+
"documentation": null
29+
}]
630

731
Complete tests/src/Jsx.res 10:2
832
[{
@@ -25,3 +49,30 @@ Complete tests/src/Jsx.res 10:2
2549
"documentation": null
2650
}]
2751

52+
Complete tests/src/Jsx.res 12:2
53+
[{
54+
"label": "key",
55+
"kind": 4,
56+
"tags": [],
57+
"detail": "string",
58+
"documentation": null
59+
}, {
60+
"label": "first",
61+
"kind": 4,
62+
"tags": [],
63+
"detail": "string",
64+
"documentation": null
65+
}, {
66+
"label": "fun",
67+
"kind": 4,
68+
"tags": [],
69+
"detail": "option<string>",
70+
"documentation": null
71+
}, {
72+
"label": "second",
73+
"kind": 4,
74+
"tags": [],
75+
"detail": "option<string>",
76+
"documentation": null
77+
}]
78+

0 commit comments

Comments
 (0)