-
Notifications
You must be signed in to change notification settings - Fork 118
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
Demystifying OCaml Syntax with Merlin and OCaml-LSP #1218
Conversation
I suspect that users will want this to be configurable. I could see how novice users might find this information helpful, but it's noisy. #1198 suggests go-to links for types. We could consider a go-to link for documentation, instead of inlining the documentation sentence into the hover. |
This is certainly a good idea. I like the Go to Documentation format. It definitely trims is down a bunch. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made a few comments, you are doing good progress !
To make the feature opt-in (or opt-out ?) can take inspiration from other configurable features of ocaml-lsp like "extended hover".
Changes for this PR on the VSCode extension side have just been merged. |
I'll let @voodoos merge |
ack, I will try to release Merlin so that we can properly run the testsuite before merging. |
Pull Request Test Coverage Report for Build 4211Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late review. Nice job Pizie, it looks like it's almost ready !
I think you changed the formatting of the on_hover responses slightly which breaks other tests. (The 5.0/5.1 CI only pass because it doesn't run the tests.) Did you run them on your machine ? Did they pass on your machine ?
For example, the following diff is clearly linked to your new printing of the dividers:
- ---
+
+ ---
+
There is no reason to change the results of other tests in this PR, unless the new feature is activated. You can run the make test
target to run the test on your machine and check that the result is correct.
ocaml-lsp-server/src/hover_req.ml
Outdated
@@ -12,29 +12,40 @@ let environment_mode = | |||
| Some true -> Extended_variable | |||
| Some false | None -> Default | |||
|
|||
let format_contents ~syntax ~markdown ~typ ~doc = | |||
let print_dividers sections = String.concat ~sep:"\n\n --- \n\n" sections |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in the orginal printer there is only one \n
before and after the ---
and no spaced. Does that matter ?
It would be great to have the commit with the test moved at the first position in this PR so that it first show the printing before the changes in that PR and then how this PR alters the test. (@pitag-ha can probably help you with the rebase 🤞)
Ahh yeah, I was using |
192f59a
to
c5f37c9
Compare
add syntax doc command change syntax_doc output from string to record type parse record to extract and display different fields correctly lint code refactor code add formatting functions and check if syn_doc is activated check if syntax_doc is activated in ocamllsp env variables refactor for proper types include syntax documentation in configuation data check if feature is activated from ocaml.server remove redundant code lint add version refactor code and lint refactor code and lint let merlin work only if syntax doc is activated lint change from italics to code pill lint update changelog update documentation remove configuration via environment variables update docs syntax highlighting for code block make syntax highlighter required add constraint for most recent version of merlin-lib upgrade merlin-lib to latest version add syntax doc to ppx expect Write tests for syntax doc command linting helper function for positions Update README.md Co-authored-by: Ulysse <5031221+voodoos@users.noreply.github.com> Update README.md Co-authored-by: Ulysse <5031221+voodoos@users.noreply.github.com> Update ocaml-lsp-server/src/document.ml Co-authored-by: Ulysse <5031221+voodoos@users.noreply.github.com> Update ocaml-lsp-server/src/document.ml Co-authored-by: Ulysse <5031221+voodoos@users.noreply.github.com> 80 char per line limit use better descriptive function name adjust formatting fix bug fix bug
9f3a377
to
b462e3b
Compare
Thanks @PizieDust, I will merge once the checks finish. |
FEATURE: Add Syntax Documentation to Hover request
Introduction
This PR introduces a new feature to OCaml-LSP for both beginners and also more experienced programmers. No more searching for obscure keywords or symbols on Google trying to find documentation.
With this PR, you can hover over OCaml code in your editor, and instantly see a clear and summarized explanation of its syntax along with a link to the exact portion of OCaml's documentation for it.
Benefits:
How it works:
Syntax Documentation
command from Merlin which returns aJSON
output containing aname
, somedescription
and aurl
pointing to the documentation.Scope
Currently the command covers only specific sections of OCaml's syntax such as
Language Extensions
. Subsequently, more syntax will be covered.Code Example
Example: Hovering over type definitions in VS code:
Code example:
Current Behaviour
Before
Syntax document
command: UI will display only type definitionOr display comments if they are available
New Feature
The UI now includes a short description about the syntax highlighted under the cursor.
UI will also display comments if they are available
New
Syntax Document
command can differentiate different kinds of syntax and return appropriate documentationWIP/Dependencies
This PR relies on a new Merlin command found in this PR (ocaml/merlin#1706) which is currently unmerged. To test this feature out, add a pin dependency of Merlin to https://github.com/PizieDust/merlin/tree/syntax_documentation.
This PR is related to ocaml/merlin#1692
Update
cc @voodoos @pitag-ha