Skip to content

Commit cc8efb4

Browse files
committed
fix scope
1 parent 7e69428 commit cc8efb4

File tree

2 files changed

+50
-40
lines changed

2 files changed

+50
-40
lines changed

analysis/src/CompletionFrontEndNew.ml

+13-3
Original file line numberDiff line numberDiff line change
@@ -587,12 +587,22 @@ let scopeModuleBinding ~scope (mb : Parsetree.module_binding) =
587587
let scopeModuleDeclaration ~scope (md : Parsetree.module_declaration) =
588588
scope |> Scope.addModule ~name:md.pmd_name.txt ~loc:md.pmd_name.loc
589589

590-
let rec completeFromStructure ~completionContext
590+
let rec completeFromStructure ~(completionContext : CompletionContext.t)
591591
(structure : Parsetree.structure) : CompletionResult.t =
592-
(* TODO: Scope? *)
592+
let scope = ref completionContext.scope in
593593
structure
594594
|> Utils.findMap (fun (item : Parsetree.structure_item) ->
595-
completeStructureItem ~completionContext item)
595+
let res =
596+
completeStructureItem
597+
~completionContext:
598+
(CompletionContext.withScope !scope completionContext)
599+
item
600+
in
601+
(match item.pstr_desc with
602+
| Pstr_value (_, valueBindings) ->
603+
scope := scopeValueBindings ~scope:!scope valueBindings
604+
| _ -> ());
605+
res)
596606

597607
and completeStructureItem ~(completionContext : CompletionContext.t)
598608
(item : Parsetree.structure_item) : CompletionResult.t =
Original file line numberDiff line numberDiff line change
@@ -1,185 +1,185 @@
11
Complete2 src/CompletionNew.res 2:17
22
Result: Cexpression: ctxPath: CId(Value)=m, rootType: TypeAtLoc: [2:7->2:13]
3-
Scope: 0 items
3+
Scope: 1 items
44
Looking for type: TypeAtLoc: [2:7->2:13]
55

66
Complete2 src/CompletionNew.res 7:30
77
Result: Cexpression: ctxPath: CId(Module)=O, rootType: Type<CId(Type)=someVariant>, prefix: "O"
8-
Scope: 0 items
8+
Scope: 1 items
99
Looking for type: Type<CId(Type)=someVariant>
1010

1111
Complete2 src/CompletionNew.res 10:36
1212
Result: Cexpression: ctxPath: CVariantPayload($0)->CId(Value)=t, rootType: Type<CId(Type)=someVariant>
13-
Scope: 0 items
13+
Scope: 1 items
1414
Looking for type: Type<CId(Type)=someVariant>
1515

1616
Complete2 src/CompletionNew.res 13:42
1717
Result: Cexpression: ctxPath: CVariantPayload($1)->CId(Module)=S, rootType: Type<CId(Type)=someVariant>, prefix: "S"
18-
Scope: 0 items
18+
Scope: 1 items
1919
Looking for type: Type<CId(Type)=someVariant>
2020

2121
Complete2 src/CompletionNew.res 16:47
2222
Result: Cexpression: ctxPath: CVariantPayload($1)->CVariantPayload($0)->CId(Module)=O, rootType: Type<CId(Type)=someVariant>, prefix: "O"
23-
Scope: 0 items
23+
Scope: 1 items
2424
Looking for type: Type<CId(Type)=someVariant>
2525

2626
Complete2 src/CompletionNew.res 27:29
2727
Result: Cexpression: ctxPath: CRecordField=, rootType: Type<CId(Type)=someRecord>
28-
Scope: 0 items
28+
Scope: 1 items
2929
Looking for type: Type<CId(Type)=someRecord>
3030

3131
Complete2 src/CompletionNew.res 30:30
3232
Result: Cexpression: ctxPath: CRecordField=n, rootType: Type<CId(Type)=someRecord>, prefix: "n"
33-
Scope: 0 items
33+
Scope: 1 items
3434
Looking for type: Type<CId(Type)=someRecord>
3535

3636
Complete2 src/CompletionNew.res 33:39
3737
Result: Cexpression: ctxPath: CRecordField=variant->CId(Module)=O, rootType: Type<CId(Type)=someRecord>, prefix: "O"
38-
Scope: 0 items
38+
Scope: 1 items
3939
Looking for type: Type<CId(Type)=someRecord>
4040

