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

Is knowing Merlin a prerequisite for contributing? #1357

Open
jpoly1219 opened this issue Aug 14, 2024 · 1 comment
Open

Is knowing Merlin a prerequisite for contributing? #1357

jpoly1219 opened this issue Aug 14, 2024 · 1 comment

Comments

@jpoly1219
Copy link

Hi! I was hoping to get a better understanding of the project to be able to implement custom requests. Lots of Fiber and stream code aside, I noticed that the main logic is in the on_request function in ocaml_lsp_server.ml, where it pattern matches against the type of request method.

I looked at a couple of <lsp_method>.ml files in the ocaml_lsp_server/src/ directory, and noticed that they accomplish the following:

  • the handler calls Document.Merlin to do something, saving it to a result.
  • result is then passed to a method-specific logic to generate some data, which is sent back to the client by the handler.

I'll admit that I don't have lots of experience with OCaml or the OCaml ecosystem, but I was slightly lost in the document.ml file, mostly because I have no idea what the Document module is doing, nor do I know how Merlin works. How important is it to know which Merlin method to call, and how can I get better at it?

Thank you!

@jpoly1219 jpoly1219 changed the title Prerequisites for contributing? Is knowing Merlin a prerequisite for contributing? Aug 14, 2024
@voodoos
Copy link
Collaborator

voodoos commented Aug 22, 2024

Hi @jpoly1219 !

A quick answer to the title "Is knowing Merlin a prerequisite for contributing?" is: it depends on what your trying to do. Most of the time a query is forwarded to Merlin using the protocol described here. This is simple plumbing and requires little knowledge of how Merlin. If you want to perform custom analysis then you need to understand how Merlin internals work.

The usual route a of a request is something like this:

  • The client sends the request, encoded using the LSP protocol to the ocaml-lsp server.
  • The server decodes the request and dispatch it it the Ocaml_lsp_server module which is the heart of the server and main entry point when adding support for new requests. You can grep for Req_ to see how custom requests are plugged in here.
  • The requests themselves are implemented in a standardized way (thanks @xvw!) in the custom_request folder.
  • Usually this means parsing the query, querying Merlin and return the encoded the answer.
  • Querying Merlin is done by obtaining the Merlin instance attached to the current Document and using the dispatch function with the appropriate query from Merlin's own protocol. A canonical example of how to do that is the get_documentation request.

Hi! I was hoping to get a better understanding of the project to be able to implement custom requests.

Just a warning: we try not to clutter the server with custom request that also require custom client support. Every feature that can be implemented via the official protocol should be done that way. If your goal is to have your custom request merged upstream, I encourage you to open an issue describing precisely its interface and the reason why you think it would be useful.

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

No branches or pull requests

2 participants