Skip to content

Commit 444dae2

Browse files
authored
Merge pull request #696 from coq-community/invalid-filename
Send a message instead of crashing when filename is invalid.
2 parents 6a30d47 + 580c21a commit 444dae2

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

language-server/dm/documentManager.ml

+4-2
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,11 @@ let validate_document state =
230230

231231
let init init_vs ~opts uri ~text =
232232
Vernacstate.unfreeze_full_state init_vs;
233-
let top = Coqargs.(dirpath_of_top (TopPhysical (DocumentUri.to_path uri))) in
233+
let top = try Coqargs.(dirpath_of_top (TopPhysical (DocumentUri.to_path uri))) with
234+
e -> raise e
235+
in
234236
Coqinit.start_library ~top opts;
235-
let init_vs = Vernacstate.freeze_full_state () in
237+
let init_vs = Vernacstate.freeze_full_state () in
236238
let document = Document.create_document init_vs.Vernacstate.synterp text in
237239
let execution_state, feedback = ExecutionManager.init init_vs in
238240
let st = { uri; opts; init_vs; document; execution_state; observe_id = None } in

language-server/vscoqtop/lspManager.ml

+14-2
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,12 @@ let send_move_cursor uri range =
199199
let notification = Notification.Server.MoveCursor {uri;range} in
200200
output_notification notification
201201

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+
202208
let update_view uri st =
203209
if (Dm.ExecutionManager.is_diagnostics_enabled ()) then (
204210
send_highlights uri st;
@@ -219,7 +225,9 @@ let run_documents () =
219225
let textDocumentDidOpen params =
220226
let Lsp.Types.DidOpenTextDocumentParams.{ textDocument = { uri; text } } = params in
221227
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
223231
let (st, events') =
224232
if !check_mode = Settings.Mode.Continuous then
225233
Dm.DocumentManager.interpret_in_background st
@@ -466,7 +474,11 @@ let dispatch_request : type a. Jsonrpc.Id.t -> a Request.Client.t -> (a,string)
466474
let dispatch_std_notification =
467475
let open Lsp.Client_notification in function
468476
| 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
470482
| TextDocumentDidChange params -> log "Recieved notification: textDocument/didChange";
471483
textDocumentDidChange params
472484
| TextDocumentDidClose params -> log "Recieved notification: textDocument/didClose";

0 commit comments

Comments
 (0)