Skip to content

Commit c1d16db

Browse files
committed
Some fixes
1 parent 231ceb2 commit c1d16db

File tree

6 files changed

+29
-10
lines changed

6 files changed

+29
-10
lines changed

analysis/src/CompletionBackEnd.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,10 @@ let rec completeTypedValue (t : SharedTypes.completionType) ~env ~full ~prefix
10901090
|> List.filter (fun (field : field) ->
10911091
List.mem field.fname.txt seenFields = false)
10921092
|> List.map (fun (field : field) ->
1093-
Completion.create field.fname.txt
1093+
let fname =
1094+
PrintType.printIdentLike ~allowUident:false field.fname.txt
1095+
in
1096+
Completion.create fname
10941097
~kind:(Field (field, typeExpr |> Shared.typeToString))
10951098
~env)
10961099
|> filterItems ~prefix
@@ -1214,6 +1217,7 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover
12141217
| Cjsx ([id], prefix, identsSeen) when String.uncapitalize_ascii id = id ->
12151218
(* Lowercase JSX tag means builtin *)
12161219
let mkLabel (name, typString) =
1220+
let name = PrintType.printIdentLike ~allowUident:false name in
12171221
Completion.create name ~kind:(Label typString) ~env
12181222
in
12191223
let keyLabels =
@@ -1230,6 +1234,7 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover
12301234
CompletionJsx.getJsxLabels ~componentPath ~findTypeOfValue ~package
12311235
in
12321236
let mkLabel_ name typString =
1237+
let name = PrintType.printIdentLike ~allowUident:false name in
12331238
Completion.create name ~kind:(Label typString) ~env
12341239
in
12351240
let mkLabel (name, typ, _env) =
@@ -1286,6 +1291,7 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover
12861291
| None -> []
12871292
in
12881293
let mkLabel (name, typ) =
1294+
let name = PrintType.printIdentLike ~allowUident:false name in
12891295
Completion.create name ~kind:(Label (typ |> Shared.typeToString)) ~env
12901296
in
12911297
labels

analysis/src/Hover.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ let showModuleTopLevel ~docstring ~isType ~name (topLevel : Module.item list) =
1010
" " ^ (decl |> Shared.declToString ~recStatus item.name)
1111
| Module _ -> " module " ^ item.name
1212
| Value typ ->
13-
" let " ^ item.name ^ ": " ^ (typ |> Shared.typeToString))
13+
" let "
14+
^ PrintType.printIdentLike ~allowUident:false item.name
15+
^ ": "
16+
^ (typ |> Shared.typeToString))
1417
(* TODO indent *)
1518
|> String.concat "\n"
1619
in

analysis/src/PrintType.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ let printDecl ?printNameAsIs ~recStatus name decl =
88
Res_doc.toString ~width:60
99
(Res_outcome_printer.printOutSigItemDoc ?printNameAsIs
1010
(Printtyp.tree_of_type_declaration (Ident.create name) decl recStatus))
11+
12+
let printIdentLike ~allowUident name =
13+
Res_doc.toString ~width:60
14+
(Res_outcome_printer.printIdentLike ~allowUident name)

analysis/src/SharedTypes.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,12 @@ module Completable = struct
692692
^ (match argumentLabel with
693693
| Unlabelled {argumentPosition} ->
694694
"$" ^ string_of_int argumentPosition
695-
| Labelled name -> "~" ^ name
696-
| Optional name -> "~" ^ name ^ "=?")
695+
| Labelled name ->
696+
let name = PrintType.printIdentLike ~allowUident:false name in
697+
"~" ^ name
698+
| Optional name ->
699+
let name = PrintType.printIdentLike ~allowUident:false name in
700+
"~" ^ name ^ "= ?")
697701
^ ")"
698702
| CJsxPropValue {pathToComponent; propName} ->
699703
"CJsxPropValue " ^ (pathToComponent |> list) ^ " " ^ propName

analysis/tests/src/expected/ExoticIdentifiers.res.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Hover src/ExoticIdentifiers.res 0:7
2-
{"contents": {"kind": "markdown", "value": "```rescript\nmodule X: {\n let Foo: string\n}\n```"}}
2+
{"contents": {"kind": "markdown", "value": "```rescript\nmodule X: {\n let \\\"Foo\": string\n}\n```"}}
33

44
Complete src/ExoticIdentifiers.res 5:15
55
posCursor:[5:15] posNoWhite:[5:14] Found expr:[5:13->5:15]
@@ -14,7 +14,7 @@ Completable: Cpath Value[X, ""]
1414
}]
1515

1616
Hover src/ExoticIdentifiers.res 8:12
17-
{"contents": {"kind": "markdown", "value": "```rescript\nmodule type Y = {\n let Foo: string\n}\n```"}}
17+
{"contents": {"kind": "markdown", "value": "```rescript\nmodule type Y = {\n let \\\"Foo\": string\n}\n```"}}
1818

1919
Hover src/ExoticIdentifiers.res 13:5
2020
{"contents": {"kind": "markdown", "value": "```rescript\ntype x = {\\\"Foo\": string}\n```"}}
@@ -25,10 +25,10 @@ posCursor:[17:10] posNoWhite:[17:9] Found expr:[17:5->19:11]
2525
posCursor:[17:10] posNoWhite:[17:9] Found pattern:[17:9->17:11]
2626
Completable: Cpattern Value[x]->recordBody
2727
[{
28-
"label": "Foo",
28+
"label": "\\\"Foo\"",
2929
"kind": 5,
3030
"tags": [],
31-
"detail": "Foo: string\n\nx",
31+
"detail": "\\\"Foo\": string\n\nx",
3232
"documentation": null
3333
}]
3434

@@ -41,7 +41,7 @@ Pexp_apply ...[25:3->25:4] ()
4141
Completable: CnamedArg(Value[g], "", [])
4242
Found type for function (~Foo: 'a) => 'a
4343
[{
44-
"label": "Foo",
44+
"label": "\\\"Foo\"",
4545
"kind": 4,
4646
"tags": [],
4747
"detail": "'a",
@@ -56,7 +56,7 @@ posCursor:[38:11] posNoWhite:[38:9] Found expr:[38:9->38:13]
5656
JSX <C:[38:9->38:10] > _children:38:11
5757
Completable: Cjsx([C], "", [])
5858
[{
59-
"label": "Foo",
59+
"label": "\\\"Foo\"",
6060
"kind": 4,
6161
"tags": [],
6262
"detail": "option<string>",

analysis/vendor/res_outcome_printer/res_outcome_printer.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ val parenthesized_ident : string -> bool [@@live]
1212
val setup : unit lazy_t [@@live]
1313

1414
(* Needed for e.g. the playground to print typedtree data *)
15+
val printIdentLike : allowUident:bool -> string -> Res_doc.t
16+
1517
val printOutTypeDoc : Outcometree.out_type -> Res_doc.t [@@live]
1618
val printOutSigItemDoc :
1719
?printNameAsIs:bool -> Outcometree.out_sig_item -> Res_doc.t

0 commit comments

Comments
 (0)