Skip to content

Commit a8523cb

Browse files
committed
Merge branch 'master' into completion-revamp
2 parents aebde4a + 59855be commit a8523cb

13 files changed

+271
-134
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,22 @@
1212
1313
## master
1414

15+
## 1.20.0
16+
1517
#### :rocket: New Feature
1618

1719
- Add support for syntax highlighting in `%raw` and `%ffi` extension points. https://github.com/rescript-lang/rescript-vscode/pull/774
1820
- Add completion to top level decorators. https://github.com/rescript-lang/rescript-vscode/pull/799
1921
- Add code action for wrapping patterns where option is expected with `Some`. https://github.com/rescript-lang/rescript-vscode/pull/806
2022
- Better completion from identifiers with inferred types. https://github.com/rescript-lang/rescript-vscode/pull/808
23+
- Make suggested template functions async when the target function returns a promise. https://github.com/rescript-lang/rescript-vscode/pull/816
24+
- Fix code action for inserting undefined record fields in ReScript v11. https://github.com/rescript-lang/rescript-vscode/pull/817
2125

2226
#### :nail_care: Polish
2327

2428
- Revamp "Insert missing cases" code action to make it apply in more cases and be much more robust. https://github.com/rescript-lang/rescript-vscode/pull/804
2529
- Make the completion engine understand async/await. https://github.com/rescript-lang/rescript-vscode/pull/813
30+
- Comments are now automatically closed and indented. https://github.com/rescript-lang/rescript-vscode/pull/815
2631

2732
#### :bug: Bug Fix
2833

@@ -33,6 +38,7 @@
3338
- Fix signature help in uncurried mode. https://github.com/rescript-lang/rescript-vscode/pull/809
3439
- Fix various issues in uncurried mode. https://github.com/rescript-lang/rescript-vscode/pull/810
3540
- Fixes a bug in pattern completion where for example `result` wouldn't complete, due to type variables getting lost/not being instantiated. https://github.com/rescript-lang/rescript-vscode/pull/814
41+
- Fix bug where pipes would not be considered in certain cases when completing for single unlabelled function arguments. https://github.com/rescript-lang/rescript-vscode/pull/818
3642

3743
## 1.18.0
3844

analysis/src/CompletionBackEnd.ml

