Skip to content

Commit 642d4f1

Browse files
committed
clean up use of pos
1 parent cd065b4 commit 642d4f1

File tree

1 file changed

+21
-31
lines changed

1 file changed

+21
-31
lines changed

analysis/src/SemanticTokens.ml

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,7 @@ let emitVariable ~id ~debug ~loc emitter =
167167
emitter |> emitFromLoc ~loc ~type_:Variable
168168

169169
let emitJsxOpen ~lid ~debug ~loc emitter =
170-
emitter
171-
|> emitLongident
172-
~pos:(Pos.ofLexing loc.Location.loc_start)
173-
~lid ~jsx:true ~debug
170+
emitter |> emitLongident ~pos:(Loc.start loc) ~lid ~jsx:true ~debug
174171

175172
let emitJsxClose ~lid ~debug ~pos emitter =
176173
emitter |> emitLongident ~backwards:true ~pos ~lid ~jsx:true ~debug
@@ -181,21 +178,17 @@ let emitJsxTag ~debug ~name ~pos emitter =
181178

182179
let emitType ~lid ~debug ~loc emitter =
183180
emitter
184-
|> emitLongident ~lowerCaseToken:Token.Type
185-
~pos:(Pos.ofLexing loc.Location.loc_start)
186-
~lid ~debug
181+
|> emitLongident ~lowerCaseToken:Token.Type ~pos:(Loc.start loc) ~lid ~debug
187182

188183
let emitRecordLabel ~(label : Longident.t Location.loc) ~debug emitter =
189184
emitter
190-
|> emitLongident ~lowerCaseToken:Token.Property
191-
~pos:(Pos.ofLexing label.loc.loc_start)
192-
~posEnd:(Some (Pos.ofLexing label.loc.loc_end))
185+
|> emitLongident ~lowerCaseToken:Token.Property ~pos:(Loc.start label.loc)
186+
~posEnd:(Some (Loc.end_ label.loc))
193187
~lid:label.txt ~debug
194188

195189
let emitVariant ~(name : Longident.t Location.loc) ~debug emitter =
196190
emitter
197-
|> emitLongident ~lastToken:(Some Token.EnumMember)
198-
~pos:(Pos.ofLexing name.loc.loc_start)
191+
|> emitLongident ~lastToken:(Some Token.EnumMember) ~pos:(Loc.start name.loc)
199192
~lid:name.txt ~debug
200193

