Skip to content

Commit 2f38459

Browse files
authored
Better completion for applications (#7291)
* WIP: better completion for applications * Comment out scope thing * Uncomment filter * Remove verbose * Optional dig * Add changelog entry
1 parent fd1e7b8 commit 2f38459

File tree

6 files changed

+63
-30
lines changed

6 files changed

+63
-30
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
- Stdlib namespace for Core modules (fixes name clashes with user modules). https://github.com/rescript-lang/rescript/pull/7285
3636
- Fix runtime type check for Object in untagged variants when one variant case is `null`. https://github.com/rescript-lang/rescript/pull/7303
3737
- Fix files that were being truncated when sent to the CDN over FTP. https://github.com/rescript-lang/rescript/pull/7306
38+
- Fix better editor completion for applications. https://github.com/rescript-lang/rescript/pull/7291
3839

3940
#### :house: Internal
4041

analysis/src/CompletionBackEnd.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,8 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
965965
| [], [(Nolabel | Labelled _ | Optional _)] ->
966966
(* should not happen, but just ignore extra arguments *) []
967967
in
968-
match TypeUtils.extractFunctionType ~env ~package typ with
968+
969+
match TypeUtils.extractFunctionType ~env ~package ~digInto:false typ with
969970
| args, tRet when args <> [] ->
970971
let args = processApply args labels in
971972
let retType = reconstructFunctionType args tRet in

analysis/src/TypeUtils.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,12 @@ let rec extractObjectType ~env ~package (t : Types.type_expr) =
243243
| _ -> None)
244244
| _ -> None
245245