+11-4
Original file line numberDiff line numberDiff line change
@@ -1385,8 +1385,8 @@ let rec completeTypedValue ~full ~prefix ~completionContext ~mode
13851385
~env ();
13861386
]
13871387
else []
1388-
| Tfunction {env; typ; args; uncurried} when prefix = "" && mode = Expression
1389-
->
1388+
| Tfunction {env; typ; args; uncurried; returnType}
1389+
when prefix = "" && mode = Expression ->
13901390
let shouldPrintAsUncurried = uncurried && !Config.uncurried <> Uncurried in
13911391
let mkFnArgs ~asSnippet =
13921392
match args with
@@ -1422,11 +1422,18 @@ let rec completeTypedValue ~full ~prefix ~completionContext ~mode
14221422
in
14231423
"(" ^ if shouldPrintAsUncurried then ". " else "" ^ argsText ^ ")"
14241424
in
1425+
let isAsync =
1426+
match TypeUtils.extractType ~env ~package:full.package returnType with
1427+
| Some (Tpromise _) -> true
1428+
| _ -> false
1429+
in
1430+
let asyncPrefix = if isAsync then "async " else "" in
14251431
[
14261432
Completion.createWithSnippet
1427-
~name:(mkFnArgs ~asSnippet:false ^ " => {}")
1433+
~name:(asyncPrefix ^ mkFnArgs ~asSnippet:false ^ " => {}")
14281434
~insertText:
1429-
(mkFnArgs ~asSnippet:!Cfg.supportsSnippets
1435+
(asyncPrefix
1436+
^ mkFnArgs ~asSnippet:!Cfg.supportsSnippets
14301437
^ " => "
14311438
^ if !Cfg.supportsSnippets then "{$0}" else "{}")
14321439
~sortText:"A" ~kind:(Value typ) ~env ();

analysis/src/CompletionFrontEnd.ml

+3-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ let findArgCompletables ~(args : arg list) ~endPos ~posBeforeCursor
129129
CArgument
130130
{
131131
functionContextPath = contextPath;
132-
argumentLabel = Unlabelled {argumentPosition = 0};
132+
argumentLabel =
133+
Unlabelled
134+
{argumentPosition = (if isPipedExpr then 1 else 0)};
133135
};
134136
prefix = "";
135137
nested = [];

analysis/src/SharedTypes.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,8 @@ and completionType =
342342
env: QueryEnv.t;
343343
args: typedFnArg list;
344344
typ: Types.type_expr;
345-
returnType: Types.type_expr;
346345
uncurried: bool;
346+
returnType: Types.type_expr;
347347
}
348348

349349
module Env = struct

analysis/tests/src/CompletionExpressions.res

+12
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,15 @@ external commitLocalUpdate: (~updater: RecordSourceSelectorProxy.t => unit) => u
250250

251251
// commitLocalUpdate(~updater=)
252252
// ^com
253+
254+
let fnTakingAsyncCallback = (cb: unit => promise<unit>) => {
255+
let _ = cb
256+
}
257+
258+
// fnTakingAsyncCallback()
259+
// ^com
260+
261+
let arr = ["hello"]
262+
263+
// arr->Belt.Array.map()
264+
// ^com

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

+39
Original file line numberDiff line numberDiff line change
@@ -1074,3 +1074,42 @@ Path commitLocalUpdate
10741074
"insertTextFormat": 2
10751075
}]
10761076

1077+
Complete src/CompletionExpressions.res 257:25
1078+
posCursor:[257:25] posNoWhite:[257:24] Found expr:[257:3->257:26]
1079+
Pexp_apply ...[257:3->257:24] (...[257:25->257:26])
1080+
Completable: Cexpression CArgument Value[fnTakingAsyncCallback]($0)
1081+
Package opens Pervasives.JsxModules.place holder
1082+
Resolved opens 1 pervasives
1083+
ContextPath CArgument Value[fnTakingAsyncCallback]($0)
1084+
ContextPath Value[fnTakingAsyncCallback]
1085+
Path fnTakingAsyncCallback
1086+
[{
1087+
"label": "async () => {}",
1088+
"kind": 12,
1089+
"tags": [],
1090+
"detail": "unit => promise<unit>",
1091+
"documentation": null,
1092+
"sortText": "A",
1093+
"insertText": "async () => {$0}",
1094+
"insertTextFormat": 2
1095+
}]
1096+
1097+
Complete src/CompletionExpressions.res 262:23
1098+
posCursor:[262:23] posNoWhite:[262:22] Found expr:[262:3->262:24]
1099+
Completable: Cexpression CArgument Value[Belt, Array, map]($1)
1100+
Package opens Pervasives.JsxModules.place holder
1101+
Resolved opens 1 pervasives
1102+
ContextPath CArgument Value[Belt, Array, map]($1)
1103+
ContextPath Value[Belt, Array, map]
1104+
Path Belt.Array.map
1105+
[{
1106+
"label": "v => {}",
1107+
"kind": 12,
1108+
"tags": [],
1109+
"detail": "'a => 'b",
1110+
"documentation": null,
1111+
"sortText": "A",
1112+
"insertText": "${1:v} => {$0}",
1113+
"insertTextFormat": 2
1114+
}]
1115+

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

