@@ -80,10 +80,15 @@ let rec resolvePathInner = (~env, ~path) => {
80
80
switch (path) {
81
81
| Tip (name ) => Some (` Local ((env, name)))
82
82
| Nested (subName , subPath ) =>
83
- let %opt stamp = Hashtbl.find_opt(env.exported.modules, subName);
84
- let %opt {item: kind} = Hashtbl.find_opt(env.file.stamps.modules, stamp);
85
- findInModule (~env , kind , subPath );
86
- };
83
+ switch (Hashtbl . find_opt(env. exported. modules, subName)) {
84
+ | None => None
85
+ | Some (stamp ) =>
86
+ switch (Hashtbl . find_opt(env. file. stamps. modules, stamp)) {
87
+ | None => None
88
+ | Some ({item: kind }) => findInModule(~env, kind, subPath)
89
+ }
90
+ }
91
+ }
87
92
}
88
93
and findInModule = (~env, kind, path) => {
89
94
switch (kind) {
@@ -94,22 +99,29 @@ and findInModule = (~env, kind, path) => {
94
99
if (stamp == 0 ) {
95
100
Some (` Global ((moduleName, fullPath)));
96
101
} else {
97
- let %opt {item: kind} =
98
- Hashtbl . find_opt (env .file .stamps .modules , stamp );
99
- findInModule(~env, kind, fullPath);
102
+ switch (Hashtbl . find_opt(env. file. stamps. modules, stamp)) {
103
+ | None => None
104
+ | Some ({item: kind }) => findInModule(~env, kind, fullPath)
105
+ };
100
106
};
101
107
};
102
108
};
103
109
104
110
/* let rec findSubModule = (~env, ~getModule) */
105
111
106
112
let rec resolvePath = (~env, ~path, ~getModule) => {
107
- let %opt result = resolvePathInner(~env, ~path);
108
- switch (result ) {
109
- | `Local (env, name) => Some ((env, name))
110
- | `Global (moduleName, fullPath) =>
111
- let%opt file = getModule(moduleName);
112
- resolvePath(~env=fileEnv(file), ~path=fullPath, ~getModule);
113
+ switch (resolvePathInner(~env, ~path)) {
114
+ | None => None
115
+ | Some (result ) =>
116
+ switch (result) {
117
+ | ` Local (env , name ) => Some ((env, name))
118
+ | ` Global (moduleName , fullPath ) =>
119
+ switch (getModule(moduleName)) {
120
+ | None => None
121
+ | Some (file ) =>
122
+ resolvePath(~env= fileEnv(file), ~path= fullPath, ~getModule)
123
+ }
124
+ }
113
125
};
114
126
};
115
127
@@ -118,15 +130,24 @@ let resolveFromStamps = (~env, ~path, ~getModule, ~pos) => {
118
130
| Tip (name ) => Some ((env, name))
119
131
| Nested (name , inner ) =>
120
132
/* Log.log("Finding from stamps " ++ name); */
121
- let %opt declared = findInScope(pos, name, env.file.stamps.modules);
122
- /* Log.log("found it"); */
123
- let %opt res = findInModule(~env, declared.item, inner);
124
- switch (res ) {
125
- | `Local (env, name) => Some ((env, name))
126
- | `Global (moduleName, fullPath) =>
127
- let%opt file = getModule(moduleName);
128
- resolvePath(~env=fileEnv(file), ~path=fullPath, ~getModule);
129
- };
133
+ switch (findInScope(pos, name, env. file. stamps. modules)) {
134
+ | None => None
135
+ | Some (declared ) =>
136
+ /* Log.log("found it"); */
137
+ switch (findInModule(~env, declared. item, inner)) {
138
+ | None => None
139
+ | Some (res ) =>
140
+ switch (res) {
141
+ | ` Local (env , name ) => Some ((env, name))
142
+ | ` Global (moduleName , fullPath ) =>
143
+ switch (getModule(moduleName)) {
144
+ | None => None
145
+ | Some (file ) =>
146
+ resolvePath(~env= fileEnv(file), ~path= fullPath, ~getModule)
147
+ }
148
+ }
149
+ }
150
+ }
130
151
};
131
152
};
132
153
@@ -154,24 +175,45 @@ let fromCompilerPath = (~env, path) => {
154
175
let resolveModuleFromCompilerPath = (~env, ~getModule, path) => {
155
176
switch (fromCompilerPath(~env, path)) {
156
177
| ` Global (moduleName , path ) =>
157
- let %opt file = getModule(moduleName);
158
- let env = fileEnv(file);
159
- let %opt (env, name) = resolvePath(~env, ~getModule, ~path);
160
- let %opt stamp = Hashtbl.find_opt(env.exported.modules, name);
161
- let %opt declared = Hashtbl.find_opt(env.file.stamps.modules, stamp);
162
- Some ((env , Some (declared )));
178
+ switch (getModule(moduleName)) {
179
+ | None => None
180
+ | Some (file ) =>
181
+ let env = fileEnv(file);
182
+ switch (resolvePath(~env, ~getModule, ~path)) {
183
+ | None => None
184
+ | Some ((env , name )) =>
185
+ switch (Hashtbl . find_opt(env. exported. modules, name)) {
186
+ | None => None
187
+ | Some (stamp ) =>
188
+ switch (Hashtbl . find_opt(env. file. stamps. modules, stamp)) {
189
+ | None => None
190
+ | Some (declared ) => Some ((env, Some (declared)))
191
+ }
192
+ }
193
+ };
194
+ }
163
195
| ` Stamp (stamp ) =>
164
- let %opt declared = Hashtbl.find_opt(env.file.stamps.modules, stamp);
165
- Some ((env , Some (declared )));
196
+ switch (Hashtbl . find_opt(env. file. stamps. modules, stamp)) {
197
+ | None => None
198
+ | Some (declared ) => Some ((env, Some (declared)))
199
+ }
166
200
| ` GlobalMod (moduleName ) =>
167
- let %opt file = getModule(moduleName);
168
- let env = fileEnv(file);
169
- Some ((env, None ));
201
+ switch (getModule(moduleName)) {
202
+ | None => None
203
+ | Some (file ) =>
204
+ let env = fileEnv(file);
205
+ Some ((env, None ));
206
+ }
170
207
| ` Not_found => None
171
208
| ` Exported (env , name ) =>
172
- let %opt stamp = Hashtbl.find_opt(env.exported.modules, name);
173
- let %opt declared = Hashtbl.find_opt(env.file.stamps.modules, stamp);
174
- Some ((env , Some (declared )));
209
+ switch (Hashtbl . find_opt(env. exported. modules, name)) {
210
+ | None => None
211
+ | Some (stamp ) =>
212
+ switch (Hashtbl . find_opt(env. file. stamps. modules, stamp)) {
213
+ | None => None
214
+ | Some (declared ) => Some ((env, Some (declared)))
215
+ }
216
+ }
175
217
};
176
218
};
177
219
@@ -234,21 +276,28 @@ let declaredForTip = (~stamps, stamp, tip) =>
234
276
};
235
277
236
278
let getField = (file, stamp, name) => {
237
- let %opt {item: {kind}} = Hashtbl.find_opt(file.stamps.types, stamp);
238
- switch (kind ) {
239
- | Record (fields) => fields |> List.find_opt(f => f.fname.txt == name)
240
- | _ => None
279
+ switch (Hashtbl . find_opt(file. stamps. types, stamp)) {
280
+ | None => None
281
+ | Some ({item: {kind}}) =>
282
+ switch (kind) {
283
+ | Record (fields ) => fields |> List . find_opt(f => f. fname. txt == name)
284
+ | _ => None
285
+ }
241
286
};
242
287
};
243
288
244
289
let getConstructor = (file, stamp, name) => {
245
- let %opt {item: {kind}} = Hashtbl.find_opt(file.stamps.types, stamp);
246
- switch (kind ) {
247
- | Variant (constructors) =>
248
- let%opt const =
249
- constructors |> List.find_opt(const => const.cname.txt == name);
250
- Some(const);
251
- | _ => None
290
+ switch (Hashtbl . find_opt(file. stamps. types, stamp)) {
291
+ | None => None
292
+ | Some ({item: {kind}}) =>
293
+ switch (kind) {
294
+ | Variant (constructors ) =>
295
+ switch (constructors |> List . find_opt(const => const. cname. txt == name)) {
296
+ | None => None
297
+ | Some (const ) => Some (const)
298
+ }
299
+ | _ => None
300
+ }
252
301
};
253
302
};
254
303
0 commit comments