1
- let dumpLocations state ~package ~file ~extra =
1
+ let dumpLocations ~package ~file ~extra =
2
2
let locations =
3
3
extra.SharedTypes. locations
4
4
|> List. filter (fun (l , _ ) -> not l.Location. loc_ghost)
5
5
in
6
6
locations
7
7
|> List. map (fun ((location : Location.t ), loc ) ->
8
- let hoverText =
9
- Hover. newHover ~file
10
- ~get Module:(State. fileForModule state ~package )
11
- loc
12
- in
8
+ let hoverText = Hover. newHover ~package ~file loc in
13
9
let hover =
14
10
match hoverText with None -> " " | Some s -> String. escaped s
15
11
in
16
- let uriLocOpt =
17
- References. definitionForLoc ~paths ForModule:package.pathsForModule
18
- ~file ~get Uri:(State. fileForUri state)
19
- ~get Module:(State. fileForModule state ~package )
20
- loc
21
- in
12
+ let uriLocOpt = References. definitionForLoc ~package ~file loc in
22
13
let def =
23
14
match uriLocOpt with
24
15
| None -> Protocol. null
@@ -32,41 +23,35 @@ let dumpLocations state ~package ~file ~extra =
32
23
33
24
let dump files =
34
25
Shared. cacheTypeToString := true ;
35
- let state = TopTypes. empty () in
36
26
files
37
27
|> List. iter (fun path ->
38
- let filePath = Files. maybeConcat (Unix. getcwd () ) path in
39
- let uri = Uri2. fromPath filePath in
28
+ let uri = Uri2. fromLocalPath path in
40
29
let result =
41
- match State . getFullFromCmt ~state ~uri with
30
+ match ProcessCmt . getFullFromCmt ~uri with
42
31
| Error message ->
43
32
prerr_endline message;
44
33
" []"
45
- | Ok (package , {file; extra} ) ->
46
- dumpLocations state ~package ~file ~extra
34
+ | Ok (package , {file; extra} ) -> dumpLocations ~package ~file ~extra
47
35
in
48
36
print_endline result)
49
37
50
38
let complete ~path ~line ~col ~currentFile =
51
- let state = TopTypes. empty () in
52
- let filePath = Files. maybeConcat (Unix. getcwd () ) path in
53
- let uri = Uri2. fromPath filePath in
39
+ let uri = Uri2. fromLocalPath path in
54
40
let result =
55
- match State . getFullFromCmt ~state ~uri with
41
+ match ProcessCmt . getFullFromCmt ~uri with
56
42
| Error message ->
57
43
prerr_endline message;
58
44
" []"
59
45
| Ok (package , full ) ->
60
46
let maybeText = Files. readFile currentFile in
61
47
NewCompletions. computeCompletions ~full ~maybe Text ~package
62
- ~pos: (line, col) ~state
48
+ ~pos: (line, col)
63
49
|> List. map Protocol. stringifyCompletionItem
64
50
|> Protocol. array
65
51
in
66
52
print_endline result
67
53
68
- let hover state ~file ~line ~col ~extra ~package =
69
- let open TopTypes in
54
+ let hover ~file ~line ~col ~extra ~package =
70
55
let locations =
71
56
extra.SharedTypes. locations
72
57
|> List. filter (fun (l , _ ) -> not l.Location. loc_ghost)
@@ -80,12 +65,7 @@ let hover state ~file ~line ~col ~extra ~package =
80
65
| SharedTypes. LModule _ | TopLevelModule _ -> true
81
66
| TypeDefinition _ | Typed _ | Constant _ | Explanation _ -> false
82
67
in
83
- let uriLocOpt =
84
- References. definitionForLoc ~paths ForModule:package.pathsForModule ~file
85
- ~get Uri:(State. fileForUri state)
86
- ~get Module:(State. fileForModule state ~package )
87
- loc
88
- in
68
+ let uriLocOpt = References. definitionForLoc ~package ~file loc in
89
69
let skipZero =
90
70
match uriLocOpt with
91
71
| None -> false
@@ -98,27 +78,21 @@ let hover state ~file ~line ~col ~extra ~package =
98
78
in
99
79
if skipZero then Protocol. null
100
80
else
101
- let hoverText =
102
- Hover. newHover ~file ~get Module:(State. fileForModule state ~package ) loc
103
- in
81
+ let hoverText = Hover. newHover ~file ~package loc in
104
82
match hoverText with
105
83
| None -> Protocol. null
106
84
| Some s -> Protocol. stringifyHover {contents = s})
107
85
108
86
let hover ~path ~line ~col =
109
- let state = TopTypes. empty () in
110
- let filePath = Files. maybeConcat (Unix. getcwd () ) path in
111
- let uri = Uri2. fromPath filePath in
87
+ let uri = Uri2. fromLocalPath path in
112
88
let result =
113
- match State . getFullFromCmt ~state ~uri with
89
+ match ProcessCmt . getFullFromCmt ~uri with
114
90
| Error message -> Protocol. stringifyHover {contents = message}
115
- | Ok (package , {file; extra} ) ->
116
- hover state ~file ~line ~col ~extra ~package
91
+ | Ok (package , {file; extra} ) -> hover ~file ~line ~col ~extra ~package
117
92
in
118
93
print_endline result
119
94
120
- let definition state ~file ~line ~col ~extra ~package =
121
- let open TopTypes in
95
+ let definition ~file ~line ~col ~extra ~package =
122
96
let locations =
123
97
extra.SharedTypes. locations
124
98
|> List. filter (fun (l , _ ) -> not l.Location. loc_ghost)
@@ -133,12 +107,7 @@ let definition state ~file ~line ~col ~extra ~package =
133
107
| SharedTypes. LModule _ | TopLevelModule _ -> true
134
108
| TypeDefinition _ | Typed _ | Constant _ | Explanation _ -> false
135
109
in
136
- let uriLocOpt =
137
- References. definitionForLoc ~paths ForModule:package.pathsForModule ~file
138
- ~get Uri:(State. fileForUri state)
139
- ~get Module:(State. fileForModule state ~package )
140
- loc
141
- in
110
+ let uriLocOpt = References. definitionForLoc ~package ~file loc in
142
111
match uriLocOpt with
143
112
| None -> Protocol. null
144
113
| Some (uri2 , loc ) ->
@@ -155,19 +124,15 @@ let definition state ~file ~line ~col ~extra ~package =
155
124
{uri = Uri2. toString uri2; range = Utils. cmtLocToRange loc})
156
125
157
126
let definition ~path ~line ~col =
158
- let state = TopTypes. empty () in
159
- let filePath = Files. maybeConcat (Unix. getcwd () ) path in
160
- let uri = Uri2. fromPath filePath in
127
+ let uri = Uri2. fromLocalPath path in
161
128
let result =
162
- match State . getFullFromCmt ~state ~uri with
129
+ match ProcessCmt . getFullFromCmt ~uri with
163
130
| Error _message -> Protocol. null
164
- | Ok (package , {file; extra} ) ->
165
- definition state ~file ~line ~col ~extra ~package
131
+ | Ok (package , {file; extra} ) -> definition ~file ~line ~col ~extra ~package
166
132
in
167
133
print_endline result
168
134
169
- let references state ~file ~line ~col ~extra ~package =
170
- let open TopTypes in
135
+ let references ~file ~line ~col ~extra ~package =
171
136
let locations =
172
137
extra.SharedTypes. locations
173
138
|> List. filter (fun (l , _ ) -> not l.Location. loc_ghost)
@@ -178,12 +143,7 @@ let references state ~file ~line ~col ~extra ~package =
178
143
| None -> Protocol. null
179
144
| Some (_ , loc ) ->
180
145
let allReferences =
181
- References. allReferencesForLoc ~paths ForModule:package.pathsForModule
182
- ~file ~extra ~all Modules:package.localModules
183
- ~get Uri:(State. fileForUri state)
184
- ~get Module:(State. fileForModule state ~package )
185
- ~get Extra:(State. extraForModule state ~package )
186
- loc
146
+ References. allReferencesForLoc ~package ~file ~extra loc
187
147
in
188
148
let allLocs =
189
149
allReferences
@@ -202,14 +162,11 @@ let references state ~file ~line ~col ~extra ~package =
202
162
" [\n " ^ (allLocs |> String. concat " ,\n " ) ^ " \n ]"
203
163
204
164
let references ~path ~line ~col =
205
- let state = TopTypes. empty () in
206
- let filePath = Files. maybeConcat (Unix. getcwd () ) path in
207
- let uri = Uri2. fromPath filePath in
165
+ let uri = Uri2. fromLocalPath path in
208
166
let result =
209
- match State . getFullFromCmt ~state ~uri with
167
+ match ProcessCmt . getFullFromCmt ~uri with
210
168
| Error _message -> Protocol. null
211
- | Ok (package , {file; extra} ) ->
212
- references state ~file ~line ~col ~extra ~package
169
+ | Ok (package , {file; extra} ) -> references ~file ~line ~col ~extra ~package
213
170
in
214
171
print_endline result
215
172
0 commit comments