+30-44
Original file line numberDiff line numberDiff line change
@@ -154,40 +154,33 @@ CRecordField: found record: type someRecord = {nested: option<nestedRecord>, var
154154

155155
Complete2 src/CompletionNew.res 33:39
156156
Scope: 105 items
157-
Completable: Cexpression: ctxPath: (Type(prefix=someRecord))->followRecordField{variant} , prefix: "O"
157+
Completable: Cexpression: ctxPath: Type(prefix=someRecord) , prefix: "O"
158158
Package opens Pervasives.JsxModules.place holder
159159
Resolved opens 1 pervasives
160160
Path someRecord
161-
CRecordFieldFollow: type of field ("variant") to follow: someVariant
162161
[{
163-
"label": "One",
164-
"kind": 4,
162+
"label": "Obj",
163+
"kind": 9,
165164
"tags": [],
166-
"detail": "One\n\ntype someVariant =\n | One\n | Two\n | Three(bool, option<someVariant>)",
167-
"documentation": null,
168-
"insertText": "One",
169-
"insertTextFormat": 2
165+
"detail": "file module",
166+
"documentation": null
167+
}, {
168+
"label": "Objects",
169+
"kind": 9,
170+
"tags": [],
171+
"detail": "file module",
172+
"documentation": null
170173
}]
171174

172175
Complete2 src/CompletionNew.res 36:72
173176
Scope: 105 items
174-
Completable: Cexpression: ctxPath: ((((Type(prefix=someRecord))->followRecordField{nested})->variantPayload(Some<$0>))->followRecordField{maybeVariant})->variantPayload(Three<$1>) , prefix: "So"
177+
Completable: Cexpression: ctxPath: ((Type(prefix=someRecord))->variantPayload(Some<$0>))->variantPayload(Three<$1>) , prefix: "So"
175178
Package opens Pervasives.JsxModules.place holder
176179
Resolved opens 1 pervasives
177180
Path someRecord
178-
CRecordFieldFollow: type of field ("nested") to follow: option<nestedRecord>
179-
CRecordFieldFollow: type of field ("maybeVariant") to follow: someVariant
180-
CVariantPayload: found payload type: option<someVariant>
181+
CVariantPayload(constructorName: Some, itemNum: 0): some other type than a variant found at variant ctx path: type someRecord = {nested: option<nestedRecord>, variant: someVariant, someString: string}
182+
CVariantPayload: did not find type at variant ctx path
181183
[{
182-
"label": "Some(_)",
183-
"kind": 12,
184-
"tags": [],
185-
"detail": "someVariant",
186-
"documentation": null,
187-
"sortText": "A Some(_)",
188-
"insertText": "Some(${1:_})",
189-
"insertTextFormat": 2
190-
}, {
191184
"label": "Sort",
192185
"kind": 9,
193186
"tags": [],
@@ -230,25 +223,13 @@ CRecordFieldFollow: type of field ("variant") to follow: someVariant
230223

231224
Complete2 src/CompletionNew.res 42:61
232225
Scope: 105 items
233-
Completable: Cexpression: ctxPath: ((Type(prefix=someRecord))->followRecordField{nested})->variantPayload(Some<$0>)->recordField("", [maybeVariant])
226+
Completable: Cexpression: ctxPath: (Type(prefix=someRecord))->variantPayload(Some<$0>)->recordField("", [maybeVariant])
234227
Package opens Pervasives.JsxModules.place holder
235228
Resolved opens 1 pervasives
236229
Path someRecord
237-
CRecordFieldFollow: type of field ("nested") to follow: option<nestedRecord>
238-
CRecordField: found record: nestedRecord
239-
[{
240-
"label": "on",
241-
"kind": 5,
242-
"tags": [],
243-
"detail": "on: bool\n\nnestedRecord",
244-
"documentation": null
245-
}, {
246-
"label": "off",
247-
"kind": 5,
248-
"tags": [],
249-
"detail": "off?: bool\n\nnestedRecord",
250-
"documentation": null
251-
}]
230+
CVariantPayload(constructorName: Some, itemNum: 0): some other type than a variant found at variant ctx path: type someRecord = {nested: option<nestedRecord>, variant: someVariant, someString: string}
231+
CRecordField: found no type at record ctx path
232+
[]
252233

253234
Complete2 src/CompletionNew.res 45:63
254235
Scope: 105 items
@@ -286,22 +267,27 @@ Resolved opens 1 pervasives
286267

287268
Complete2 src/CompletionNew.res 53:73
288269
Scope: 106 items
289-
Completable: Cexpression: ctxPath: ((Type(prefix=someRecord))->followRecordField{nested})->followRecordField{maybeVariant}
270+
Completable: Cexpression: ctxPath: Type(prefix=someRecord)
290271
Package opens Pervasives.JsxModules.place holder
291272
Resolved opens 1 pervasives
292273
Path someRecord
293-
CRecordFieldFollow: type of field ("nested") to follow: option<nestedRecord>
294-
CRecordFieldFollow: found type at record ctx path, but it's not a record: option<nestedRecord>
295-
[]
274+
[{
275+
"label": "{}",
276+
"kind": 12,
277+
"tags": [],
278+
"detail": "type someRecord = {nested: option<nestedRecord>, variant: someVariant, someString: string}",
279+
"documentation": null,
280+
"sortText": "A",
281+
"insertText": "{$0}",
282+
"insertTextFormat": 2
283+
}]
296284

297285
Complete2 src/CompletionNew.res 57:86
298286
Scope: 106 items
299-
Completable: Cexpression: ctxPath: ((Type(prefix=someRecord))->followRecordField{nested})->followRecordField{maybeVariant} , prefix: "So"
287+
Completable: Cexpression: ctxPath: Type(prefix=someRecord) , prefix: "So"
300288
Package opens Pervasives.JsxModules.place holder
301289
Resolved opens 1 pervasives
302290
Path someRecord
303-
CRecordFieldFollow: type of field ("nested") to follow: option<nestedRecord>
304-
CRecordFieldFollow: found type at record ctx path, but it's not a record: option<nestedRecord>
305291
[{
306292
"label": "Sort",
307293
"kind": 9,

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "ReScript language support (official)",
55
"author": "chenglou",
66
"license": "MIT",
7-
"version": "1.18.0",
7+
"version": "1.20.0",
88
"repository": {
99
"type": "git",
1010
"url": "https://github.com/rescript-lang/rescript-vscode"

rescript.configuration.json

+22-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@
4040
[
4141
"`",
4242
"`"
43-
]
43+
],
44+
{
45+
"open": "/*",
46+
"close": " */",
47+
"notIn": ["string"]
48+
}
4449
],
4550
"surroundingPairs": [
4651
[
@@ -69,5 +74,20 @@
6974
"start": "^\\s*//\\s*#?region\\b",
7075
"end": "^\\s*//\\s*#?endregion\\b"
7176
}
72-
}
77+
},
78+
"onEnterRules": [
79+
{
80+
"beforeText": { "pattern": "^\\s*/\\*(?!/)([^\\*]|\\*(?!/))*$" },
81+
"afterText": { "pattern": "^\\s*\\*/$" },
82+
"action": { "indent": "indentOutdent", "appendText": " "}
83+
},
84+
{
85+
"beforeText": { "pattern": "^\\s*/\\*(?!/)([^\\*]|\\*(?!/))*$" },
86+
"action": { "indent": "none", "appendText": " "}
87+
},
88+
{
89+
"beforeText": { "pattern": "^(\\t|[ ])*[ ]\\*/\\s*$" },
90+
"action": { "indent": "none", "removeText": 1 }
91+
}
92+
]
7393
}

server/package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "rescript-language-server",
33
"description": "ReScript's language-server",
4-
"version": "1.18.0",
4+
"version": "1.20.0",
55
"author": "chenglou",
66
"license": "MIT",
77
"engines": {

0 commit comments

Comments
 (0)