4141
Complete2 src/CompletionNew.res 36:66
4242
Result: Cexpression: ctxPath: CRecordField=nested->CRecordField=maybeVariant->CVariantPayload($1)->CId(Value)=t, rootType: Type<CId(Type)=someRecord>
43-
Scope: 0 items
43+
Scope: 1 items
4444
Looking for type: Type<CId(Type)=someRecord>
4545

4646
Complete2 src/CompletionNew.res 39:66
4747
Result: Cexpression: ctxPath: CRecordField=variant, rootType: Type<CId(Type)=someRecord>
48-
Scope: 0 items
48+
Scope: 1 items
4949
Looking for type: Type<CId(Type)=someRecord>
5050

5151
Complete2 src/CompletionNew.res 42:56
5252
Result: Cexpression: ctxPath: CRecordField=nested->CRecordField=, rootType: Type<CId(Type)=someRecord>
53-
Scope: 0 items
53+
Scope: 1 items
5454
Looking for type: Type<CId(Type)=someRecord>
5555

5656
Complete2 src/CompletionNew.res 45:57
5757
Result: Cexpression: ctxPath: CRecordField=, rootType: Type<CId(Type)=someRecord>
58-
Scope: 0 items
58+
Scope: 1 items
5959
Looking for type: Type<CId(Type)=someRecord>
6060

6161
Complete2 src/CompletionNew.res 49:71
6262
Result: Cexpression: ctxPath: CId(Value)=x, rootType: Unit
63-
Scope: 1 items
63+
Scope: 2 items
6464
Looking for type: Unit
6565

6666
Complete2 src/CompletionNew.res 53:73
6767
Result: Cexpression: ctxPath: CRecordField=nested->CRecordField=maybeVariant->CId(Value)=, rootType: Type<CId(Type)=someRecord>
68-
Scope: 1 items
68+
Scope: 2 items
6969
Looking for type: Type<CId(Type)=someRecord>
7070

7171
Complete2 src/CompletionNew.res 57:85
7272
Result: Cexpression: ctxPath: CRecordField=nested->CRecordField=maybeVariant->CId(Value)=v, rootType: Type<CId(Type)=someRecord>
73-
Scope: 1 items
73+
Scope: 2 items
7474
Looking for type: Type<CId(Type)=someRecord>
7575

7676
Complete2 src/CompletionNew.res 61:58
7777
Result: Cexpression: ctxPath: CId(Value)=doStuff, rootType: Unit
78-
Scope: 0 items
78+
Scope: 1 items
7979
Looking for type: Unit
8080

8181
Complete2 src/CompletionNew.res 66:32
8282
Result: Cexpression: ctxPath: CId(Value)=, rootType: Type<bool>
83-
Scope: 1 items
83+
Scope: 2 items
8484
Looking for type: Type<bool>
8585

8686
Complete2 src/CompletionNew.res 69:38
8787
Result: Cexpression: ctxPath: CRecordField=, rootType: FunctionReturnType<CId(Type)=fn>
88-
Scope: 2 items
88+
Scope: 3 items
8989
Looking for type: FunctionReturnType<CId(Type)=fn>
9090

9191
Complete2 src/CompletionNew.res 72:72
9292
Result: Cexpression: ctxPath: CId(Value)=, rootType: FunctionReturnType<CId(Type)=fn>
93-
Scope: 3 items
93+
Scope: 4 items
9494
Looking for type: FunctionReturnType<CId(Type)=fn>
9595

9696
Complete2 src/CompletionNew.res 76:60
9797
Result: Cexpression: ctxPath: CId(Value)=t, rootType: Type<bool>
98-
Scope: 2 items
98+
Scope: 3 items
9999
Looking for type: Type<bool>
100100

101101
Complete2 src/CompletionNew.res 80:54
102102
Result: Cexpression: ctxPath: CId(Value)=t, rootType: TypeAtLoc: [80:42->80:50]
103-
Scope: 2 items
103+
Scope: 3 items
104104
Looking for type: TypeAtLoc: [80:42->80:50]
105105

106106
Complete2 src/CompletionNew.res 84:22
107107
Result: CtxPath: CId(Value)=
108-
Scope: 0 items
108+
Scope: 1 items
109109
Looking for type: Type<bool>
110110

111111
Complete2 src/CompletionNew.res 87:20
112112
Result: Cpattern: ctxPath: CRecordField=someField, rootType: Type<CId(Value)=someRecordVar>, prefix: "s"
113-
Scope: 0 items
113+
Scope: 1 items
114114
Looking for type: Type<CId(Value)=someRecordVar>
115115

