Skip to content

Go-to-definition does not work on custom operators #1915

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

Open
WardBrian opened this issue Mar 27, 2025 · 4 comments · May be fixed by #1917
Open

Go-to-definition does not work on custom operators #1915

WardBrian opened this issue Mar 27, 2025 · 4 comments · May be fixed by #1917
Labels

Comments

@WardBrian
Copy link

WardBrian commented Mar 27, 2025

Go-to-definition doesn't work on (all) custom operators, which would be very useful for navigating DSLs.

For example,

let ( := ) v a = Printf.printf "%s = %d" v a
let () = "foo" := 3
(*              ^ *)

If I place my cursor at the point indicated by the ^, go-to-definition does nothing.

Similarly, for custom indexing operators:

let (.%{;..}) a k = Printf.printf "%s.coeffRef(%d);\n" a k.(0)
let (.%{ }) a k = Printf.printf "%s.coeffRef(%d);\n" a k
let name = "baz"
let () = name.%{2;4}
let () = name.%{5}

Placing the cursor at the % on either like 4 or 5 does not succeed.

Originally opened as ocamllabs/vscode-ocaml-platform#1766

@WardBrian
Copy link
Author

I should also say, if someone is willing to give me a few pointers on how to get started and what the scope of this is, I'd be more than willing to have a go at contributing the fix myself!

@voodoos
Copy link
Collaborator

voodoos commented Mar 28, 2025

Here is how I would proceed:

  • Write a test illustrating the wrong behavior (similar as https://github.com/ocaml/merlin/blob/main/tests/test-dirs/locate/issue949.t)
  • Such a test would already be welcome as a contribution
  • Then you can use that test to print some logs by adding -log-file - to the $MERLIN command line.
  • I expect these to guide you toward Query_commands (the entry point for Merlin analyses)
  • My bet would be an issue with reconstruct_identifier (here) that Merlin uses to reparse the identifier under the cursor.
  • You can also have a look at the asts in the test by using the commands $MERLIN single dump -what parsetree ... and dump -what typedtree

@WardBrian
Copy link
Author

Huh. I started writing the test and was surprised when the output actually was what I expected. I then tried M-x merlin-locate in Emacs and it also worked. Going back into VSCode, it now works too -- so maybe I just hadn't run a dune clean && dune build recently enough. My binary operators also seem to be working now.

Things that aren't:

A custom definition of ( := ) is returning Not a valid identifier, and the custom indexing operators are failing. I'll see if I can at least contribute a test for those.

@WardBrian WardBrian linked a pull request Mar 31, 2025 that will close this issue
@WardBrian
Copy link
Author

Thanks @voodoos -- your hints were very helpful (and your hunch about reconstruct_identifier right on the money). I've taken a crack at it over in #1917

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants