@@ -199,6 +199,12 @@ let send_move_cursor uri range =
199
199
let notification = Notification.Server. MoveCursor {uri;range} in
200
200
output_notification notification
201
201
202
+ let send_error_notification message =
203
+ let type_ = MessageType. Error in
204
+ let params = ShowMessageParams. {type_; message} in
205
+ let notification = Lsp.Server_notification. ShowMessage params in
206
+ output_json @@ Jsonrpc.Notification. yojson_of_t @@ Lsp.Server_notification. to_jsonrpc notification
207
+
202
208
let update_view uri st =
203
209
if (Dm.ExecutionManager. is_diagnostics_enabled () ) then (
204
210
send_highlights uri st;
@@ -219,7 +225,9 @@ let run_documents () =
219
225
let textDocumentDidOpen params =
220
226
let Lsp.Types.DidOpenTextDocumentParams. { textDocument = { uri; text } } = params in
221
227
let vst, opts = get_init_state () in
222
- let st, events = Dm.DocumentManager. init vst ~opts uri ~text in
228
+ let st, events = try Dm.DocumentManager. init vst ~opts uri ~text with
229
+ e -> raise e
230
+ in
223
231
let (st, events') =
224
232
if ! check_mode = Settings.Mode. Continuous then
225
233
Dm.DocumentManager. interpret_in_background st
@@ -466,7 +474,11 @@ let dispatch_request : type a. Jsonrpc.Id.t -> a Request.Client.t -> (a,string)
466
474
let dispatch_std_notification =
467
475
let open Lsp.Client_notification in function
468
476
| TextDocumentDidOpen params -> log " Recieved notification: textDocument/didOpen" ;
469
- textDocumentDidOpen params
477
+ begin try textDocumentDidOpen params with
478
+ exn -> let info = Exninfo. capture exn in
479
+ let message = " Error while opening document. " ^ Pp. string_of_ppcmds @@ CErrors. iprint_no_report info in
480
+ send_error_notification message; []
481
+ end
470
482
| TextDocumentDidChange params -> log " Recieved notification: textDocument/didChange" ;
471
483
textDocumentDidChange params
472
484
| TextDocumentDidClose params -> log " Recieved notification: textDocument/didClose" ;
0 commit comments