116116
Complete2 src/CompletionNew.res 91:13
117117
Result: Cpattern: ctxPath: CTupleItem($1), rootType: Type<CId(Value)=someRecordVar>
118-
Scope: 0 items
118+
Scope: 1 items
119119
Looking for type: Type<CId(Value)=someRecordVar>
120120

121121
Complete2 src/CompletionNew.res 94:20
122122
Result: Cpattern: ctxPath: CTupleItem($2), rootType: Type<CId(Value)=someRecordVar>
123-
Scope: 0 items
123+
Scope: 1 items
124124
Looking for type: Type<CId(Value)=someRecordVar>
125125

126126
Complete2 src/CompletionNew.res 98:9
127127
Result: Cpattern: ctxPath: array, rootType: Type<CId(Value)=someArr>
128-
Scope: 0 items
128+
Scope: 1 items
129129
Looking for type: Type<CId(Value)=someArr>
130130

131131
Complete2 src/CompletionNew.res 101:22
132132
Result: Cpattern: ctxPath: array->CTupleItem($1)->array, rootType: Type<CId(Value)=someArr>
133-
Scope: 0 items
133+
Scope: 1 items
134134
Looking for type: Type<CId(Value)=someArr>
135135

136136
Complete2 src/CompletionNew.res 104:24
137137
Result: Cpattern: ctxPath: array->CTupleItem($1)->array, rootType: Type<CId(Value)=someArr>, prefix: "f"
138-
Scope: 0 items
138+
Scope: 1 items
139139
Looking for type: Type<CId(Value)=someArr>
140140

141141
Complete2 src/CompletionNew.res 108:23
142142
Result: Cexpression: ctxPath: CId(Value)=f, rootType: Type<CFunctionArgument CId(Value)=&&($1)>
143-
Scope: 0 items
143+
Scope: 1 items
144144
Looking for type: Type<CFunctionArgument CId(Value)=&&($1)>
145145

146146
Complete2 src/CompletionNew.res 111:42
147147
Result: Cexpression: ctxPath: CId(Value)=f, rootType: FunctionReturnType<CFunctionArgument CId(Value)=someFunc($0)>
148-
Scope: 1 items
148+
Scope: 2 items
149149
Looking for type: FunctionReturnType<CFunctionArgument CId(Value)=someFunc($0)>
150150

151151
Complete2 src/CompletionNew.res 114:34
152152
Result: Cexpression: ctxPath: CId(Value)=f, rootType: Type<CFunctionArgument CId(Value)=someFunc(~labelledArg)>
153-
Scope: 0 items
153+
Scope: 1 items
154154
Looking for type: Type<CFunctionArgument CId(Value)=someFunc(~labelledArg)>
155155

156156
Complete2 src/CompletionNew.res 117:33
157157
Result: Cexpression: ctxPath: , rootType: Type<CFunctionArgument CId(Value)=someFunc(~labelledArg)>
158-
Scope: 0 items
158+
Scope: 1 items
159159
Looking for type: Type<CFunctionArgument CId(Value)=someFunc(~labelledArg)>
160160

161161
Complete2 src/CompletionNew.res 121:17
162162
Result: CtxPath: (CId(Value)=foo)->id
163-
Scope: 0 items
163+
Scope: 1 items
164164
Looking for type: Unit
165165

166166
Complete2 src/CompletionNew.res 124:16
167167
Result: CtxPath: (CId(Value)=foo)->
168-
Scope: 0 items
168+
Scope: 1 items
169169
Looking for type: Unit
170170

171171
Complete2 src/CompletionNew.res 127:17
172172
Result: Cexpression: ctxPath: CId(Module)=M, rootType: Unit, prefix: "M"
173-
Scope: 0 items
173+
Scope: 1 items
174174
Looking for type: Unit
175175

176176
Complete2 src/CompletionNew.res 136:36
177177
Result: CnamedArg(CId(Value)=someFun, f, [secondLabel, f])
178-
Scope: 0 items
178+
Scope: 2 items
179179
Looking for type: TypeAtLoc: [136:7->136:9]
180180

181181
Complete2 src/CompletionNew.res 139:37
182182
Result: Cexpression: ctxPath: , rootType: Type<CFunctionArgument CId(Value)=someFun($0)>
183-
Scope: 0 items
183+
Scope: 2 items
184184
Looking for type: Type<CFunctionArgument CId(Value)=someFun($0)>
185185

0 commit comments

Comments
 (0)