@@ -117,178 +117,35 @@ let tick = state => {
117
117
let orLog = (message, v) =>
118
118
switch (v) {
119
119
| None =>
120
- print_endline (message);
120
+ prerr_endline (message);
121
121
None ;
122
122
| Some (x ) => Some (x)
123
123
};
124
124
125
125
let processFile = (~state, ~uri, ~quiet) => {
126
126
switch (Packages . getPackage(~reportDiagnostics= (_, _) => () , uri, state)) {
127
127
| Error (message ) =>
128
- print_endline (" Unable to get package: " ++ uri);
129
- print_endline (message);
128
+ prerr_endline (" Unable to get package: " ++ uri);
129
+ prerr_endline (message);
130
130
None ;
131
131
| Ok (package ) =>
132
132
switch (State . getCompilationResult(uri, state, ~package)) {
133
133
| Error (message ) =>
134
- print_endline (" Invalid compilation result: " ++ message);
134
+ prerr_endline (" Invalid compilation result: " ++ message);
135
135
Some ((package, None ));
136
136
| Ok (Success (_message , contents )) =>
137
137
if (! quiet) {
138
- print_endline (" Good: " ++ uri);
138
+ prerr_endline (" Good: " ++ uri);
139
139
};
140
140
Some ((package, Some (contents)));
141
141
| Ok (TypeError (message , _ ) | SyntaxError (message , _ , _ )) =>
142
- print_endline (" Error compiling: " ++ uri);
143
- print_endline (message);
142
+ prerr_endline (" Error compiling: " ++ uri);
143
+ prerr_endline (message);
144
144
Some ((package, None ));
145
145
}
146
146
};
147
147
};
148
148
149
- let singleDefinition = (~quiet, rootPath, filePath, line, col) => {
150
- Log . log(
151
- "# Reason Langauge Server - checking individual files to ensure they load & process correctly" ,
152
- );
153
- let rootPath =
154
- rootPath == "." ? Unix . getcwd() : maybeConcat(Unix . getcwd() , rootPath);
155
- let filePath = maybeConcat(Unix . getcwd() , filePath);
156
- let state = {
157
- ... TopTypes . empty(),
158
- rootPath,
159
- rootUri: Utils . toUri(rootPath),
160
- };
161
-
162
- let uri = Utils . toUri(filePath);
163
- switch (processFile(~state, ~uri, ~quiet)) {
164
- | Some ((package , Some ({file, extra}))) =>
165
- let _ = {
166
- let %opt_consume (location, loc) =
167
- References . locForPos (~extra , (line , col - 1 ))
168
- |> orLog (
169
- Printf . sprintf (
170
- "Nothing definable found at % s :% d :% d " ,
171
- filePath ,
172
- line ,
173
- col ,
174
- ),
175
- );
176
- let %opt_consume (fname, dlocation) =
177
- References . definitionForLoc (
178
- ~pathsForModule =package .pathsForModule ,
179
- ~file ,
180
- ~getUri =State . fileForUri (state , ~package ),
181
- ~getModule =State . fileForModule (state , ~package ),
182
- loc ,
183
- )
184
- |> orLog (
185
- Printf . sprintf (
186
- "Unable to resolve a definition for % s :% d :% d " ,
187
- filePath ,
188
- location .loc_start .pos_lnum ,
189
- location .loc_start .pos_cnum - location .loc_start .pos_bol + 1 ,
190
- ),
191
- );
192
- let %opt_consume fname = Utils.parseUri(fname);
193
- Printf . printf (
194
- "Definition for % s :% d :% d found at % s :% d :% d \n " ,
195
- filePath ,
196
- location .loc_start .pos_lnum ,
197
- location .loc_start .pos_cnum - location .loc_start .pos_bol + 1 ,
198
- fname ,
199
- dlocation .loc_start .pos_lnum ,
200
- dlocation .loc_start .pos_cnum - dlocation .loc_start .pos_bol + 1 ,
201
- );
202
- };
203
- print_endline(" Good: " ++ uri);
204
- | _ => ()
205
- };
206
- };
207
-
208
- let check = (~definitions, ~quiet, rootPath, files) => {
209
- Log . log(
210
- "# Reason Langauge Server - checking individual files to ensure they load & process correctly" ,
211
- );
212
- let rootPath =
213
- rootPath == "." ? Unix . getcwd() : maybeConcat(Unix . getcwd() , rootPath);
214
- let state = {
215
- ... TopTypes . empty(),
216
- rootPath,
217
- rootUri: Utils . toUri(rootPath),
218
- };
219
- files
220
- |> List . iter(filePath => {
221
- let filePath = maybeConcat(Unix . getcwd() , filePath);
222
- let uri = Utils . toUri(filePath);
223
- switch (processFile(~state, ~uri, ~quiet)) {
224
- | Some ((package , result )) =>
225
- if (! definitions) {
226
- Log . log(State . Show . state(state, package));
227
- } else {
228
- switch (result) {
229
- | None => ()
230
- | Some ({file, extra}) =>
231
- let missing = ref ([] );
232
- extra. locations
233
- |> List . iter(((location, loc)) => {
234
- switch (loc) {
235
- | SharedTypes . Typed (_ , LocalReference (tag , Type ))
236
- when tag <= 15 =>
237
- ()
238
- | Typed (
239
- _ ,
240
- GlobalReference (_ , _ , Constructor ("[]" | "::" )),
241
- ) =>
242
- ()
243
- | Typed (
244
- _ ,
245
- (LocalReference (_ , _ ) | GlobalReference (_ , _ , _ )) as t ,
246
- )
247
- when ! location. Location . loc_ghost =>
248
- switch (
249
- References . definitionForLoc(
250
- ~pathsForModule= package. pathsForModule,
251
- ~file,
252
- ~getUri= State . fileForUri(state, ~package),
253
- ~getModule= State . fileForModule(state, ~package),
254
- loc,
255
- )
256
- ) {
257
- | None =>
258
- // missing := 1 + missing^;
259
- missing :=
260
- [
261
- Printf . sprintf(
262
- " - \" % s :% d :% d \" : % s " ,
263
- filePath,
264
- location. loc_start. pos_lnum,
265
- location. loc_start. pos_cnum
266
- - location. loc_start. pos_bol
267
- + 1 ,
268
- SharedTypes . locKindToString(t),
269
- ),
270
- ... missing^,
271
- ]
272
- | Some (_defn ) => ()
273
- }
274
- | _ => ()
275
- }
276
- });
277
- if (missing^ != [] ) {
278
- print_endline(filePath);
279
- print_endline(
280
- " > " ++ string_of_int(List . length(missing^ )) ++ " missing" ,
281
- );
282
- missing^ |> List . iter(text => print_endline(text));
283
- };
284
- };
285
- }
286
- | _ => ()
287
- };
288
- });
289
- Log . log("Ok" );
290
- };
291
-
292
149
let parseArgs = args => {
293
150
switch (args) {
294
151
| [] => assert (false )
@@ -331,7 +188,7 @@ The dump command can also omit `:line:column`, to show results for every positio
331
188
|} ;
332
189
333
190
let showHelp = () => {
334
- print_endline (help);
191
+ prerr_endline (help);
335
192
};
336
193
337
194
let main = () => {
@@ -353,28 +210,6 @@ let main = () => {
353
210
);
354
211
Log . log("Finished" );
355
212
Log . out^ |?< close_out;
356
- | (opts , [ "definition" , rootPath , file , line , col ] ) =>
357
- let line = int_of_string(line);
358
- let col = int_of_string(col);
359
- let quiet = hasOpts(opts, [ "-q" , "--quiet" ] );
360
- if (opts |> hasVerbose) {
361
- Log . spamError := true ;
362
- References . debugReferences := true ;
363
- MerlinFile . debug := true ;
364
- };
365
- singleDefinition(~quiet, rootPath, file, line, col);
366
- | (opts , [ "check" , rootPath , ... files ] ) =>
367
- let definitions = hasOpts(opts, [ "-d" , "--definitions" ] );
368
- let quiet = hasOpts(opts, [ "-q" , "--quiet" ] );
369
- if (opts |> hasVerbose) {
370
- Log . spamError := true ;
371
- // if (!definitions) {
372
- MerlinFile . debug := true ;
373
- // }
374
- } else {
375
- Log . spamError := false ;
376
- };
377
- check(~definitions, ~quiet, rootPath, files);
378
213
| (_opts , [ "dump" , ... files ] ) => EditorSupportCommands . dump(files)
379
214
| (_opts , [ "complete" , pathWithPos , currentFile ] ) =>
380
215
EditorSupportCommands . complete(~pathWithPos, ~currentFile)
0 commit comments