ocaml-lsp icon indicating copy to clipboard operation
ocaml-lsp copied to clipboard

Jump Custom Request

Open PizieDust opened this issue 1 year ago • 3 comments

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 of fun, 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)

cc @voodoos @xvw @rgrinberg @awilliambauer

PizieDust avatar Sep 18 '24 06:09 PizieDust

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 Coverage Status
Change from base Build 4617: 0.09%
Covered Lines: 5632
Relevant Lines: 25447

💛 - Coveralls

coveralls avatar Sep 18 '24 06:09 coveralls

We should think about what we want to do with the jump code action. The two obvious possibilities are:

  1. Revert the changes
  2. 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.

voodoos avatar Sep 18 '24 14:09 voodoos

We should think about what we want to do with the jump code action. The two obvious possibilities are:

  1. Revert the changes
  2. 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.

PizieDust avatar Sep 18 '24 14:09 PizieDust

This should be ready to merge now, and we have the vscode implementation ready: https://github.com/ocamllabs/vscode-ocaml-platform/pull/1654

voodoos avatar Nov 27 '24 14:11 voodoos