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

fix: improve error messages when merlin is absent #608

Merged

Conversation

rgrinberg
Copy link
Member

thanks @let-def

@rgrinberg rgrinberg added this to the 1.10.0 milestone Feb 4, 2022
@rgrinberg rgrinberg force-pushed the ps/rr/fix__improve_error_messages_when_merlin_is_absent branch 2 times, most recently from bb23057 to 4d8d0e9 Compare February 5, 2022 03:34
@rgrinberg rgrinberg requested a review from ulugbekna February 5, 2022 03:43
match Query_commands.dispatch pipeline command with
| exception Extend_main.Handshake.Error error ->
let message =
sprintf "%s.\nHint: install merlin-extend reason" error
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's "merlin-extend reason"? Something like "install merlin-extend package" or something in that spirit would be more understandable I think.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reason is an additional package I'm proposing to the user to install.

ps-id: 5AE68BEC-4D7B-4289-9D58-C1D993F443F8
@rgrinberg rgrinberg force-pushed the ps/rr/fix__improve_error_messages_when_merlin_is_absent branch from 4d8d0e9 to 3319e88 Compare February 7, 2022 18:05
@rgrinberg rgrinberg merged commit 3319e88 into master Feb 7, 2022
@rgrinberg rgrinberg deleted the ps/rr/fix__improve_error_messages_when_merlin_is_absent branch February 7, 2022 18:05
Comment on lines +336 to +337
| _, Exn _ ->
x
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a second thought, this results in Initial, Exn -> Initial, which shouldn't be the case.

I had a throwing code action now, which resulted in assertion failure from | Error Initial -> assert false

I think it would also make sense if the monoid combined all exceptions rather than taking the latest one.

Irrelevant but curious, the code action threw this

[Trace - 2:10:58 AM] Received response 'textDocument/codeAction - (39)' in 2ms. Request failed: uncaught exception (-32603).
Error data: {
    "exn": "File \"ocaml-lsp-server/vendor/merlin/src/ocaml/utils/local_store.ml\", line 53, characters 2-8: Assertion failed",
    "backtrace": "Raised at Ocaml_utils__Local_store.with_store in file \"ocaml-lsp-server/vendor/merlin/src/ocaml/utils/local_store.ml\", line 53, characters 2-39\nCalled from Mocaml.new_state in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mocaml.ml\", line 12, characters 2-70\nCalled from Mpipeline.Cache.get in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mpipeline.ml\", line 60, characters 18-37\nCalled from Mpipeline.process in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mpipeline.ml\", line 141, characters 14-30\nCalled from Ocaml_lsp_server__Action_type_annotate.code_action.(fun) in file \"ocaml-lsp-server/src/code_actions/action_type_annotate.ml\", line 57, characters 25-68\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 Mocaml.with_state in file \"ocaml-lsp-server/vendor/merlin/src/kernel/mocaml.ml\", line 18, characters 8-38\nRe-raised at 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 \"submodules/dune/otherlibs/stdune/exn_with_backtrace.ml\", line 9, characters 8-12\nRe-raised at Stdune__Exn.raise_with_backtrace in file \"submodules/dune/otherlibs/stdune/exn.ml\", line 36, characters 27-56\nCalled from Fiber.O.(>>|).(fun) in file \"submodules/dune/src/fiber/fiber.ml\", line 338, characters 36-41\nCalled from Fiber.Execution_context.run_jobs in file \"submodules/dune/src/fiber/fiber.ml\", line 218, characters 8-13\nRe-raised at Stdune__Exn.raise_with_backtrace in file \"submodules/dune/otherlibs/stdune/exn.ml\", line 36, characters 27-56\nCalled from Fiber.O.(>>|).(fun) in file \"submodules/dune/src/fiber/fiber.ml\", line 338, characters 36-41\nCalled from Fiber.Execution_context.run_jobs in file \"submodules/dune/src/fiber/fiber.ml\", line 218, characters 8-13\n"
}

Copy link
Collaborator

@ulugbekna ulugbekna Feb 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this perhaps?

  let combine x y =
    match (x, y) with
    | Initial, _ -> y (* [Initial] cedes to any *)
    | _, Initial -> x
    | _, Exn _ -> y (* [Exn] takes over any; the right one wins - why? *) 
    | Exn _, _ -> x
    | Need_merlin_extend _, Need_merlin_extend _ -> y

Another easy way would be to define comparison function on variants and simply always take max of them

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this perhaps?

Yeah that looks fine.

Another easy way would be to define comparison function on variants and simply always take max of them

Writing the comparison function is just as much work so I think the current approach is better because it's more direct.

rgrinberg added a commit to rgrinberg/opam-repository that referenced this pull request Feb 10, 2022
CHANGES:

## Features

- Add better support for code folding: more folds and more precise folds

## Fixes

- Fix infer interface code action crash when implementation source does not
  exist (ocaml/ocaml-lsp#597)

- Improve error message when the reason plugin for merlin is absent (ocaml/ocaml-lsp#608)

- Fix `chdir` races when running ppx (ocaml/ocaml-lsp#550)

- More accurate completion kinds.
  New completion kinds for variants and fields. Removed inaccurate completion
  kinds for constructors and types. (ocaml/ocaml-lsp#510)

- Fix handling request cancellation (ocaml/ocaml-lsp#616)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants