Skip to content

Commit 4fd3ed4

Browse files
committed
complete string (for consistency) and fix sort texts
1 parent fbcd530 commit 4fd3ed4

8 files changed

+57
-21
lines changed

analysis/src/CompletionBackEnd.ml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,6 +1717,7 @@ let rec extractType ~env ~package (t : Types.type_expr) =
17171717
| Tconstr (Path.Pident {name = "array"}, [payloadTypeExpr], _) ->
17181718
Some (Tarray (env, payloadTypeExpr))
17191719
| Tconstr (Path.Pident {name = "bool"}, [], _) -> Some (Tbool env)
1720+
| Tconstr (Path.Pident {name = "string"}, [], _) -> Some (Tstring env)
17201721
| Tconstr (path, _, _) -> (
17211722
match References.digConstructor ~env ~package path with
17221723
| Some (env, {item = {decl = {type_manifest = Some t1}}}) ->
@@ -1855,15 +1856,27 @@ let completeTypedValue ~env ~full ~prefix ~completionContext =
18551856
[
18561857
Completion.createWithSnippet ~name:"{}"
18571858
~insertText:(if !Cfg.supportsSnippets then "{$0}" else "{}")
1858-
~sortText:"a" ~kind:(Value typeExpr) ~env ();
1859+
~sortText:"A" ~kind:(Value typeExpr) ~env ();
18591860
]
18601861
else [])
18611862
| Some (Tarray (env, typeExpr)) ->
18621863
if prefix = "" then
18631864
[
18641865
Completion.createWithSnippet ~name:"[]"
18651866
~insertText:(if !Cfg.supportsSnippets then "[$0]" else "[]")
1866-
~sortText:"a" ~kind:(Value typeExpr) ~env ();
1867+
~sortText:"A" ~kind:(Value typeExpr) ~env ();
1868+
]
1869+
else []
1870+
| Some (Tstring env) ->
1871+
if prefix = "" then
1872+
[
1873+
Completion.createWithSnippet ~name:"\"\""
1874+
~insertText:(if !Cfg.supportsSnippets then "\"$0\"" else "\"\"")
1875+
~sortText:"A"
1876+
~kind:
1877+
(Value
1878+
(Ctype.newconstr (Path.Pident (Ident.create "string")) []))
1879+
~env ();
18671880
]
18681881
else []
18691882
| _ -> []
@@ -2297,7 +2310,7 @@ Note: The `@react.component` decorator requires the react-jsx config to be set i
22972310
{
22982311
c with
22992312
sortText =
2300-
Some ("AAA" ^ string_of_int (index + 1) ^ " " ^ c.name);
2313+
Some ("A" ^ string_of_int (index + 1) ^ " " ^ c.name);
23012314
})
23022315
else items
23032316
in

analysis/src/Protocol.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ let stringifyObject properties =
109109
|> String.concat ",\n")
110110
^ "\n }"
111111

112-
let wrapInQuotes s = "\"" ^ s ^ "\""
112+
let wrapInQuotes s = "\"" ^ Json.escape s ^ "\""
113113

114114
let optWrapInQuotes s =
115115
match s with
@@ -119,10 +119,10 @@ let optWrapInQuotes s =
119119
let stringifyCompletionItem c =
120120
stringifyObject
121121
[
122-
("label", Some (wrapInQuotes (Json.escape c.label)));
122+
("label", Some (wrapInQuotes c.label));
123123
("kind", Some (string_of_int c.kind));
124124
("tags", Some (c.tags |> List.map string_of_int |> array));
125-
("detail", Some (wrapInQuotes (Json.escape c.detail)));
125+
("detail", Some (wrapInQuotes c.detail));
126126
( "documentation",
127127
Some
128128
(match c.documentation with

analysis/src/SharedTypes.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ module Completable = struct
605605
| Toption of QueryEnv.t * Types.type_expr
606606
| Tbool of QueryEnv.t
607607
| Tarray of QueryEnv.t * Types.type_expr
608+
| Tstring of QueryEnv.t
608609
| Tvariant of {
609610
env: QueryEnv.t;
610611
constructors: Constructor.t list;

analysis/tests/src/CompletionExpressions.res

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,10 @@ let someBoolVar = true
8989

9090
// let _ = fnTakingRecord({offline: so })
9191
// ^com
92+
93+
let fnTakingOtherRecord = (r: otherRecord) => {
94+
ignore(r)
95+
}
96+
97+
// let _ = fnTakingOtherRecord({otherField: })
98+
// ^com

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ Completable: Cexpression CArgument Value[fnTakingRecord]($0)=O->recordField(vari
233233
"tags": [],
234234
"detail": "One\n\ntype someVariant = One | Two | Three(int, string)",
235235
"documentation": null,
236-
"sortText": "AAA1 One",
236+
"sortText": "A1 One",
237237
"insertText": "One",
238238
"insertTextFormat": 2
239239
}, {
@@ -260,7 +260,7 @@ Completable: Cexpression CArgument Value[fnTakingRecord]($0)->recordField(polyva
260260
"tags": [],
261261
"detail": "someRecord",
262262
"documentation": null,
263-
"sortText": "a",
263+
"sortText": "A",
264264
"insertText": "{$0}",
265265
"insertTextFormat": 2
266266
}]
@@ -305,7 +305,7 @@ Completable: Cexpression CArgument Value[fnTakingArray]($0)
305305
"tags": [],
306306
"detail": "option<bool>",
307307
"documentation": null,
308-
"sortText": "a",
308+
"sortText": "A",
309309
"insertText": "[$0]",
310310
"insertTextFormat": 2
311311
}]
@@ -412,3 +412,18 @@ Completable: Cexpression CArgument Value[fnTakingRecord]($0)=so
412412
"documentation": null
413413
}]
414414

415+
Complete src/CompletionExpressions.res 96:43
416+
posCursor:[96:43] posNoWhite:[96:42] Found expr:[96:11->96:46]
417+
Pexp_apply ...[96:11->96:30] (...[96:31->96:46])
418+
Completable: Cexpression CArgument Value[fnTakingOtherRecord]($0)->recordField(otherField)
419+
[{
420+
"label": "\"\"",
421+
"kind": 12,
422+
"tags": [],
423+
"detail": "string",
424+
"documentation": null,
425+
"sortText": "A",
426+
"insertText": "\"$0\"",
427+
"insertTextFormat": 2
428+
}]
429+

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Completable: Cexpression CArgument Value[someFn](~isOn)=t
2626
"tags": [],
2727
"detail": "bool",
2828
"documentation": null,
29-
"sortText": "AAA1 true"
29+
"sortText": "A1 true"
3030
}, {
3131
"label": "tLocalVar",
3232
"kind": 12,
@@ -127,7 +127,7 @@ Completable: Cexpression CArgument Value[someFnTakingVariant](~config)=O
127127
"tags": [],
128128
"detail": "One\n\ntype someVariant = One | Two | Three(int, string)",
129129
"documentation": null,
130-
"sortText": "AAA1 One",
130+
"sortText": "A1 One",
131131
"insertText": "One",
132132
"insertTextFormat": 2
133133
}, {
@@ -160,7 +160,7 @@ Completable: Cexpression CArgument Value[someFnTakingVariant]($0)=So
160160
"tags": [],
161161
"detail": "someVariant",
162162
"documentation": null,
163-
"sortText": "AAA1 Some(_)",
163+
"sortText": "A1 Some(_)",
164164
"insertText": "Some(${1:_})",
165165
"insertTextFormat": 2
166166
}, {
@@ -181,7 +181,7 @@ Completable: Cexpression CArgument Value[someFnTakingVariant](~configOpt2)=O
181181
"tags": [],
182182
"detail": "One\n\ntype someVariant = One | Two | Three(int, string)",
183183
"documentation": null,
184-
"sortText": "AAA1 One",
184+
"sortText": "A1 One",
185185
"insertText": "One",
186186
"insertTextFormat": 2
187187
}, {
@@ -249,7 +249,7 @@ Completable: Cexpression CArgument Value[someOtherFn]($2)=t
249249
"tags": [],
250250
"detail": "bool",
251251
"documentation": null,
252-
"sortText": "AAA1 true"
252+
"sortText": "A1 true"
253253
}, {
254254
"label": "tLocalVar",
255255
"kind": 12,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Completable: Cexpression CJsxPropValue [CompletionSupport, TestComponent] test=T
3838
"tags": [],
3939
"detail": "Two\n\ntype testVariant = One | Two | Three(int)",
4040
"documentation": null,
41-
"sortText": "AAA1 Two",
41+
"sortText": "A1 Two",
4242
"insertText": "Two",
4343
"insertTextFormat": 2
4444
}, {
@@ -47,7 +47,7 @@ Completable: Cexpression CJsxPropValue [CompletionSupport, TestComponent] test=T
4747
"tags": [],
4848
"detail": "Three(int)\n\ntype testVariant = One | Two | Three(int)",
4949
"documentation": null,
50-
"sortText": "AAA2 Three(_)",
50+
"sortText": "A2 Three(_)",
5151
"insertText": "Three(${1:_})",
5252
"insertTextFormat": 2
5353
}, {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Completable: Cpattern Value[f]
8080
"tags": [],
8181
"detail": "someRecord",
8282
"documentation": null,
83-
"sortText": "a",
83+
"sortText": "A",
8484
"insertText": "{$0}",
8585
"insertTextFormat": 2
8686
}]
@@ -170,7 +170,7 @@ Completable: Cpattern Value[f]->recordField(nest)
170170
"tags": [],
171171
"detail": "nestedRecord",
172172
"documentation": null,
173-
"sortText": "a",
173+
"sortText": "A",
174174
"insertText": "{$0}",
175175
"insertTextFormat": 2
176176
}]
@@ -414,7 +414,7 @@ Completable: Cpattern Value[c]
414414
"tags": [],
415415
"detail": "bool",
416416
"documentation": null,
417-
"sortText": "a",
417+
"sortText": "A",
418418
"insertText": "[$0]",
419419
"insertTextFormat": 2
420420
}]
@@ -531,7 +531,7 @@ Completable: Cpattern Value[p]->variantPayload::Test($3)
531531
"tags": [],
532532
"detail": "bool",
533533
"documentation": null,
534-
"sortText": "a",
534+
"sortText": "A",
535535
"insertText": "[$0]",
536536
"insertTextFormat": 2
537537
}]
@@ -605,7 +605,7 @@ Completable: Cpattern Value[v]->polyvariantPayload::test($3)
605605
"tags": [],
606606
"detail": "bool",
607607
"documentation": null,
608-
"sortText": "a",
608+
"sortText": "A",
609609
"insertText": "[$0]",
610610
"insertTextFormat": 2
611611
}]

0 commit comments

Comments
 (0)