ocaml / ocaml-lsp

OCaml Language Server Protocol implementation
Other
771 stars 121 forks source link

ocaml-lsp crashes when some characters are below the comment #695

Open v1nh1shungry opened 2 years ago

v1nh1shungry commented 2 years ago

I am working with ocaml-lsp in VS Code. When I wrote some comments, go to the new line, and typed * (by accident), ocaml-lsp crashed.

(**)
*

Here are logs.

[Error - 22:10:24] Request textDocument/documentSymbol failed.
  Message: uncaught exception
  Code: -32603 
[object Object]
[Error - 22:10:24] Request textDocument/codeAction failed.
  Message: uncaught exception
  Code: -32603 
[object Object]
[Error - 22:10:24] Request textDocument/foldingRange failed.
  Message: uncaught exception
  Code: -32603 
[object Object]
[Warn  - 22:10:24] failed to poll dune registry. Unix.Unix_error(Unix.ENOENT, "stat", "/home/vinh/.local/share/dune/rpc")
/-----------------------------------------------------------------------
| Internal error: Uncaught exception.
| Failure("Empty file")
| Raised at CamlinternalLazy.force_lazy_block.(fun) in file "camlinternalLazy.ml", line 35, characters 56-63
| Called from CamlinternalLazy.force_lazy_block in file "camlinternalLazy.ml", line 31, characters 17-27
| Re-raised at CamlinternalLazy.force_lazy_block in file "camlinternalLazy.ml", line 36, characters 4-11
| Called from Merlin_kernel__Mpipeline.typer_result in file "ocaml-lsp-server/vendor/merlin/src/kernel/mpipeline.ml" (inlined), line 128, characters 21-30
| Called from Ocaml_lsp_server__Action_type_annotate.check_typeable_context in file "ocaml-lsp-server/src/code_actions/action_type_annotate.ml", line 8, characters 14-45
| Called from Ocaml_lsp_server__Action_type_annotate.code_action.(fun) in file "ocaml-lsp-server/src/code_actions/action_type_annotate.ml", line 46, characters 22-63
| Called from Merlin_utils__Std.let_ref in file "ocaml-lsp-server/vendor/merlin/src/utils/std.ml", line 686, characters 8-12
| Re-raised at Merlin_utils__Std.let_ref in file "ocaml-lsp-server/vendor/merlin/src/utils/std.ml", line 688, characters 30-39
| Called from Merlin_utils__Misc.try_finally in file "ocaml-lsp-server/vendor/merlin/src/utils/misc.ml", line 45, characters 8-15
| Re-raised at Merlin_utils__Misc.try_finally in file "ocaml-lsp-server/vendor/merlin/src/utils/misc.ml", line 62, characters 10-24
| Called from Stdlib__Fun.protect in file "fun.ml", line 33, characters 8-15
| Re-raised at Stdlib__Fun.protect in file "fun.ml", line 38, characters 6-52
| Called from Merlin_kernel__Mocaml.with_state in file "ocaml-lsp-server/vendor/merlin/src/kernel/mocaml.ml", line 18, characters 8-38
| Re-raised at Merlin_kernel__Mocaml.with_state in file "ocaml-lsp-server/vendor/merlin/src/kernel/mocaml.ml", line 20, characters 42-53
| Called from Stdune__Exn_with_backtrace.try_with in file "otherlibs/stdune/exn_with_backtrace.ml", line 9, characters 8-12
| Re-raised at CamlinternalLazy.force_lazy_block.(fun) in file "camlinternalLazy.ml", line 35, characters 56-63
| Called from CamlinternalLazy.force_lazy_block in file "camlinternalLazy.ml", line 31, characters 17-27
| Re-raised at CamlinternalLazy.force_lazy_block in file "camlinternalLazy.ml", line 36, characters 4-11
| Called from Merlin_kernel__Mpipeline.typer_result in file "ocaml-lsp-server/vendor/merlin/src/kernel/mpipeline.ml" (inlined), line 128, characters 21-30
| Called from Query_commands.dispatch in file "ocaml-lsp-server/vendor/merlin/src/frontend/query_commands.ml", line 481, characters 16-47
| Called from Merlin_utils__Std.let_ref in file "ocaml-lsp-server/vendor/merlin/src/utils/std.ml", line 686, characters 8-12
| Re-raised at Merlin_utils__Std.let_ref in file "ocaml-lsp-server/vendor/merlin/src/utils/std.ml", line 688, characters 30-39
| Called from Merlin_utils__Misc.try_finally in file "ocaml-lsp-server/vendor/merlin/src/utils/misc.ml", line 45, characters 8-15
| Re-raised at Merlin_utils__Misc.try_finally in file "ocaml-lsp-server/vendor/merlin/src/utils/misc.ml", line 62, characters 10-24
| Called from Stdlib__Fun.protect in file "fun.ml", line 33, characters 8-15
| Re-raised at Stdlib__Fun.protect in file "fun.ml", line 38, characters 6-52
| Called from Merlin_kernel__Mocaml.with_state in file "ocaml-lsp-server/vendor/merlin/src/kernel/mocaml.ml", line 18, characters 8-38
| Re-raised at Merlin_kernel__Mocaml.with_state in file "ocaml-lsp-server/vendor/merlin/src/kernel/mocaml.ml", line 20, characters 42-53
| Called from Stdune__Exn_with_backtrace.try_with in file "otherlibs/stdune/exn_with_backtrace.ml", line 9, characters 8-12
| Re-raised at CamlinternalLazy.force_lazy_block.(fun) in file "camlinternalLazy.ml", line 35, characters 56-63
| Called from CamlinternalLazy.force_lazy_block in file "camlinternalLazy.ml", line 31, characters 17-27
| Re-raised at CamlinternalLazy.force_lazy_block in file "camlinternalLazy.ml", line 36, characters 4-11
| Called from Merlin_kernel__Mpipeline.typer_result in file "ocaml-lsp-server/vendor/merlin/src/kernel/mpipeline.ml" (inlined), line 128, characters 21-30
| Called from Query_commands.dispatch in file "ocaml-lsp-server/vendor/merlin/src/frontend/query_commands.ml", line 481, characters 16-47
| Called from Merlin_utils__Std.let_ref in file "ocaml-lsp-server/vendor/merlin/src/utils/std.ml", line 686, characters 8-12
| Re-raised at Merlin_utils__Std.let_ref in file "ocaml-lsp-server/vendor/merlin/src/utils/std.ml", line 688, characters 30-39
| Called from Merlin_utils__Misc.try_finally in file "ocaml-lsp-server/vendor/merlin/src/utils/misc.ml", line 45, characters 8-15
| Re-raised at Merlin_utils__Misc.try_finally in file "ocaml-lsp-server/vendor/merlin/src/utils/misc.ml", line 62, characters 10-24
| Called from Stdlib__Fun.protect in file "fun.ml", line 33, characters 8-15
| Re-raised at Stdlib__Fun.protect in file "fun.ml", line 38, characters 6-52
| Called from Merlin_kernel__Mocaml.with_state in file "ocaml-lsp-server/vendor/merlin/src/kernel/mocaml.ml", line 18, characters 8-38
| Re-raised at Merlin_kernel__Mocaml.with_state in file "ocaml-lsp-server/vendor/merlin/src/kernel/mocaml.ml", line 20, characters 42-53
| Called from Stdune__Exn_with_backtrace.try_with in file "otherlibs/stdune/exn_with_backtrace.ml", line 9, characters 8-12
| Re-raised at CamlinternalLazy.force_lazy_block.(fun) in file "camlinternalLazy.ml", line 35, characters 56-63
| Called from CamlinternalLazy.force_lazy_block in file "camlinternalLazy.ml", line 31, characters 17-27
| Re-raised at CamlinternalLazy.force_lazy_block in file "camlinternalLazy.ml", line 36, characters 4-11
| Called from Merlin_kernel__Mpipeline.reader_parsetree in file "ocaml-lsp-server/vendor/merlin/src/kernel/mpipeline.ml" (inlined), line 115, characters 30-40
| Called from Ocaml_lsp_server__Folding_range.compute.(fun) in file "ocaml-lsp-server/src/folding_range.ml", line 235, characters 28-63
| Called from Merlin_utils__Std.let_ref in file "ocaml-lsp-server/vendor/merlin/src/utils/std.ml", line 686, characters 8-12
| Re-raised at Merlin_utils__Std.let_ref in file "ocaml-lsp-server/vendor/merlin/src/utils/std.ml", line 688, characters 30-39
| Called from Merlin_utils__Misc.try_finally in file "ocaml-lsp-server/vendor/merlin/src/utils/misc.ml", line 45, characters 8-15
| Re-raised at Merlin_utils__Misc.try_finally in file "ocaml-lsp-server/vendor/merlin/src/utils/misc.ml", line 62, characters 10-24
| Called from Stdlib__Fun.protect in file "fun.ml", line 33, characters 8-15
| Re-raised at Stdlib__Fun.protect in file "fun.ml", line 38, characters 6-52
| Called from Merlin_kernel__Mocaml.with_state in file "ocaml-lsp-server/vendor/merlin/src/kernel/mocaml.ml", line 18, characters 8-38
| Re-raised at Merlin_kernel__Mocaml.with_state in file "ocaml-lsp-server/vendor/merlin/src/kernel/mocaml.ml", line 20, characters 42-53
| Called from Stdune__Exn_with_backtrace.try_with in file "otherlibs/stdune/exn_with_backtrace.ml", line 9, characters 8-12
| Re-raised at CamlinternalLazy.force_lazy_block.(fun) in file "camlinternalLazy.ml", line 35, characters 56-63
| Called from CamlinternalLazy.force_lazy_block in file "camlinternalLazy.ml", line 31, characters 17-27
| Re-raised at CamlinternalLazy.force_lazy_block in file "camlinternalLazy.ml", line 36, characters 4-11
| Called from Merlin_kernel__Mpipeline.typer_result in file "ocaml-lsp-server/vendor/merlin/src/kernel/mpipeline.ml" (inlined), line 128, characters 21-30
| Called from Query_commands.dispatch in file "ocaml-lsp-server/vendor/merlin/src/frontend/query_commands.ml", line 656, characters 16-47
| Called from Ocaml_lsp_server.set_diagnostics.send.(fun) in file "ocaml-lsp-server/src/ocaml_lsp_server.ml", line 190, characters 18-58
| Called from Merlin_utils__Std.let_ref in file "ocaml-lsp-server/vendor/merlin/src/utils/std.ml", line 686, characters 8-12
| Re-raised at Merlin_utils__Std.let_ref in file "ocaml-lsp-server/vendor/merlin/src/utils/std.ml", line 688, characters 30-39
| Called from Merlin_utils__Misc.try_finally in file "ocaml-lsp-server/vendor/merlin/src/utils/misc.ml", line 45, characters 8-15
| Re-raised at Merlin_utils__Misc.try_finally in file "ocaml-lsp-server/vendor/merlin/src/utils/misc.ml", line 62, characters 10-24
| Called from Stdlib__Fun.protect in file "fun.ml", line 33, characters 8-15
| Re-raised at Stdlib__Fun.protect in file "fun.ml", line 38, characters 6-52
| Called from Merlin_kernel__Mocaml.with_state in file "ocaml-lsp-server/vendor/merlin/src/kernel/mocaml.ml", line 18, characters 8-38
| Re-raised at Merlin_kernel__Mocaml.with_state in file "ocaml-lsp-server/vendor/merlin/src/kernel/mocaml.ml", line 20, characters 42-53
| Called from Stdune__Exn_with_backtrace.try_with in file "otherlibs/stdune/exn_with_backtrace.ml", line 9, characters 8-12
| Re-raised at Stdune__Exn.raise_with_backtrace in file "otherlibs/stdune/exn.ml" (inlined), line 36, characters 27-56
| Called from Stdune__Exn_with_backtrace.reraise in file "otherlibs/stdune/exn_with_backtrace.ml", line 18, characters 33-71
| Called from Fiber__Core.O.(>>|).(fun) in file "src/fiber/core.ml", line 250, characters 36-41
| Called from Fiber__Scheduler.exec in file "src/fiber/scheduler.ml", line 69, characters 8-11
| Re-raised at Stdune__Exn.raise_with_backtrace in file "otherlibs/stdune/exn.ml" (inlined), line 36, characters 27-56
| Called from Stdune__Exn_with_backtrace.reraise in file "otherlibs/stdune/exn_with_backtrace.ml", line 18, characters 33-71
| Called from Fiber__Scheduler.advance.(fun) in file "src/fiber/scheduler.ml", line 191, characters 2-58
| Called from Fiber.run.loop in file "src/fiber/fiber.ml", line 15, characters 30-61
| Called from Stdune__Exn_with_backtrace.try_with in file "otherlibs/stdune/exn_with_backtrace.ml", line 9, characters 8-12
\-----------------------------------------------------------------------