246-
let extractFunctionType ~env ~package typ =
246+
let extractFunctionType ~env ~package ?(digInto = true) typ =
247247
let rec loop ~env acc (t : Types.type_expr) =
248248
match t.desc with
249249
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> loop ~env acc t1
250250
| Tarrow (label, tArg, tRet, _, _) -> loop ~env ((label, tArg) :: acc) tRet
251-
| Tconstr (path, typeArgs, _) -> (
251+
| Tconstr (path, typeArgs, _) when digInto -> (
252252
match References.digConstructor ~env ~package path with
253253
| Some
254254
( env,

tests/analysis_tests/tests/src/CompletionTaggedTemplate.res

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module M = {
2-
type t
2+
type t = promise<string>
33

44
let a = (_t:t) => 4
55
let b = (_:t) => "c"
@@ -9,8 +9,10 @@ module M = {
99
@module("meh") @taggedTemplate
1010
external meh: (array<string>, array<string>) => M.t = "default"
1111

12+
let w = meh``
13+
14+
// let _ = w.
15+
// ^com
16+
1217
// let x = meh`foo`.
1318
// ^com
14-
15-
// let y = meh`bar`.x
16-
// ^com

tests/analysis_tests/tests/src/expected/Completion.res.txt

+8-2
Original file line numberDiff line numberDiff line change
@@ -1841,13 +1841,19 @@ Resolved opens 3 Stdlib Completion Completion
18411841
ContextPath Value[withCallback](~a)
18421842
ContextPath Value[withCallback]
18431843
Path withCallback
1844-
Found type for function (~b: int) => int
1844+
Found type for function (~b: int) => callback
18451845
[{
18461846
"label": "b",
18471847
"kind": 4,
18481848
"tags": [],
18491849
"detail": "int",
18501850
"documentation": null
1851+
}, {
1852+
"label": "a",
1853+
"kind": 4,
1854+
"tags": [],
1855+
"detail": "int",
1856+
"documentation": null
18511857
}]
18521858

18531859
Complete src/Completion.res 332:21
@@ -1860,7 +1866,7 @@ Resolved opens 3 Stdlib Completion Completion
18601866
ContextPath Value[withCallback](~b)
18611867
ContextPath Value[withCallback]
18621868
Path withCallback
1863-
Found type for function (~a: int) => int
1869+
Found type for function callback
18641870
[{
18651871
"label": "a",
18661872
"kind": 4,

tests/analysis_tests/tests/src/expected/CompletionTaggedTemplate.res.txt

+44-21
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
Complete src/CompletionTaggedTemplate.res 11:20
2-
posCursor:[11:20] posNoWhite:[11:19] Found expr:[11:11->0:-1]
3-
Completable: Cpath Value[meh](Nolabel, Nolabel).""
1+
Complete src/CompletionTaggedTemplate.res 13:13
2+
posCursor:[13:13] posNoWhite:[13:12] Found expr:[13:11->13:13]
3+
Pexp_field [13:11->13:12] _:[19:0->13:13]
4+
Completable: Cpath Value[w].""
45
Package opens Stdlib.place holder Pervasives.JsxModules.place holder
56
Resolved opens 1 Stdlib
6-
ContextPath Value[meh](Nolabel, Nolabel).""
7-
ContextPath Value[meh](Nolabel, Nolabel)
8-
ContextPath Value[meh]
9-
Path meh
10-
ContextPath Value[meh](Nolabel, Nolabel, Nolabel)->
11-
ContextPath Value[meh](Nolabel, Nolabel, Nolabel)
12-
ContextPath Value[meh]
13-
Path meh
7+
ContextPath Value[w].""
8+
ContextPath Value[w]
9+
Path w
10+
ContextPath Value[w]->
11+
ContextPath Value[w]
12+
Path w
1413
CPPipe pathFromEnv:M found:true
1514
Path M.
1615
[{
@@ -22,7 +21,7 @@ Path M.
2221
"sortText": "xyz",
2322
"insertText": "->M.xyz",
2423
"additionalTextEdits": [{
25-
"range": {"start": {"line": 11, "character": 19}, "end": {"line": 11, "character": 20}},
24+
"range": {"start": {"line": 13, "character": 12}, "end": {"line": 13, "character": 13}},
2625
"newText": ""
2726
}]
2827
}, {
@@ -34,7 +33,7 @@ Path M.
3433
"sortText": "b",
3534
"insertText": "->M.b",
3635
"additionalTextEdits": [{
37-
"range": {"start": {"line": 11, "character": 19}, "end": {"line": 11, "character": 20}},
36+
"range": {"start": {"line": 13, "character": 12}, "end": {"line": 13, "character": 13}},
3837
"newText": ""
3938
}]
4039
}, {
@@ -46,26 +45,26 @@ Path M.
4645
"sortText": "a",
4746
"insertText": "->M.a",
4847
"additionalTextEdits": [{
49-
"range": {"start": {"line": 11, "character": 19}, "end": {"line": 11, "character": 20}},
48+
"range": {"start": {"line": 13, "character": 12}, "end": {"line": 13, "character": 13}},
5049
"newText": ""
5150
}]
5251
}]
5352

54-
Complete src/CompletionTaggedTemplate.res 14:21
55-
posCursor:[14:21] posNoWhite:[14:20] Found expr:[14:11->14:21]
56-
Completable: Cpath Value[meh](Nolabel, Nolabel).x
53+
Complete src/CompletionTaggedTemplate.res 16:20
54+
posCursor:[16:20] posNoWhite:[16:19] Found expr:[16:11->0:-1]
55+
Completable: Cpath Value[meh](Nolabel, Nolabel).""
5756
Package opens Stdlib.place holder Pervasives.JsxModules.place holder
5857
Resolved opens 1 Stdlib
59-
ContextPath Value[meh](Nolabel, Nolabel).x
58+
ContextPath Value[meh](Nolabel, Nolabel).""
6059
ContextPath Value[meh](Nolabel, Nolabel)
6160
ContextPath Value[meh]
6261
Path meh
63-
ContextPath Value[meh](Nolabel, Nolabel, Nolabel)->x
62+
ContextPath Value[meh](Nolabel, Nolabel, Nolabel)->
6463
ContextPath Value[meh](Nolabel, Nolabel, Nolabel)
6564
ContextPath Value[meh]
6665
Path meh
6766
CPPipe pathFromEnv:M found:true
68-
Path M.x
67+
Path M.
6968
[{
7069
"label": "->M.xyz",
7170
"kind": 12,
@@ -75,7 +74,31 @@ Path M.x
7574
"sortText": "xyz",
7675
"insertText": "->M.xyz",
7776
"additionalTextEdits": [{
78-
"range": {"start": {"line": 14, "character": 19}, "end": {"line": 14, "character": 20}},
77+
"range": {"start": {"line": 16, "character": 19}, "end": {"line": 16, "character": 20}},
78+
"newText": ""
79+
}]
80+
}, {
81+
"label": "->M.b",
82+
"kind": 12,
83+
"tags": [],
84+
"detail": "t => string",
85+
"documentation": null,
86+
"sortText": "b",
87+
"insertText": "->M.b",
88+
"additionalTextEdits": [{
89+
"range": {"start": {"line": 16, "character": 19}, "end": {"line": 16, "character": 20}},
90+
"newText": ""
91+
}]
92+
}, {
93+
"label": "->M.a",
94+
"kind": 12,
95+
"tags": [],
96+
"detail": "t => int",
97+
"documentation": null,
98+
"sortText": "a",
99+
"insertText": "->M.a",
100+
"additionalTextEdits": [{
101+
"range": {"start": {"line": 16, "character": 19}, "end": {"line": 16, "character": 20}},
79102
"newText": ""
80103
}]
81104
}]

0 commit comments

Comments
 (0)