Jump Custom Request
related to #1360 This PR contains an implementation for a custom requests based on Merlin's jump command.
Using code actions introduces some noise as referenced in this comment: https://github.com/ocaml/ocaml-lsp/pull/1364#issuecomment-2353283155
These code actions add a lot of clutter to the code actions menu. Would there be a way to suppress them from being displayed in the menu, but still make them available via keyboard shortcut? There are various ways editors might want to incorporate these jump commands into a large commend (e.g., a macro that jumps to a let and adds a specific annotation). We'd also want the user to be able to navigate the history of these jumps (i.e., jump backwards and forwards). Having these as code actions instead of a dedicated custom query will probably make supporting both of these things a lot harder.
An alternative solution will be to use a custom request, which allows for more better finetuning.
Merlin Jump Request
Description
This custom request allows Merlin-type code navigation in a source buffer.
Server capability
- propert name:
handleMerlinJump - property type:
boolean
Request
export interface JumpParams extends TextDocumentPositionParams
{
target: string;
}
- method:
ocamllsp/merlinJump - params:
-
TextDocumentIdentifier: Specifies the document for which the request is sent. It includes a uri property that points to the document. -
Position: Specifies the position in the document for which the documentation is requested. It includes line and character properties. More details can be found in the TextDocumentPositionParams - LSP Specification. -
Target: A string representing the identifier within the document to search for and jump to. The target can be any offun,let,module,module-type,match,match-next-case,match-prev-case.
-
Response
result: Jump | String
export interface Jump extends TextDocumentPositionParams {
}
- result:
- Type: Jump or string
- Description: If the jump is successful, a position and document path is returned. If no relevant jump location is found, the result will be a string "no matching target" or an error message.
- Jump:
- Type: TextDocumentPositionParams
-
Position: The position to jump to -
TextDocumentIdentifier: the document path which contains this position (ideally the same document as the request)
-
- Type: TextDocumentPositionParams
cc @voodoos @xvw @rgrinberg @awilliambauer
Pull Request Test Coverage Report for Build 4624
Details
- 30 of 32 (93.75%) changed or added relevant lines in 1 file are covered.
- No unchanged relevant lines lost coverage.
- Overall coverage increased (+0.09%) to 22.132%
| Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
|---|---|---|---|
| ocaml-lsp-server/src/custom_requests/req_merlin_jump.ml | 30 | 32 | 93.75% |
| <!-- | Total: | 30 | 32 |
| Totals | |
|---|---|
| Change from base Build 4617: | 0.09% |
| Covered Lines: | 5632 |
| Relevant Lines: | 25447 |
💛 - Coveralls
We should think about what we want to do with the jump code action. The two obvious possibilities are:
- Revert the changes
- Add an option to disable the jump code actions
I am personally in favor of 2, since the nice trick allows direct support in any editor with the required capabilities. It could be enabled by default in the community version of the server/plugin, until we ourselves implement an alternative way using the custom request.
We should think about what we want to do with the jump code action. The two obvious possibilities are:
- Revert the changes
- Add an option to disable the jump code actions
I am personally in favor of 2, since the nice trick allows direct support in any editor with the required capabilities. It could be enabled by default in the community version of the server/plugin, until we ourselves implement an alternative way using the custom request.
I am also in favor of 2. I am currently working on the option to disable the jump code actions.
This should be ready to merge now, and we have the vscode implementation ready: https://github.com/ocamllabs/vscode-ocaml-platform/pull/1654