Skip to content

Commit 377e5e1

Browse files
committed
Fix issue in JSX autocompletion where the key label would always appear.
1 parent c5b7511 commit 377e5e1

File tree

5 files changed

+9
-28
lines changed

5 files changed

+9
-28
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Add autocompletion for object access of the form `foo["x"]` and `foo["x"]["y"]["z"]`.
66
- Fix issue with autocomplete then punned props are used in JSX. E.g. `<M foo ...>`.
77
- Fix issue with JSX autocompletion not working after `foo=#variant`.
8+
- Fix issue in JSX autocompletion where the `key` label would always appear.
89

910
## 1.1.3
1011

analysis/src/NewCompletions.ml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -879,14 +879,16 @@ let processCompletable ~findItems ~full ~package ~rawOpens
879879
mkItem ~name ~kind:4 ~deprecated:None ~detail:typString ~docstring:[]
880880
in
881881
let mkLabel (name, typ) = mkLabel_ name typ in
882-
let keyLabel = mkLabel_ "key" "string" in
882+
let keyLabels =
883+
if Utils.startsWith "key" prefix then [mkLabel_ "key" "string"] else []
884+
in
883885
if domLabels = [] then []
884886
else
885887
(domLabels
886888
|> List.filter (fun (name, _t) ->
887889
Utils.startsWith name prefix && not (List.mem name identsSeen))
888890
|> List.map mkLabel)
889-
@ [keyLabel]
891+
@ keyLabels
890892
| Cjsx (componentPath, prefix, identsSeen) ->
891893
let items = findItems ~exact:true (componentPath @ ["make"]) in
892894
let labels =
@@ -936,14 +938,16 @@ let processCompletable ~findItems ~full ~package ~rawOpens
936938
mkItem ~name ~kind:4 ~deprecated:None ~detail:typString ~docstring:[]
937939
in
938940
let mkLabel (name, typ) = mkLabel_ name (typ |> Shared.typeToString) in
939-
let keyLabel = mkLabel_ "key" "string" in
941+
let keyLabels =
942+
if Utils.startsWith "key" prefix then [mkLabel_ "key" "string"] else []
943+
in
940944
if labels = [] then []
941945
else
942946
(labels
943947
|> List.filter (fun (name, _t) ->
944948
Utils.startsWith name prefix && not (List.mem name identsSeen))
945949
|> List.map mkLabel)
946-
@ [keyLabel]
950+
@ keyLabels
947951
| Cpath parts ->
948952
let items = parts |> findItems ~exact:false in
949953
(* TODO(#107): figure out why we're getting duplicates. *)

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -446,12 +446,6 @@ Complete tests/src/Completion.res 52:2
446446
"tags": [],
447447
"detail": "option<int>",
448448
"documentation": null
449-
}, {
450-
"label": "key",
451-
"kind": 4,
452-
"tags": [],
453-
"detail": "string",
454-
"documentation": null
455449
}]
456450

457451
DocumentSymbol tests/src/Completion.res

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,5 @@ Complete tests/src/Div.res 3:3
88
"tags": [],
99
"detail": "{\"__html\": string}",
1010
"documentation": null
11-
}, {
12-
"label": "key",
13-
"kind": 4,
14-
"tags": [],
15-
"detail": "string",
16-
"documentation": null
1711
}]
1812

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ Complete tests/src/Jsx.res 9:2
3535
"tags": [],
3636
"detail": "option<string>",
3737
"documentation": null
38-
}, {
39-
"label": "key",
40-
"kind": 4,
41-
"tags": [],
42-
"detail": "string",
43-
"documentation": null
4438
}]
4539

4640
Complete tests/src/Jsx.res 11:2
@@ -182,12 +176,6 @@ Complete tests/src/Jsx.res 52:2
182176
"tags": [],
183177
"detail": "option<string>",
184178
"documentation": null
185-
}, {
186-
"label": "key",
187-
"kind": 4,
188-
"tags": [],
189-
"detail": "string",
190-
"documentation": null
191179
}]
192180

193181
Complete tests/src/Jsx.res 54:2

0 commit comments

Comments
 (0)