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

Feature: provide information about the syntax #1692

Closed
voodoos opened this issue Oct 20, 2023 · 1 comment · Fixed by #1706
Closed

Feature: provide information about the syntax #1692

voodoos opened this issue Oct 20, 2023 · 1 comment · Fixed by #1706
Assignees

Comments

@voodoos
Copy link
Collaborator

voodoos commented Oct 20, 2023

OCaml's syntax can be puzzling for new users and sometime prove to be challenging to search on the internet due to the use of special characters. On the other hand, the manual and compiler's parsetree.mli provides useful comments when one knows where to look for: that is the name of the features.

The proposition is to add a command to Merlin that, given a certain OCaml syntax, will display the corresponding Parsetree node name and a documentation string. For example, on module F (M : T) = it will give the hints “Pmod_functor” and “Functor declaration: [functor(X : MT1) -> ME]”.

Tasks:

  • Boilerplate code to add a new command to the protocol and associated tests.
  • Identify the most interesting node around the cursor. (It would be natural to do it on the non-preprocessed AST for this feature, but Merlin only has utilities that work on the Typedtree.)
  • Lookup documentation for the interesting nodes, in the sources themselves and in a complementary table.
  • Update ocaml-lsp to also provide that information as a code action or in addition to the standard document request.
@PizieDust
Copy link
Contributor

PizieDust commented Oct 25, 2023

After meeting with @voodoos, here are some ideas on how to get started with this issue.

  • Will need to create a new command new_commands that can look up documentation for the node currently under the cursor (or the most interesting node around the cursor)
  • Update the query_protocol to use this new command.
  • Develop some logic for this new command in query_commands
  • Update query_json to use this new command so we can parse the CLI and also display the result
  • Write a test case to verify the new command

On the question of if to work on the AST or the TypedTree, @voodoos indicates that this feature is really developed for the end user, who may likely not be very concerned with the semantics found in the Parsetree and perhaps the documentation or comments found in the parsetree may be of little help to end users.
So a possible implementation may require building on the TypedTree as it already contains most of the functions (such as getting cursor position and nodes etc) and also to ensure compatibility moving forward with changes to the Merlin codebase.

This may also involve providing some basic documentation for what's currently in the Parsetree.

A likely outcome when a user hovers will be something like:

Name: some name
Description: some description or definition
Documentation: https://v2.ocaml.org/...some link to the specific documentation for the node example: https://v2.ocaml.org/releases/5.1/htmlman/extensiblevariants.html

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 a pull request may close this issue.

2 participants