-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
respect completion prefix when completing optional arguments (#1277)
* respect completion prefix
- Loading branch information
1 parent
ec53219
commit b47bd73
Showing
9 changed files
with
215 additions
and
199 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,133 @@ | ||
open Test.Import | ||
|
||
let print_completion | ||
(completions : | ||
[ `CompletionList of CompletionList.t | `List of CompletionItem.t list ] | ||
option) = | ||
let print_items (items : CompletionItem.t list) = | ||
List.map items ~f:(fun item -> | ||
CompletionItem.yojson_of_t item | ||
|> Yojson.Safe.pretty_to_string ~std:false) | ||
|> String.concat ~sep:"\n" |> print_endline | ||
in | ||
match completions with | ||
| None -> print_endline "no completion response" | ||
| Some completions -> ( | ||
match completions with | ||
| `List items -> print_items items | ||
| `CompletionList completions -> print_items completions.items) | ||
|
||
let completion client position = | ||
Client.request | ||
client | ||
(TextDocumentCompletion | ||
(CompletionParams.create | ||
~position | ||
~textDocument:(TextDocumentIdentifier.create ~uri:Helpers.uri) | ||
())) | ||
|
||
let%expect_test "completing optional arguments" = | ||
let source = | ||
{ocaml| | ||
let foo ?aaa ?aab ~abb () = 5 | ||
|
||
let foo_value = foo ~a | ||
let foo_value = foo ?a | ||
|ocaml} | ||
in | ||
let req client = | ||
let* resp = completion client (Position.create ~line:3 ~character:22) in | ||
let () = print_completion resp in | ||
print_endline "****************************************"; | ||
let* resp = completion client (Position.create ~line:4 ~character:22) in | ||
let () = print_completion resp in | ||
Fiber.return () | ||
in | ||
(* The first three results should respect the [~] prefix and contain "newText" that | ||
starts with a [~]. The second three should contain the prefix matching the argument | ||
type. The LSP could filter these to exclude those that don't match the [?] prefix, | ||
but since the LSP already relies on the clients to do filtering, it feels weird to | ||
add filtering to the LSP. *) | ||
Helpers.test source req; | ||
[%expect | ||
{| | ||
{ | ||
"detail": "'a", | ||
"kind": 5, | ||
"label": "~aaa", | ||
"sortText": "0000", | ||
"textEdit": { | ||
"newText": "~aaa", | ||
"range": { | ||
"end": { "character": 22, "line": 3 }, | ||
"start": { "character": 20, "line": 3 } | ||
} | ||
} | ||
} | ||
{ | ||
"detail": "'b", | ||
"kind": 5, | ||
"label": "~aab", | ||
"sortText": "0001", | ||
"textEdit": { | ||
"newText": "~aab", | ||
"range": { | ||
"end": { "character": 22, "line": 3 }, | ||
"start": { "character": 20, "line": 3 } | ||
} | ||
} | ||
} | ||
{ | ||
"detail": "'c", | ||
"kind": 5, | ||
"label": "~abb", | ||
"sortText": "0002", | ||
"textEdit": { | ||
"newText": "~abb", | ||
"range": { | ||
"end": { "character": 22, "line": 3 }, | ||
"start": { "character": 20, "line": 3 } | ||
} | ||
} | ||
} | ||
**************************************** | ||
{ | ||
"detail": "'a", | ||
"kind": 5, | ||
"label": "?aaa", | ||
"sortText": "0000", | ||
"textEdit": { | ||
"newText": "?aaa", | ||
"range": { | ||
"end": { "character": 22, "line": 4 }, | ||
"start": { "character": 20, "line": 4 } | ||
} | ||
} | ||
} | ||
{ | ||
"detail": "'b", | ||
"kind": 5, | ||
"label": "?aab", | ||
"sortText": "0001", | ||
"textEdit": { | ||
"newText": "?aab", | ||
"range": { | ||
"end": { "character": 22, "line": 4 }, | ||
"start": { "character": 20, "line": 4 } | ||
} | ||
} | ||
} | ||
{ | ||
"detail": "'c", | ||
"kind": 5, | ||
"label": "~abb", | ||
"sortText": "0002", | ||
"textEdit": { | ||
"newText": "~abb", | ||
"range": { | ||
"end": { "character": 22, "line": 4 }, | ||
"start": { "character": 20, "line": 4 } | ||
} | ||
} | ||
} | ||
|}] |
This file contains 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 |
---|---|---|
|
@@ -45,6 +45,7 @@ | |
action_mark_remove | ||
code_actions | ||
completion | ||
completions | ||
doc_to_md | ||
document_flow | ||
exit_notification | ||
|
This file contains 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,36 @@ | ||
open Test.Import | ||
|
||
let client_capabilities = ClientCapabilities.create () | ||
|
||
let uri = DocumentUri.of_path "test.ml" | ||
|
||
let test ?extra_env text req = | ||
let handler = | ||
Client.Handler.make | ||
~on_notification:(fun client _notification -> | ||
Client.state client; | ||
Fiber.return ()) | ||
() | ||
in | ||
Test.run ~handler ?extra_env (fun client -> | ||
let run_client () = | ||
Client.start | ||
client | ||
(InitializeParams.create ~capabilities:client_capabilities ()) | ||
in | ||
let run () = | ||
let* (_ : InitializeResult.t) = Client.initialized client in | ||
let textDocument = | ||
TextDocumentItem.create ~uri ~languageId:"ocaml" ~version:0 ~text | ||
in | ||
let* () = | ||
Client.notification | ||
client | ||
(TextDocumentDidOpen | ||
(DidOpenTextDocumentParams.create ~textDocument)) | ||
in | ||
let* () = req client in | ||
let* () = Client.request client Shutdown in | ||
Client.stop client | ||
in | ||
Fiber.fork_and_join_unit run_client run) |
This file contains 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,6 @@ | ||
open Test.Import | ||
|
||
val uri : Uri.t | ||
|
||
val test : | ||
?extra_env:string list -> string -> (unit Client.t -> unit Fiber.t) -> unit |
Oops, something went wrong.