1
1
open SharedTypes
2
2
3
+ type resolution =
4
+ | Exported of QueryEnv .t * filePath
5
+ | Global of filePath * filePath list
6
+ | GlobalMod of filePath
7
+ | NotFound
8
+ | Stamp of int
9
+
3
10
let rec joinPaths modulePath path =
4
11
match modulePath with
5
12
| Path. Pident ident -> (ident.stamp, ident.name, path)
6
13
| Papply (fnPath , _argPath ) -> joinPaths fnPath path
7
14
| Pdot (inner , name , _ ) -> joinPaths inner (name :: path)
8
15
9
- let rec makePath modulePath =
16
+ let rec makePath ~( env : QueryEnv.t ) modulePath =
10
17
match modulePath with
11
- | Path. Pident ident when ident.stamp == 0 -> `GlobalMod ident.name
12
- | Pident ident -> `Stamp ident.stamp
13
- | Papply (fnPath , _argPath ) -> makePath fnPath
14
- | Pdot (inner , name , _ ) -> `Path (joinPaths inner [name])
18
+ | Path. Pident ident when ident.stamp == 0 -> GlobalMod ident.name
19
+ | Pident ident -> Stamp ident.stamp
20
+ | Papply (fnPath , _argPath ) -> makePath ~env fnPath
21
+ | Pdot (inner , name , _ ) -> (
22
+ match joinPaths inner [name] with
23
+ | 0 , moduleName , path -> Global (moduleName, path)
24
+ | stamp , _moduleName , path -> (
25
+ let res =
26
+ match Stamps. findModule env.file.stamps stamp with
27
+ | None -> None
28
+ | Some {item = kind } -> findInModule ~env kind path
29
+ in
30
+ match res with
31
+ | None -> NotFound
32
+ | Some (`Local (env , name )) -> Exported (env, name)
33
+ | Some (`Global (moduleName , fullPath )) -> Global (moduleName, fullPath)))
15
34
16
- let rec resolvePathInner ~(env : QueryEnv.t ) ~path =
35
+ and resolvePathInner ~(env : QueryEnv.t ) ~path =
17
36
match path with
18
37
| [] -> None
19
38
| [name] -> Some (`Local (env, name))
@@ -25,7 +44,7 @@ let rec resolvePathInner ~(env : QueryEnv.t) ~path =
25
44
| None -> None
26
45
| Some {item} -> findInModule ~env item subPath))
27
46
28
- and findInModule ~env module_ path =
47
+ and findInModule ~( env : QueryEnv.t ) module_ path =
29
48
match module_ with
30
49
| Structure {exported} -> resolvePathInner ~env: {env with exported} ~path
31
50
| Constraint (_ , module1 ) -> findInModule ~env module1 path
@@ -53,25 +72,17 @@ let rec resolvePath ~env ~path ~package =
53
72
| Some file ->
54
73
resolvePath ~env: (QueryEnv. fromFile file) ~path: fullPath ~package ))
55
74
56
- let fromCompilerPath ~(env : QueryEnv.t ) path =
57
- match makePath path with
58
- | `Stamp stamp -> `Stamp stamp
59
- | `Path (0 , moduleName , path ) -> `Global (moduleName, path)
60
- | `GlobalMod name -> `GlobalMod name
61
- | `Path (stamp , _moduleName , path ) -> (
62
- let res =
63
- match Stamps. findModule env.file.stamps stamp with
64
- | None -> None
65
- | Some {item = kind } -> findInModule ~env kind path
66
- in
67
- match res with
68
- | None -> `Not_found
69
- | Some (`Local (env , name )) -> `Exported (env, name)
70
- | Some (`Global (moduleName , fullPath )) -> `Global (moduleName, fullPath))
75
+ let fromCompilerPath ~(env : QueryEnv.t ) path : resolution =
76
+ match makePath ~env path with
77
+ | Stamp stamp -> Stamp stamp
78
+ | GlobalMod name -> GlobalMod name
79
+ | NotFound -> NotFound
80
+ | Exported (env , name ) -> Exported (env, name)
81
+ | Global (moduleName , fullPath ) -> Global (moduleName, fullPath)
71
82
72
83
let resolveModuleFromCompilerPath ~env ~package path =
73
84
match fromCompilerPath ~env path with
74
- | ` Global (moduleName , path ) -> (
85
+ | Global (moduleName , path ) -> (
75
86
match ProcessCmt. fileForModule ~package moduleName with
76
87
| None -> None
77
88
| Some file -> (
@@ -85,18 +96,18 @@ let resolveModuleFromCompilerPath ~env ~package path =
85
96
match Stamps. findModule env.file.stamps stamp with
86
97
| None -> None
87
98
| Some declared -> Some (env, Some declared)))))
88
- | ` Stamp stamp -> (
99
+ | Stamp stamp -> (
89
100
match Stamps. findModule env.file.stamps stamp with
90
101
| None -> None
91
102
| Some declared -> Some (env, Some declared))
92
- | ` GlobalMod moduleName -> (
103
+ | GlobalMod moduleName -> (
93
104
match ProcessCmt. fileForModule ~package moduleName with
94
105
| None -> None
95
106
| Some file ->
96
107
let env = QueryEnv. fromFile file in
97
108
Some (env, None ))
98
- | `Not_found -> None
99
- | ` Exported (env , name ) -> (
109
+ | NotFound -> None
110
+ | Exported (env , name ) -> (
100
111
match Exported. find env.exported Exported. Module name with
101
112
| None -> None
102
113
| Some stamp -> (
@@ -106,21 +117,19 @@ let resolveModuleFromCompilerPath ~env ~package path =
106
117
107
118
let resolveFromCompilerPath ~env ~package path =
108
119
match fromCompilerPath ~env path with
109
- | ` Global (moduleName , path ) -> (
120
+ | Global (moduleName , path ) -> (
110
121
let res =
111
122
match ProcessCmt. fileForModule ~package moduleName with
112
123
| None -> None
113
124
| Some file ->
114
125
let env = QueryEnv. fromFile file in
115
126
resolvePath ~env ~package ~path
116
127
in
117
- match res with
118
- | None -> `Not_found
119
- | Some (env , name ) -> `Exported (env, name))
120
- | `Stamp stamp -> `Stamp stamp
121
- | `GlobalMod _ -> `Not_found
122
- | `Not_found -> `Not_found
123
- | `Exported (env , name ) -> `Exported (env, name)
128
+ match res with None -> NotFound | Some (env , name ) -> Exported (env, name))
129
+ | Stamp stamp -> Stamp stamp
130
+ | GlobalMod _ -> NotFound
131
+ | NotFound -> NotFound
132
+ | Exported (env , name ) -> Exported (env, name)
124
133
125
134
let rec getSourceUri ~(env : QueryEnv.t ) ~package path =
126
135
match path with
0 commit comments