Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debug changes #1007

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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