-
Notifications
You must be signed in to change notification settings - Fork 147
Type search custom request #1369
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
Merged
Merged
Changes from 23 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
5eb87cc
polarity search custom request
PizieDust 3863432
update intf
PizieDust 512c01d
add json functions
PizieDust 59f3055
update spec
PizieDust 641d5f4
add test
PizieDust 46779cb
lint
PizieDust 5e7500a
Merge branch 'ocaml:master' into polarity_search
PizieDust de5459d
add changelog
PizieDust e074bcd
review changes
PizieDust 0cddcad
add limits
PizieDust 9200936
update docs
PizieDust 730b743
update doc
PizieDust daf0f83
chagnes according to review
PizieDust 835d6bb
minor refactoring
PizieDust 8059820
rename to type search
PizieDust 04792e8
refactor polarity search to type search
PizieDust 9605202
update test
PizieDust 01ca054
update docs
PizieDust ca4631c
update tests
PizieDust d4603e5
pin to merlin main branch
PizieDust c691624
update change log
PizieDust 4f4b706
update api
PizieDust 2b621cc
lint
PizieDust 0111307
unpin merlin
PizieDust 49fd7a7
update doc
PizieDust a56130b
Merge branch 'master' of github.com:PizieDust/ocaml-lsp into polarity…
PizieDust c8bc4de
Merge branch 'master' of github.com:ocaml/ocaml-lsp into polarity_search
PizieDust 803a137
move changelog to unreleased
PizieDust 080d88e
add capability
PizieDust 9c17c78
Merge branch 'master' of github.com:ocaml/ocaml-lsp into polarity_search
PizieDust 26fdb8a
update docs
PizieDust 6100599
add doc format
PizieDust fd7e6fa
review updates
PizieDust File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # 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 | ||
|
|
||
| ```js | ||
| export interface TypeSearchParams extends TexDocumentPositionParams | ||
| { | ||
| query: string; | ||
| limit: int; | ||
| with_doc: bool; | ||
PizieDust marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| ``` | ||
| - 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](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentPositionParams). | ||
| - `query`: The search pattern. | ||
| - `limit`: The number of results to return | ||
| - `with_doc`: If to return documentation information or not | ||
|
|
||
| ## Response | ||
|
|
||
| ```js | ||
| result: TypeSearch | null | ||
| export interface TypeSearch { | ||
PizieDust marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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 | ||
| } | ||
| ``` | ||
PizieDust marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - A response with null result is returned if no entries are found. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| open Import | ||
| module TextDocumentPositionParams = Lsp.Types.TextDocumentPositionParams | ||
|
|
||
| let meth = "ocamllsp/typeSearch" | ||
| let capability = "handleTypeSearch", `Bool true | ||
|
|
||
| module TypeSearchParams = struct | ||
| type t = | ||
| { text_document : TextDocumentIdentifier.t | ||
| ; position : Position.t | ||
| ; limit : int | ||
| ; query : string | ||
| ; with_doc : bool | ||
| } | ||
|
|
||
| let t_of_yojson json = | ||
| let open Yojson.Safe.Util in | ||
| let textDocumentPosition = Lsp.Types.TextDocumentPositionParams.t_of_yojson json in | ||
| let query = json |> member "query" |> to_string in | ||
| let limit = json |> member "limit" |> to_int in | ||
| let with_doc = json |> member "with_doc" |> to_bool in | ||
| { position = textDocumentPosition.position | ||
| ; text_document = textDocumentPosition.textDocument | ||
| ; query | ||
| ; limit | ||
| ; with_doc | ||
| } | ||
| ;; | ||
|
|
||
| let yojson_of_t { text_document; position; query; limit; with_doc } = | ||
| `Assoc | ||
| (("textDocument", TextDocumentIdentifier.yojson_of_t text_document) | ||
| :: ("position", Position.yojson_of_t position) | ||
| :: ("limit", `Int limit) | ||
| :: ("with_doc", `Bool with_doc) | ||
| :: [ "query", `String query ]) | ||
| ;; | ||
| end | ||
|
|
||
| module TypeSearch = struct | ||
| type t = string Query_protocol.type_search_result list | ||
|
|
||
| let yojson_of_t (t : t) = | ||
| let yojson_of_type_search_result (res : string Query_protocol.type_search_result) = | ||
| `Assoc | ||
| [ "name", `String res.name | ||
| ; "typ", `String res.typ | ||
| ; "loc", Range.yojson_of_t (Range.of_loc res.loc) | ||
| ; ( "doc" | ||
| , match res.doc with | ||
| | Some d -> `String d | ||
| | None -> `Null ) | ||
PizieDust marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ; "cost", `Int res.cost | ||
| ; "constructible", `String res.constructible | ||
| ] | ||
| in | ||
| `List (List.map ~f:yojson_of_type_search_result t) | ||
| ;; | ||
| end | ||
|
|
||
| type t = TypeSearch.t | ||
|
|
||
| module Request_params = struct | ||
| type t = TypeSearchParams.t | ||
|
|
||
| let yojson_of_t t = TypeSearchParams.yojson_of_t t | ||
|
|
||
| let create text_document position limit query with_doc : t = | ||
| { text_document; position; limit; query; with_doc } | ||
| ;; | ||
| end | ||
|
|
||
| let dispatch merlin position limit query with_doc = | ||
| Document.Merlin.with_pipeline_exn merlin (fun pipeline -> | ||
| let position = Position.logical position in | ||
| let query = Query_protocol.Type_search (query, position, limit, with_doc) in | ||
| let results = Query_commands.dispatch pipeline query in | ||
| TypeSearch.yojson_of_t results) | ||
| ;; | ||
|
|
||
| let on_request ~params state = | ||
| Fiber.of_thunk (fun () -> | ||
| let params = (Option.value ~default:(`Assoc []) params :> Yojson.Safe.t) in | ||
| let TypeSearchParams.{ text_document; position; limit; query; with_doc } = | ||
| TypeSearchParams.t_of_yojson params | ||
| in | ||
| let uri = text_document.uri in | ||
| let doc = Document_store.get state.State.store uri in | ||
| match Document.kind doc with | ||
| | `Other -> Fiber.return `Null | ||
| | `Merlin merlin -> dispatch merlin position limit query with_doc) | ||
| ;; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| open Import | ||
|
|
||
| module Request_params : sig | ||
| type t | ||
|
|
||
| val yojson_of_t : t -> Json.t | ||
| val create : TextDocumentIdentifier.t -> Position.t -> int -> string -> bool -> t | ||
| end | ||
|
|
||
| type t | ||
|
|
||
| val meth : string | ||
| val capability : string * [> `Bool of bool ] | ||
| val on_request : params:Jsonrpc.Structured.t option -> State.t -> Json.t Fiber.t |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,7 @@ | |
| test | ||
| type_enclosing | ||
| documentation | ||
| type_search | ||
| with_pp | ||
| with_ppx | ||
| workspace_change_config)))) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.