Skip to content

Commit 9d543d5

Browse files
committed
Autocomplete of JSX props without first letter.
Fixes #147
1 parent c143df6 commit 9d543d5

File tree

3 files changed

+57
-5
lines changed

3 files changed

+57
-5
lines changed

analysis/src/PartialParser.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ 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+
match findJsxContext text (offset - 1) with
180+
| None -> None
181+
| Some componentName ->
182+
Some (Cjsx (Str.split (Str.regexp_string ".") componentName, "")))
178183
| _ -> if i = offset - 1 then None else Some (mkPath (suffix i))
179184
in
180185
if offset > String.length text || offset = 0 then None else loop (offset - 1)

analysis/tests/src/Jsx.res

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@ let d = <M first="abc" />
1111

1212
//^com <M second="abc" f
1313

14-
let e = <M first="abc" />
15-
// ^com
14+
//^com let e = <M

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

Lines changed: 51 additions & 3 deletions
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,6 +49,30 @@ Complete tests/src/Jsx.res 10:2
2549
"documentation": null
2650
}]
2751

28-
Complete tests/src/Jsx.res 13:11
29-
[]
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+
}]
3078

0 commit comments

Comments
 (0)