Skip to content
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

Fix printtyp issue with completion #1884

Merged
merged 3 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ocaml-lsp-compat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
os:
- ubuntu-latest
ocaml-compiler:
- ocaml-base-compiler.5.3.0~alpha1
- ocaml-base-compiler.5.3.0
# The type of runner that the job will run on
runs-on: ${{ matrix.os }}

Expand All @@ -52,6 +52,6 @@ jobs:
- name: Check that Merlin and OCaml-LSP are co-installable
run: |
opam --cli=2.1 pin --with-version=dev --no-action https://github.com/voodoos/ocaml-lsp.git#merlin-503-compat
opam --cli=2.1 pin --with-version=5.3-503 --no-action .
opam --cli=2.1 pin --with-version=5.4-503 --no-action .
opam install ocaml-lsp-server --ignore-constraints-on=ocamlformat
5 changes: 3 additions & 2 deletions src/analysis/completion.ml
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ let raw_info_printer : raw_info -> _ = function
(Out_sig_item
(Out_type.tree_of_type_declaration id tdecl Types.Trec_first))
| `Type_scheme te ->
`Print (Out_type (Out_type.tree_of_typexp Type_scheme te))
`Print (Out_type (Type_utils.Printtyp.tree_of_typ_scheme te))
| `Variant (label, arg) -> begin
match arg with
| None -> `String label
| Some te ->
`Concat (label ^ " of ", Out_type (Out_type.tree_of_typexp Type_scheme te))
`Concat
(label ^ " of ", Out_type (Type_utils.Printtyp.tree_of_typ_scheme te))
end

(* List methods of an object.
Expand Down
4 changes: 4 additions & 0 deletions src/analysis/type_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ module Printtyp = struct
(select_by_verbosity ~default:type_scheme ~verbose:(verbose_type_scheme env))
ppf ty

let tree_of_typ_scheme te =
Out_type.prepare_for_printing [ te ];
Out_type.tree_of_typexp Type_scheme te

let type_declaration env id ppf =
(select_by_verbosity ~default:type_declaration
~verbose:(verbose_type_declaration env))
Expand Down
2 changes: 2 additions & 0 deletions src/analysis/type_utils.mli
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ module Printtyp : sig

val type_scheme : Env.t -> Format.formatter -> Types.type_expr -> unit

val tree_of_typ_scheme : Types.type_expr -> Outcometree.out_type

val modtype : Env.t -> Format.formatter -> Types.module_type -> unit

val wrap_printing_env :
Expand Down
39 changes: 39 additions & 0 deletions tests/test-dirs/completion/issue-lsp-503.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

$ cat >test.ml <<'EOF'
> [1;2]|>List.ma
> EOF

We complete the name of the object

$ $MERLIN single complete-prefix -position 1:14 -prefix "List.ma" \
> -filename test.ml < test.ml
{
"class": "return",
"value": {
"entries": [
{
"name": "map",
"kind": "Value",
"desc": "('a -> 'b) -> 'a list -> 'b list",
"info": "",
"deprecated": false
},
{
"name": "mapi",
"kind": "Value",
"desc": "(int -> 'a -> 'b) -> 'a list -> 'b list",
"info": "",
"deprecated": false
},
{
"name": "map2",
"kind": "Value",
"desc": "('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list",
"info": "",
"deprecated": false
}
],
"context": null
},
"notifications": []
}
Loading