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

Type search custom request

Open PizieDust opened this issue 1 year ago • 5 comments

TypeSearch Request

Description

This custom request allows clients to perform a type search at a specific position within a text document based on finding functions or types that match a specific query pattern.

Server capability

  • property name: handleTypeSearch
  • property type: boolean

Request

export interface TypeSearchParams extends TexDocumentPositionParams
{
    query: string;
    limit: int;
    with_doc: bool;
}
  • method: ocamllsp/typeSearch
  • params:
    • TextDocumentPositionParams: This is an existing interface that includes: - TextDocumentIdentifier: Specifies the document uri for which the request is sent. - Position: Specifies the cursor position. More details can be found in the TextDocumentPositionParams - LSP Specification.
    • query: The search pattern.
    • limit: The number of results to return
    • with_doc: If to return documentation information or not

Response

result: TypeSearch | null
export interface TypeSearch {
    type t = Query_protocol.type_search_result list
}
  • t: A list of types that match the query.
    type Query_protocol.type_search_result =
    {
        name : string; // The fully qualified name of this result.
        typ : string;  // The signature of this result.
        loc : Range.t; // The location of the definition of this result in the source code.
        doc : string option; // Optional documentation associated with this result.
        cost : int; // A numeric value representing the "cost" or distance between this result and the query.
        constructible : string; // A constructible form or template that can be used to invoke this result
    }
    
  • A response with null result is returned if no entries are found.

PizieDust avatar Sep 04 '24 14:09 PizieDust

Pull Request Test Coverage Report for Build 4607

Details

  • 35 of 37 (94.59%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 22.034%

Changes Missing Coverage Covered Lines Changed/Added Lines %
ocaml-lsp-server/src/custom_requests/req_type_search.ml 35 37 94.59%
<!-- Total: 35 37
Totals Coverage Status
Change from base Build 4597: 0.1%
Covered Lines: 5599
Relevant Lines: 25411

💛 - Coveralls

coveralls avatar Sep 11 '24 03:09 coveralls

Nice. Which client is going to make use of this?

rgrinberg avatar Sep 11 '24 14:09 rgrinberg

Nice. Which client is going to make use of this?

We probably will implement a VScode extension for the query

xvw avatar Sep 11 '24 14:09 xvw

Okay, I think we need to see that vscode client to evaluate this work.

rgrinberg avatar Sep 11 '24 14:09 rgrinberg

@xvw, @PizieDust, Melrin 5.2-502 has been released so the CI should pass without pinning and could be un-drafted. Is the custom request ready for a last round of review ?

voodoos avatar Sep 30 '24 13:09 voodoos

@PizieDust I think we should, similarly as for the Type enclosing custom request, provide a way to ask for different format for the documentation, like markdown, and maybe plaintext and html ?

voodoos avatar Oct 28 '24 10:10 voodoos

Client support in VScode is on the way: https://github.com/ocamllabs/vscode-ocaml-platform/pull/1626

voodoos avatar Nov 14 '24 14:11 voodoos