Skip to content

Commit 7cca91a

Browse files
committed
debug changes
<!-- ps-id: fcc53d5e-89b6-4f93-a7ff-3054691846db -->
1 parent 2d216d5 commit 7cca91a

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

lsp/src/text_document.ml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,24 @@ let version (t : t) = t.document.version
133133

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

136+
let debug =
137+
match Sys.getenv_opt "OCAMLLSP_DEBUG_CHANGES" with
138+
| None -> None
139+
| Some f -> Some (open_out f)
140+
141+
let () =
142+
at_exit (fun () ->
143+
match debug with
144+
| None -> ()
145+
| Some f -> close_out f)
146+
136147
let apply_change encoding text (change : TextDocumentContentChangeEvent.t) =
137148
match change.range with
138149
| None -> change.text
139150
| Some range ->
151+
(match debug with
152+
| None -> ()
153+
| Some out -> Printf.fprintf out "%s\n---\n" text);
140154
let start_offset, end_offset =
141155
let utf8 = text in
142156
match encoding with
@@ -153,12 +167,28 @@ let apply_change encoding text (change : TextDocumentContentChangeEvent.t) =
153167
|> Array_view.make ~pos:0 |> Substring.concat
154168

155169
let apply_content_changes ?version t changes =
170+
(match debug with
171+
| None -> ()
172+
| Some out ->
173+
Printf.fprintf
174+
out
175+
"changes:\n%s\n---\n%s\n---\n"
176+
(Yojson.Safe.pretty_to_string
177+
~std:false
178+
(`List
179+
(List.map changes ~f:TextDocumentContentChangeEvent.yojson_of_t)))
180+
t.document.text);
156181
let text =
157182
List.fold_left
158183
~f:(apply_change t.position_encoding)
159184
~init:t.document.text
160185
changes
161186
in
187+
(match debug with
188+
| None -> ()
189+
| Some out ->
190+
Printf.fprintf out "%s\n---\n" text;
191+
flush out);
162192
let document = { t.document with text } in
163193
let document =
164194
match version with

0 commit comments

Comments
 (0)