ocaml / ocaml-lsp

OCaml Language Server Protocol implementation
Other
749 stars 117 forks source link

How to troubleshoot `destruct` when "No code actions for 'destruct' available"? #1301

Open mbarbin opened 3 months ago

mbarbin commented 3 months ago

Hi!

I notice the recent post about the amazing destruct on ocaml discuss, and I am excited to try it out.

When I type Alt+d on a pattern '_' in vscode, I see a message saying: "No code actions for 'destruct' available". This is from within an editor, while a dune build @all @runtest -w is running in that repo, and reached a Success, waiting for filesystem changes... state.

Here are some info about the environment under which this happens:

ocaml 5.2.0 dune 3.15.3 ocaml-lsp-server 1.18.0~5.2preview merlin 5.0-502

Could you give me some pointers as to how to troubleshoot my installation, or things I need to upgrade, enable, configure, etc.

Thank you!

dalps commented 3 months ago

Not a maintainer, but I believe your installation is fine. That message simply warns you that destruct can't infer any constructor from your pattern, or that it is already exhaustive. Maybe share the code snippet with the pattern you tried running destruct on?

Here's an example image

mbarbin commented 3 months ago

Hi, and thanks for your help! That's helpful for you to confirm the installation is fine. This prompted me to try further.

I'm trying with simple cases first, just to see if things are working.

let _f (a : int option) = match a with _ -> ()
;;

no-code-actions-for-destruct

However, I am now noticing that the clickable More Actions menu proposes actions that do work (Destruct-line, and Destruct).

more-actions

This narrows it down to the use of the shortcut Alt + d, perhaps.

Back to my question, are there some logs I could try to access ? (vscode+ocaml-platform newbie here, relatively recently switch from another editor !!!)

Thank you

dalps commented 3 months ago

Strange, I can't replicate the behavior shown by your screenshots; on my end Alt + d works well on your example code, however I don't get those two actions in the More actions menu... quirky, but I can't help much further in that regard.

VS Code has an "Output" panel wherein you can inspect messages sent by extensions, the OCaml platform docs explains how to enable them for ocaml-lsp.

dalps commented 2 months ago

Turns out I was using an older version of ocaml-lsp. After updating my installation to ocaml-lsp-server 1.18.0~5.2preview, the destruct option is no longer available through the Alt + d shortcut.