@@ -57,57 +57,60 @@ let findCallFromArgument text offset =
57
57
(* arg ::= id | id = [?] val *)
58
58
(* val ::= id | "abc" | 42 | {...} | (...) | [...] *)
59
59
let findJsxContext text offset =
60
- let rec loop i =
60
+ let rec loop identsSeen i =
61
61
let i = skipWhite text i in
62
62
if i > 0 then
63
63
match text.[i] with
64
64
| '}' ->
65
65
let i1 = findBackSkippingCommentsAndStrings text '{' '}' (i - 1 ) 0 in
66
- if i1 > 0 then beforeValue i1 else None
66
+ if i1 > 0 then beforeValue identsSeen i1 else None
67
67
| ')' ->
68
68
let i1 = findBackSkippingCommentsAndStrings text '(' ')' (i - 1 ) 0 in
69
- if i1 > 0 then beforeValue i1 else None
69
+ if i1 > 0 then beforeValue identsSeen i1 else None
70
70
| ']' ->
71
71
let i1 = findBackSkippingCommentsAndStrings text '[' ']' (i - 1 ) 0 in
72
- if i1 > 0 then beforeValue i1 else None
72
+ if i1 > 0 then beforeValue identsSeen i1 else None
73
73
| '"' ->
74
74
let i1 = findBack text '"' (i - 1 ) in
75
- if i1 > 0 then beforeValue i1 else None
75
+ if i1 > 0 then beforeValue identsSeen i1 else None
76
76
| _ ->
77
77
let i1 = startOfLident text i in
78
78
let ident = String. sub text i1 (i - i1 + 1 ) in
79
79
if i1 > = 1 && ident <> " " then
80
80
match ident.[0 ] with
81
- | 'A' .. 'Z' when i1 > = 1 && text.[i1 - 1 ] = '<' -> Some ident
82
- | _ -> beforeIdent (i1 - 1 )
81
+ | 'A' .. 'Z' when i1 > = 1 && text.[i1 - 1 ] = '<' ->
82
+ Some (ident, identsSeen)
83
+ | _ -> beforeIdent identsSeen (i1 - 1 )
83
84
else None
84
85
else None
85
- and beforeIdent i =
86
+ and beforeIdent identsSeen i =
86
87
let i = skipWhite text i in
87
88
if i > 0 then
88
89
match text.[i] with
89
- | '?' -> fromEquals (i - 1 )
90
- | '=' -> fromEquals i
91
- | _ -> loop (i - 1 )
90
+ | '?' -> fromEquals identsSeen (i - 1 )
91
+ | '=' -> fromEquals identsSeen i
92
+ | _ -> loop identsSeen (i - 1 )
92
93
else None
93
- and beforeValue i =
94
+ and beforeValue identsSeen i =
94
95
let i = skipWhite text i in
95
96
if i > 0 then
96
- match text.[i] with '?' -> fromEquals (i - 1 ) | _ -> fromEquals i
97
+ match text.[i] with
98
+ | '?' -> fromEquals identsSeen (i - 1 )
99
+ | _ -> fromEquals identsSeen i
97
100
else None
98
- and fromEquals i =
101
+ and fromEquals identsSeen i =
99
102
let i = skipWhite text i in
100
103
if i > 0 then
101
104
match text.[i] with
102
105
| '=' -> (
103
106
let i = skipWhite text (i - 1 ) in
104
107
let i1 = startOfLident text i in
105
108
let ident = String. sub text i1 (i - i1 + 1 ) in
106
- match ident with "" -> None | _ -> loop (i1 - 1 ))
109
+ match ident with "" -> None | _ -> loop (ident :: identsSeen) ( i1 - 1 ))
107
110
| _ -> None
108
111
else None
109
112
in
110
- loop offset
113
+ loop [] offset
111
114
112
115
type pipe = PipeId of string | PipeArray | PipeString
113
116
@@ -116,8 +119,8 @@ type completable =
116
119
| Clabel of string list * string
117
120
(* * e.g. (["M", "foo"], "label") for M.foo(...~label...) *)
118
121
| Cpath of string list (* * e.g. ["M", "foo"] for M.foo *)
119
- | Cjsx of string list * string
120
- (* * E.g. (["M", "Comp"], "id") for <M.Comp ... id *)
122
+ | Cjsx of string list * string * string list
123
+ (* * E.g. (["M", "Comp"], "id", ["id1", "id2"] ) for <M.Comp id1=... id2=... ... id *)
121
124
| Cpipe of pipe * string (* * E.g. ("x", "foo") for "x->foo" *)
122
125
123
126
let isLowercaseIdent id =
@@ -140,8 +143,8 @@ let findCompletable text offset =
140
143
| [id] when String. lowercase_ascii id = id -> (
141
144
match findJsxContext text (offset - len - 1 ) with
142
145
| None -> Cpath parts
143
- | Some componentName ->
144
- Cjsx (Str. split (Str. regexp_string " ." ) componentName, id))
146
+ | Some ( componentName , identsSeen ) ->
147
+ Cjsx (Str. split (Str. regexp_string " ." ) componentName, id, identsSeen ))
145
148
| _ -> Cpath parts
146
149
in
147
150
let mkPipe off partialName =
@@ -179,8 +182,11 @@ let findCompletable text offset =
179
182
(* autocomplete with no id: check if inside JSX *)
180
183
match findJsxContext text (offset - 1 ) with
181
184
| None -> None
182
- | Some componentName ->
183
- Some (Cjsx (Str. split (Str. regexp_string " ." ) componentName, " " )))
185
+ | Some (componentName , identsSeen ) ->
186
+ Some
187
+ (Cjsx
188
+ (Str. split (Str. regexp_string " ." ) componentName, " " , identsSeen))
189
+ )
184
190
| _ -> if i = offset - 1 then None else Some (mkPath (suffix i))
185
191
in
186
192
if offset > String. length text || offset = 0 then None else loop (offset - 1 )
0 commit comments