[Error - 22:10:24] Connection to server got closed. Server will not be restarted.

/, ~, $ can cause this too. Maybe more. And I found that if there are something below the evil character then everything is okay.

Can you reproduce this bug? I know my platform may be a bit unusual.

tatchi commented 2 years ago

Thanks for the report, I confirm that I can reproduce it. It seems to happen with the foldingRange and codeAction request too:

[Trace - 7:00:17 PM] Received response 'textDocument/foldingRange - (19)' in 1ms. Request failed: uncaught exception (-32603).
Error data: {
    "exn": "Failure(\"Empty file\")",
    "backtrace": "Raised at Stdlib.failwith in file \"stdlib.ml\", line 29, characters 17-33\nCalled from Merlin_kernel__Mreader_parser.parse in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mreader_parser.ml\", line 175, characters 20-48\nCalled from Merlin_kernel__Mreader_parser.run_parser.(fun) in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mreader_parser.ml\", line 190, characters 6-42\nCalled from Merlin_utils__Misc.try_finally in file \"ocaml-lsp-server/vendor/merlin/src/utils/misc.ml\", line 45, characters 8-15\nRe-raised at Merlin_utils__Misc.try_finally in file \"ocaml-lsp-server/vendor/merlin/src/utils/misc.ml\", line 62, characters 10-24\nCalled from Merlin_kernel__Mreader_parser.make in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mreader_parser.ml\", line 204, characters 20-56\nCalled from Merlin_kernel__Mreader.normal_parse in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mreader.ml\", line 48, characters 15-77\nCalled from Merlin_kernel__Mpipeline.process in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mpipeline.ml\", line 162, characters 19-62\nCalled from CamlinternalLazy.force_lazy_block in file \"camlinternalLazy.ml\", line 31, characters 17-27\nRe-raised at CamlinternalLazy.force_lazy_block in file \"camlinternalLazy.ml\", line 36, characters 4-11\nCalled from Merlin_kernel__Mpipeline.timed_lazy in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mpipeline.ml\", line 17, characters 10-22\nRe-raised at Merlin_kernel__Mpipeline.timed_lazy in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mpipeline.ml\", line 19, characters 34-49\nCalled from CamlinternalLazy.force_lazy_block in file \"camlinternalLazy.ml\", line 31, characters 17-27\nRe-raised at CamlinternalLazy.force_lazy_block in file \"camlinternalLazy.ml\", line 36, characters 4-11\nCalled from Merlin_kernel__Mpipeline.reader_parsetree in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mpipeline.ml\", line 115, characters 30-40\nCalled from Ocaml_lsp_server__Folding_range.compute.(fun) in file \"ocaml-lsp-server/src/folding_range.ml\", line 235, characters 28-63\nCalled from Merlin_utils__Std.let_ref in file \"ocaml-lsp-server/vendor/merlin/src/utils/std.ml\", line 686, characters 8-12\nRe-raised at Merlin_utils__Std.let_ref in file \"ocaml-lsp-server/vendor/merlin/src/utils/std.ml\", line 688, characters 30-39\nCalled from Merlin_utils__Misc.try_finally in file \"ocaml-lsp-server/vendor/merlin/src/utils/misc.ml\", line 45, characters 8-15\nRe-raised at Merlin_utils__Misc.try_finally in file \"ocaml-lsp-server/vendor/merlin/src/utils/misc.ml\", line 62, characters 10-24\nCalled from Stdlib__Fun.protect in file \"fun.ml\", line 33, characters 8-15\nRe-raised at Stdlib__Fun.protect in file \"fun.ml\", line 38, characters 6-52\nCalled from Merlin_kernel__Mocaml.with_state in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mocaml.ml\", line 18, characters 8-38\nRe-raised at Merlin_kernel__Mocaml.with_state in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mocaml.ml\", line 20, characters 42-53\nCalled from Stdune__Exn_with_backtrace.try_with in file \"otherlibs/stdune/exn_with_backtrace.ml\", line 9, characters 8-12\nRe-raised at Stdune__Exn.raise_with_backtrace in file \"otherlibs/stdune/exn.ml\" (inlined), line 36, characters 27-56\nCalled from Stdune__Exn_with_backtrace.reraise in file \"otherlibs/stdune/exn_with_backtrace.ml\", line 18, characters 33-71\nCalled from Fiber__Core.O.(>>|).(fun) in file \"src/fiber/core.ml\", line 250, characters 36-41\nCalled from Fiber__Scheduler.exec in file \"src/fiber/scheduler.ml\", line 69, characters 8-11\n"
}
[Trace - 7:00:17 PM] Received response 'textDocument/codeAction - (20)' in 2ms. Request failed: uncaught exception (-32603).
Error data: {
    "exn": "Failure(\"Empty file\")",
    "backtrace": "Raised at Stdlib.failwith in file \"stdlib.ml\", line 29, characters 17-33\nCalled from Merlin_kernel__Mreader_parser.parse in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mreader_parser.ml\", line 175, characters 20-48\nCalled from Merlin_kernel__Mreader_parser.run_parser.(fun) in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mreader_parser.ml\", line 190, characters 6-42\nCalled from Merlin_utils__Misc.try_finally in file \"ocaml-lsp-server/vendor/merlin/src/utils/misc.ml\", line 45, characters 8-15\nRe-raised at Merlin_utils__Misc.try_finally in file \"ocaml-lsp-server/vendor/merlin/src/utils/misc.ml\", line 62, characters 10-24\nCalled from Merlin_kernel__Mreader_parser.make in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mreader_parser.ml\", line 204, characters 20-56\nCalled from Merlin_kernel__Mreader.normal_parse in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mreader.ml\", line 48, characters 15-77\nCalled from Merlin_kernel__Mpipeline.process in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mpipeline.ml\", line 162, characters 19-62\nCalled from CamlinternalLazy.force_lazy_block in file \"camlinternalLazy.ml\", line 31, characters 17-27\nRe-raised at CamlinternalLazy.force_lazy_block in file \"camlinternalLazy.ml\", line 36, characters 4-11\nCalled from Merlin_kernel__Mpipeline.timed_lazy in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mpipeline.ml\", line 17, characters 10-22\nRe-raised at Merlin_kernel__Mpipeline.timed_lazy in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mpipeline.ml\", line 19, characters 34-49\nCalled from CamlinternalLazy.force_lazy_block in file \"camlinternalLazy.ml\", line 31, characters 17-27\nRe-raised at CamlinternalLazy.force_lazy_block in file \"camlinternalLazy.ml\", line 36, characters 4-11\nCalled from Merlin_kernel__Mpipeline.reader_parsetree in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mpipeline.ml\", line 115, characters 30-40\nCalled from Ocaml_lsp_server__Folding_range.compute.(fun) in file \"ocaml-lsp-server/src/folding_range.ml\", line 235, characters 28-63\nCalled from Merlin_utils__Std.let_ref in file \"ocaml-lsp-server/vendor/merlin/src/utils/std.ml\", line 686, characters 8-12\nRe-raised at Merlin_utils__Std.let_ref in file \"ocaml-lsp-server/vendor/merlin/src/utils/std.ml\", line 688, characters 30-39\nCalled from Merlin_utils__Misc.try_finally in file \"ocaml-lsp-server/vendor/merlin/src/utils/misc.ml\", line 45, characters 8-15\nRe-raised at Merlin_utils__Misc.try_finally in file \"ocaml-lsp-server/vendor/merlin/src/utils/misc.ml\", line 62, characters 10-24\nCalled from Stdlib__Fun.protect in file \"fun.ml\", line 33, characters 8-15\nRe-raised at Stdlib__Fun.protect in file \"fun.ml\", line 38, characters 6-52\nCalled from Merlin_kernel__Mocaml.with_state in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mocaml.ml\", line 18, characters 8-38\nRe-raised at Merlin_kernel__Mocaml.with_state in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mocaml.ml\", line 20, characters 42-53\nCalled from Stdune__Exn_with_backtrace.try_with in file \"otherlibs/stdune/exn_with_backtrace.ml\", line 9, characters 8-12\nRe-raised at CamlinternalLazy.force_lazy_block.(fun) in file \"camlinternalLazy.ml\", line 35, characters 56-63\nCalled from CamlinternalLazy.force_lazy_block in file \"camlinternalLazy.ml\", line 31, characters 17-27\nRe-raised at CamlinternalLazy.force_lazy_block in file \"camlinternalLazy.ml\", line 36, characters 4-11\nCalled from Merlin_kernel__Mpipeline.process in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mpipeline.ml\", line 166, characters 10-47\nCalled from CamlinternalLazy.force_lazy_block in file \"camlinternalLazy.ml\", line 31, characters 17-27\nRe-raised at CamlinternalLazy.force_lazy_block in file \"camlinternalLazy.ml\", line 36, characters 4-11\nCalled from Merlin_kernel__Mpipeline.timed_lazy in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mpipeline.ml\", line 17, characters 10-22\nRe-raised at Merlin_kernel__Mpipeline.timed_lazy in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mpipeline.ml\", line 19, characters 34-49\nCalled from CamlinternalLazy.force_lazy_block in file \"camlinternalLazy.ml\", line 31, characters 17-27\nRe-raised at CamlinternalLazy.force_lazy_block in file \"camlinternalLazy.ml\", line 36, characters 4-11\nCalled from Merlin_kernel__Mpipeline.process in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mpipeline.ml\", line 173, characters 10-44\nCalled from CamlinternalLazy.force_lazy_block in file \"camlinternalLazy.ml\", line 31, characters 17-27\nRe-raised at CamlinternalLazy.force_lazy_block in file \"camlinternalLazy.ml\", line 36, characters 4-11\nCalled from Merlin_kernel__Mpipeline.timed_lazy in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mpipeline.ml\", line 17, characters 10-22\nRe-raised at Merlin_kernel__Mpipeline.timed_lazy in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mpipeline.ml\", line 19, characters 34-49\nCalled from CamlinternalLazy.force_lazy_block in file \"camlinternalLazy.ml\", line 31, characters 17-27\nRe-raised at CamlinternalLazy.force_lazy_block in file \"camlinternalLazy.ml\", line 36, characters 4-11\nCalled from Merlin_kernel__Mpipeline.typer_result in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mpipeline.ml\", line 128, characters 21-30\nCalled from Query_commands.dispatch in file \"ocaml-lsp-server/vendor/merlin/src/frontend/query_commands.ml\", line 553, characters 16-47\nCalled from Merlin_utils__Std.let_ref in file \"ocaml-lsp-server/vendor/merlin/src/utils/std.ml\", line 686, characters 8-12\nRe-raised at Merlin_utils__Std.let_ref in file \"ocaml-lsp-server/vendor/merlin/src/utils/std.ml\", line 688, characters 30-39\nCalled from Merlin_utils__Misc.try_finally in file \"ocaml-lsp-server/vendor/merlin/src/utils/misc.ml\", line 45, characters 8-15\nRe-raised at Merlin_utils__Misc.try_finally in file \"ocaml-lsp-server/vendor/merlin/src/utils/misc.ml\", line 62, characters 10-24\nCalled from Stdlib__Fun.protect in file \"fun.ml\", line 33, characters 8-15\nRe-raised at Stdlib__Fun.protect in file \"fun.ml\", line 38, characters 6-52\nCalled from Merlin_kernel__Mocaml.with_state in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mocaml.ml\", line 18, characters 8-38\nRe-raised at Merlin_kernel__Mocaml.with_state in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mocaml.ml\", line 20, characters 42-53\nCalled from Stdune__Exn_with_backtrace.try_with in file \"otherlibs/stdune/exn_with_backtrace.ml\", line 9, characters 8-12\nRe-raised at Stdune__Exn.raise_with_backtrace in file \"otherlibs/stdune/exn.ml\" (inlined), line 36, characters 27-56\nCalled from Stdune__Exn_with_backtrace.reraise in file \"otherlibs/stdune/exn_with_backtrace.ml\", line 18, characters 33-71\nCalled from Fiber__Scheduler.exec in file \"src/fiber/scheduler.ml\", line 69, characters 8-11\nRe-raised at Stdune__Exn.raise_with_backtrace in file \"otherlibs/stdune/exn.ml\" (inlined), line 36, characters 27-56\nCalled from Stdune__Exn_with_backtrace.reraise in file \"otherlibs/stdune/exn_with_backtrace.ml\", line 18, characters 33-71\nCalled from Fiber__Core.O.(>>|).(fun) in file \"src/fiber/core.ml\", line 250, characters 36-41\nCalled from Fiber__Scheduler.exec in file \"src/fiber/scheduler.ml\", line 69, characters 8-11\n"
}
rgrinberg commented 2 years ago