201194
let command ~debug ~emitter ~path =
@@ -243,9 +236,8 @@ let command ~debug ~emitter ~path =
243236
| Pexp_ident {txt = lid; loc} ->
244237
if lid <> Lident "not" then
245238
emitter
246-
|> emitLongident
247-
~pos:(Pos.ofLexing loc.loc_start)
248-
~posEnd:(Some (Pos.ofLexing loc.loc_end))
239+
|> emitLongident ~pos:(Loc.start loc)
240+
~posEnd:(Some (Loc.end_ loc))
249241
~lid ~debug;
250242
Ast_iterator.default_iterator.expr iterator e
251243
| Pexp_apply ({pexp_desc = Pexp_ident lident; pexp_loc}, args)
@@ -261,23 +253,22 @@ let command ~debug ~emitter ~path =
261253
emitter (* --> <div... *)
262254
|> emitJsxTag ~debug ~name:"<"
263255
~pos:
264-
(let pos = Pos.ofLexing e.pexp_loc.loc_start in
256+
(let pos = Loc.start e.pexp_loc in
265257
(fst pos, snd pos - 1 (* the AST skips the loc of < somehow *)));
266258
emitter |> emitJsxOpen ~lid:lident.txt ~debug ~loc:pexp_loc;
267259

268260
let posOfGreatherthanAfterProps =
269261
let rec loop = function
270-
| (Asttypes.Labelled "children", {Parsetree.pexp_loc = {loc_start}})
271-
:: _ ->
272-
Pos.ofLexing loc_start
262+
| (Asttypes.Labelled "children", {Parsetree.pexp_loc}) :: _ ->
263+
Loc.start pexp_loc
273264
| _ :: args -> loop args
274265
| [] -> (* should not happen *) (-1, -1)
275266
in
276267

277268
loop args
278269
in
279270
let posOfFinalGreatherthan =
280-
let pos = Pos.ofLexing e.pexp_loc.loc_end in
271+
let pos = Loc.end_ e.pexp_loc in
281272
(fst pos, snd pos - 1)
282273
in
283274
let selfClosing =
@@ -286,10 +277,10 @@ let command ~debug ~emitter ~path =
286277
(* there's an off-by one somehow in the AST *)
287278
in
288279
(if not selfClosing then
289-
let lineStart, colStart = Pos.ofLexing pexp_loc.loc_start in
290-
let lineEnd, colEnd = Pos.ofLexing pexp_loc.loc_end in
280+
let lineStart, colStart = Loc.start pexp_loc in
281+
let lineEnd, colEnd = Loc.end_ pexp_loc in
291282
let length = if lineStart = lineEnd then colEnd - colStart else 0 in
292-
let lineEndWhole, colEndWhole = Pos.ofLexing e.pexp_loc.loc_end in
283+
let lineEndWhole, colEndWhole = Loc.end_ e.pexp_loc in
293284
if length > 0 && colEndWhole > length then (
294285
emitter
295286
|> emitJsxClose ~debug ~lid:lident.txt
@@ -329,23 +320,23 @@ let command ~debug ~emitter ~path =
329320
(me : Parsetree.module_expr) =
330321
match me.pmod_desc with
331322
| Pmod_ident {txt = lid; loc} ->
332-
emitter |> emitLongident ~pos:(Pos.ofLexing loc.loc_start) ~lid ~debug;
323+
emitter |> emitLongident ~pos:(Loc.start loc) ~lid ~debug;
333324
Ast_iterator.default_iterator.module_expr iterator me
334325
| _ -> Ast_iterator.default_iterator.module_expr iterator me
335326
in
336327
let module_binding (iterator : Ast_iterator.iterator)
337328
(mb : Parsetree.module_binding) =
338329
emitter
339330
|> emitLongident
340-
~pos:(Pos.ofLexing mb.pmb_name.loc.loc_start)
331+
~pos:(Loc.start mb.pmb_name.loc)
341332
~lid:(Longident.Lident mb.pmb_name.txt) ~debug;
342333
Ast_iterator.default_iterator.module_binding iterator mb
343334
in
344335
let module_declaration (iterator : Ast_iterator.iterator)
345336
(md : Parsetree.module_declaration) =
346337
emitter
347338
|> emitLongident
348-
~pos:(Pos.ofLexing md.pmd_name.loc.loc_start)
339+
~pos:(Loc.start md.pmd_name.loc)
349340
~lid:(Longident.Lident md.pmd_name.txt) ~debug;
350341
Ast_iterator.default_iterator.module_declaration iterator md
351342
in
@@ -354,25 +345,24 @@ let command ~debug ~emitter ~path =
354345
match mt.pmty_desc with
355346
| Pmty_ident {txt = lid; loc} ->
356347
emitter
357-
|> emitLongident ~upperCaseToken:Token.Type
358-
~pos:(Pos.ofLexing loc.loc_start)
359-
~lid ~debug;
348+
|> emitLongident ~upperCaseToken:Token.Type ~pos:(Loc.start loc) ~lid
349+
~debug;
360350
Ast_iterator.default_iterator.module_type iterator mt
361351
| _ -> Ast_iterator.default_iterator.module_type iterator mt
362352
in
363353
let module_type_declaration (iterator : Ast_iterator.iterator)
364354
(mtd : Parsetree.module_type_declaration) =
365355
emitter
366356
|> emitLongident ~upperCaseToken:Token.Type
367-
~pos:(Pos.ofLexing mtd.pmtd_name.loc.loc_start)
357+
~pos:(Loc.start mtd.pmtd_name.loc)
368358
~lid:(Longident.Lident mtd.pmtd_name.txt) ~debug;
369359
Ast_iterator.default_iterator.module_type_declaration iterator mtd
370360
in
371361
let open_description (iterator : Ast_iterator.iterator)
372362
(od : Parsetree.open_description) =
373363
emitter
374364
|> emitLongident
375-
~pos:(Pos.ofLexing od.popen_lid.loc.loc_start)
365+
~pos:(Loc.start od.popen_lid.loc)
376366
~lid:od.popen_lid.txt ~debug;
377367
Ast_iterator.default_iterator.open_description iterator od
378368
in

0 commit comments

Comments
 (0)