Skip to content

Commit

Permalink
debug changes
Browse files Browse the repository at this point in the history
<!-- ps-id: fcc53d5e-89b6-4f93-a7ff-3054691846db -->
  • Loading branch information
rgrinberg committed Jan 11, 2023
1 parent 2d216d5 commit 41d3f56
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lsp/src/text_document.ml
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,24 @@ let version (t : t) = t.document.version

let languageId (t : t) = t.document.languageId

let debug =
match Sys.getenv_opt "OCAMLLSP_DEBUG_CHANGES" with
| None -> None
| Some f -> Some (open_out f)

let () =
at_exit (fun () ->
match debug with
| None -> ()
| Some f -> close_out f)

let apply_change encoding text (change : TextDocumentContentChangeEvent.t) =
match change.range with
| None -> change.text
| Some range ->
(match debug with
| None -> ()
| Some out -> Printf.fprintf out "%s\n---\n" text);
let start_offset, end_offset =
let utf8 = text in
match encoding with
Expand All @@ -153,12 +167,28 @@ let apply_change encoding text (change : TextDocumentContentChangeEvent.t) =
|> Array_view.make ~pos:0 |> Substring.concat

let apply_content_changes ?version t changes =
(match debug with
| None -> ()
| Some out ->
Printf.fprintf
out
"changes:\n%s\n---\n%s\n---\n"
(Yojson.Safe.pretty_to_string
~std:false
(`List
(List.map changes ~f:TextDocumentContentChangeEvent.yojson_of_t)))
t.document.text);
let text =
List.fold_left
~f:(apply_change t.position_encoding)
~init:t.document.text
changes
in
(match debug with
| None -> ()
| Some out ->
Printf.fprintf out "%s\n---\n" text;
flush out);
let document = { t.document with text } in
let document =
match version with
Expand Down

0 comments on commit 41d3f56

Please sign in to comment.