-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
159 additions
and
84 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ | |
document_flow | ||
for_ppx | ||
hover_extended | ||
inlay_hints | ||
metrics | ||
semantic_hl_data | ||
semantic_hl_helpers | ||
|
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,69 @@ | ||
open Test.Import | ||
|
||
let apply_inlay_hints ?(path = "foo.ml") ?range ~source () = | ||
let range = | ||
match range with | ||
| Some r -> r | ||
| None -> | ||
let end_pos = | ||
let lines = String.split source ~on:'\n' in | ||
let last_line = Option.value_exn (List.last lines) in | ||
Position.create | ||
~line:(List.length lines - 1) | ||
~character:(String.length last_line) | ||
in | ||
Range.create ~start:(Position.create ~character:0 ~line:0) ~end_:end_pos | ||
in | ||
|
||
let uri = DocumentUri.of_path path in | ||
let request = | ||
let textDocument = TextDocumentIdentifier.create ~uri in | ||
InlayHintParams.create ~textDocument ~range () | ||
in | ||
let inlay_hints = | ||
Test.run_request | ||
~prep:(fun client -> Test.openDocument ~client ~uri ~source) | ||
(InlayHint request) | ||
in | ||
match inlay_hints with | ||
| Some hints -> | ||
let text_edits = | ||
List.map hints ~f:(fun (hint : InlayHint.t) -> | ||
let paddingLeftStr = | ||
match hint.paddingLeft with | ||
| Some true -> "_$" | ||
| None | Some false -> "$" | ||
in | ||
let paddingRightStr = | ||
match hint.paddingRight with | ||
| Some true -> "$_" | ||
| None | Some false -> "$" | ||
in | ||
|
||
let newText = | ||
match hint.label with | ||
| `String s -> paddingLeftStr ^ s ^ paddingRightStr | ||
| `List _ -> failwith "TODO: implement list hints" | ||
in | ||
TextEdit.create | ||
~range:(Range.create ~start:hint.position ~end_:hint.position) | ||
~newText) | ||
in | ||
Test.apply_edits source text_edits |> print_endline | ||
| None -> print_endline "No hints found" | ||
|
||
let%expect_test "simple" = | ||
apply_inlay_hints ~source:"let x = 1 + 2" (); | ||
[%expect {| let x$: int$ = 1 + 2 |}] | ||
|
||
let%expect_test "optional argument" = | ||
apply_inlay_hints ~source:"let f ?x () = x" (); | ||
[%expect {| let f ?x$: 'a option$ () = x |}] | ||
|
||
let%expect_test "optional argument with value" = | ||
apply_inlay_hints ~source:"let f ?(x = 1) () = x" (); | ||
[%expect {| let f ?(x$: int$ = 1) () = x |}] | ||
|
||
let%expect_test "labeled argument" = | ||
apply_inlay_hints ~source:"let f ~x = x + 1" (); | ||
[%expect {| let f ~x$: int$ = x + 1 |}] |
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