this should be fixed upstream in merlin i think. cc @voodoos

voodoos commented 2 years ago

I tried to write a test and cannot, indeed, reproduce: https://github.com/ocaml/merlin/pull/1473/files

@tatchi could you double-check that I am indeed testing the correct behaviour?

tatchi commented 2 years ago

I tried to write a test and cannot, indeed, reproduce: https://github.com/ocaml/merlin/pull/1473/files

@tatchi could you double-check that I am indeed testing the correct behaviour?

I investigated further this issue and noticed that it doesn't happen when there's a newline at the end of the file.

So the following works fine in my editor:

(**)
*

While the same without the last empty line doesn't work:

(**)
*

I have only a little knowledge of Linux commands, but it appears that the shell script you use in your test always inserts that last empty line. I was able to remove it using the script below (probably not the best way to do it):

  $ cat >main.ml <<EOF
  > (**)
  > *
  > EOF
  > truncate -s -1 main.ml

  $ $MERLIN single document -position 2:0 -filename main.ml <main.ml 
  {
    "class": "failure",
    "value": "Empty file",
    "notifications": []
  }

  $ $MERLIN single errors -filename main.ml <main.ml | jq '.value'
  "Empty file"

We can see now that we have a failure with an Empty file value, which seems to correspond to the original error Failure("Empty file").

I only found one place in the merlin codebase where that error is raised: https://github.com/ocaml/merlin/blob/master/src/kernel/mreader_parser.ml#L148. So I would assume that it comes from that line of code?

I hope that what I said makes sense, sorry if that's not the case 😅

voodoos commented 2 years ago

@let-def : the parser raises empty_file even if the file is not empty. The exemple is minimal, removing (**) or * does not trigger the failure...