-
Notifications
You must be signed in to change notification settings - Fork 123
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. |
CHANGES: ## Features - Introduce a configuration option to control dune diagnostics. The option is called `duneDiganostics` and it may be set to `{ enable: false }` to disable diagnostics. (ocaml/ocaml-lsp#1221) - Support folding of `ifthenelse` expressions (ocaml/ocaml-lsp#1031) - Improve hover behavior (ocaml/ocaml-lsp#1245) Hovers are no longer displaye on useless parsetree nodes such as keywords, comments, etc. Multiline hovers are now filtered away. Display expanded ppx's in the hover window. - Improve document symbols (ocaml/ocaml-lsp#1247) Use the parse tree instead of the typed tree. This means that document symbols will work even if the source code doesn't type check. Include symbols at arbitrary depth. Differentiate functions / types / variants / etc. This now includes PPXs like `let%expect_test` or `let%bench` in the outline. - Introduce a `destruct-line` code action. This is an improved version of the old `destruct` code action. (ocaml/ocaml-lsp#1283) - Improve signature inference to only include types for elements that were absent from the signature. Previously, all signature items would always be inserted. (ocaml/ocaml-lsp#1289) - Add an `update-signature` code action to update the types of elements that were already present in the signature (ocaml/ocaml-lsp#1289) - Add custom [`ocamllsp/merlinCallCompatible`](https://github.com/ocaml/ocaml-lsp/blob/e165f6a3962c356adc7364b9ca71788e93489dd0/ocaml-lsp-server/docs/ocamllsp/merlinCallCompatible-spec.md) request (ocaml/ocaml-lsp#1265) - Add custom [`ocamllsp/typeEnclosing`](https://github.com/ocaml/ocaml-lsp/blob/109801e56f2060caf4487427bede28b824f4f1fe/ocaml-lsp-server/docs/ocamllsp/typeEnclosing-spec.md) request (ocaml/ocaml-lsp#1304) ## Fixes - Detect document kind by looking at merlin's `suffixes` config. This enables more lsp features for non-.ml/.mli files. Though it still depends on merlin's support. (ocaml/ocaml-lsp#1237) - Correctly accept the `--clientProcessId` flag. (ocaml/ocaml-lsp#1242) - Disable automatic completion and signature help inside comments (ocaml/ocaml-lsp#1246) - Includes a new optional/configurable option to toggle syntax documentation. If toggled on, allows display of syntax documentation on hover tooltips. Can be controlled via environment variables and by GUI for VS code. (ocaml/ocaml-lsp#1218) - For completions on labels that the LSP gets from merlin, take into account whether the prefix being completed starts with `~` or `?`. Change the label completions that start with `?` to start with `~` when the prefix being completed starts with `~`. (ocaml/ocaml-lsp#1277) - Fix document syncing (ocaml/ocaml-lsp#1278, ocaml/ocaml-lsp#1280, fixes ocaml/ocaml-lsp#1207) - Stop generating inlay hints on generated code (ocaml/ocaml-lsp#1290) - Fix parenthesizing of function types in `SignatureHelp` (ocaml/ocaml-lsp#1296) - Fix syntax documentation rendering (ocaml/ocaml-lsp#1318)
CHANGES: ## Features - Introduce a configuration option to control dune diagnostics. The option is called `duneDiganostics` and it may be set to `{ enable: false }` to disable diagnostics. (ocaml/ocaml-lsp#1221) - Support folding of `ifthenelse` expressions (ocaml/ocaml-lsp#1031) - Improve hover behavior (ocaml/ocaml-lsp#1245) Hovers are no longer displaye on useless parsetree nodes such as keywords, comments, etc. Multiline hovers are now filtered away. Display expanded ppx's in the hover window. - Improve document symbols (ocaml/ocaml-lsp#1247) Use the parse tree instead of the typed tree. This means that document symbols will work even if the source code doesn't type check. Include symbols at arbitrary depth. Differentiate functions / types / variants / etc. This now includes PPXs like `let%expect_test` or `let%bench` in the outline. - Introduce a `destruct-line` code action. This is an improved version of the old `destruct` code action. (ocaml/ocaml-lsp#1283) - Improve signature inference to only include types for elements that were absent from the signature. Previously, all signature items would always be inserted. (ocaml/ocaml-lsp#1289) - Add an `update-signature` code action to update the types of elements that were already present in the signature (ocaml/ocaml-lsp#1289) - Add custom [`ocamllsp/merlinCallCompatible`](https://github.com/ocaml/ocaml-lsp/blob/e165f6a3962c356adc7364b9ca71788e93489dd0/ocaml-lsp-server/docs/ocamllsp/merlinCallCompatible-spec.md) request (ocaml/ocaml-lsp#1265) - Add custom [`ocamllsp/typeEnclosing`](https://github.com/ocaml/ocaml-lsp/blob/109801e56f2060caf4487427bede28b824f4f1fe/ocaml-lsp-server/docs/ocamllsp/typeEnclosing-spec.md) request (ocaml/ocaml-lsp#1304) ## Fixes - Detect document kind by looking at merlin's `suffixes` config. This enables more lsp features for non-.ml/.mli files. Though it still depends on merlin's support. (ocaml/ocaml-lsp#1237) - Correctly accept the `--clientProcessId` flag. (ocaml/ocaml-lsp#1242) - Disable automatic completion and signature help inside comments (ocaml/ocaml-lsp#1246) - Includes a new optional/configurable option to toggle syntax documentation. If toggled on, allows display of syntax documentation on hover tooltips. Can be controlled via environment variables and by GUI for VS code. (ocaml/ocaml-lsp#1218) - For completions on labels that the LSP gets from merlin, take into account whether the prefix being completed starts with `~` or `?`. Change the label completions that start with `?` to start with `~` when the prefix being completed starts with `~`. (ocaml/ocaml-lsp#1277) - Fix document syncing (ocaml/ocaml-lsp#1278, ocaml/ocaml-lsp#1280, fixes ocaml/ocaml-lsp#1207) - Stop generating inlay hints on generated code (ocaml/ocaml-lsp#1290) - Fix parenthesizing of function types in `SignatureHelp` (ocaml/ocaml-lsp#1296) - Fix syntax documentation rendering (ocaml/ocaml-lsp#1318)
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