Skip to content

Commit 80fde16

Browse files
authored
Enhance module attribute completion some more (#918)
* enhance module attribute completion some more * changelog * sort file results
1 parent 945bb85 commit 80fde16

File tree

6 files changed

+102
-13
lines changed

6 files changed

+102
-13
lines changed

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
- Enhance decorator completion. https://github.com/rescript-lang/rescript-vscode/pull/908
1818
- Completion for import attributes in `@module`. https://github.com/rescript-lang/rescript-vscode/pull/913
19+
- Relax filter for what local files that come up in from and regular string completion in `@module`. https://github.com/rescript-lang/rescript-vscode/pull/918
20+
- Make from completion trigger for expr hole so we get a nice experience when completing {from: <com>} in `@module`. https://github.com/rescript-lang/rescript-vscode/pull/918
1921

2022
## 1.38.0
2123

Diff for: analysis/src/CompletionBackEnd.ml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1882,8 +1882,9 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover completable =
18821882
then None
18831883
else
18841884
match Filename.extension fileName with
1885-
| ".js" | ".mjs" -> Some ("./" ^ fileName)
1886-
| _ -> None)
1885+
| ".res" | ".resi" | "" -> None
1886+
| _ -> Some ("./" ^ fileName))
1887+
|> List.sort String.compare
18871888
with _ ->
18881889
if debug then print_endline "Could not read relative directory";
18891890
[]

Diff for: analysis/src/CompletionFrontEnd.ml

+21-11
Original file line numberDiff line numberDiff line change
@@ -832,25 +832,35 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
832832
Pstr_eval
833833
( {
834834
pexp_desc =
835-
Pexp_record
836-
( ( {txt = Lident "from"},
837-
{
838-
pexp_loc;
839-
pexp_desc =
840-
Pexp_constant (Pconst_string (s, _));
841-
} )
842-
:: _,
843-
_ );
835+
Pexp_record (({txt = Lident "from"}, fromExpr) :: _, _);
844836
},
845837
_ );
846838
};
847839
]
848-
when locHasCursor pexp_loc ->
840+
when locHasCursor fromExpr.pexp_loc
841+
|| locIsEmpty fromExpr.pexp_loc
842+
&& CompletionExpressions.isExprHole fromExpr -> (
849843
if Debug.verbose () then
850844
print_endline
851845
"[decoratorCompletion] Found @module with import attributes and \
852846
cursor on \"from\"";
853-
setResult (Completable.CdecoratorPayload (Module s))
847+
match
848+
( locHasCursor fromExpr.pexp_loc,
849+
locIsEmpty fromExpr.pexp_loc,
850+
CompletionExpressions.isExprHole fromExpr,
851+
fromExpr )
852+
with
853+
| true, _, _, {pexp_desc = Pexp_constant (Pconst_string (s, _))} ->
854+
if Debug.verbose () then
855+
print_endline
856+
"[decoratorCompletion] @module `from` payload was string";
857+
setResult (Completable.CdecoratorPayload (Module s))
858+
| false, true, true, _ ->
859+
if Debug.verbose () then
860+
print_endline
861+
"[decoratorCompletion] @module `from` payload was expr hole";
862+
setResult (Completable.CdecoratorPayload (Module ""))
863+
| _ -> ())
854864
| PStr [{pstr_desc = Pstr_eval (expr, _)}] -> (
855865
if Debug.verbose () then
856866
print_endline

Diff for: analysis/tests/src/CompletionAttributes.res

+3
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@
3131
// @module({from: "" }) external doStuff: t = "default"
3232
// ^com
3333

34+
// @module({from: }) external doStuff: t = "default"
35+
// ^com
36+

Diff for: analysis/tests/src/expected/CompletionAttributes.res.txt

+73
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,24 @@ Resolved opens 1 pervasives
2424
"tags": [],
2525
"detail": "Package",
2626
"documentation": null
27+
}, {
28+
"label": "./TableclothMap.ml",
29+
"kind": 4,
30+
"tags": [],
31+
"detail": "Local file",
32+
"documentation": null
33+
}, {
34+
"label": "./TableclothMap.mli",
35+
"kind": 4,
36+
"tags": [],
37+
"detail": "Local file",
38+
"documentation": null
39+
}, {
40+
"label": "./test.json",
41+
"kind": 4,
42+
"tags": [],
43+
"detail": "Local file",
44+
"documentation": null
2745
}, {
2846
"label": "./tst.js",
2947
"kind": 4,
@@ -185,6 +203,61 @@ Resolved opens 1 pervasives
185203
"tags": [],
186204
"detail": "Package",
187205
"documentation": null
206+
}, {
207+
"label": "./TableclothMap.ml",
208+
"kind": 4,
209+
"tags": [],
210+
"detail": "Local file",
211+
"documentation": null
212+
}, {
213+
"label": "./TableclothMap.mli",
214+
"kind": 4,
215+
"tags": [],
216+
"detail": "Local file",
217+
"documentation": null
218+
}, {
219+
"label": "./test.json",
220+
"kind": 4,
221+
"tags": [],
222+
"detail": "Local file",
223+
"documentation": null
224+
}, {
225+
"label": "./tst.js",
226+
"kind": 4,
227+
"tags": [],
228+
"detail": "Local file",
229+
"documentation": null
230+
}]
231+
232+
Complete src/CompletionAttributes.res 33:17
233+
XXX Not found!
234+
Completable: CdecoratorPayload(module=)
235+
Package opens Pervasives.JsxModules.place holder
236+
Resolved opens 1 pervasives
237+
[{
238+
"label": "@rescript/react",
239+
"kind": 4,
240+
"tags": [],
241+
"detail": "Package",
242+
"documentation": null
243+
}, {
244+
"label": "./TableclothMap.ml",
245+
"kind": 4,
246+
"tags": [],
247+
"detail": "Local file",
248+
"documentation": null
249+
}, {
250+
"label": "./TableclothMap.mli",
251+
"kind": 4,
252+
"tags": [],
253+
"detail": "Local file",
254+
"documentation": null
255+
}, {
256+
"label": "./test.json",
257+
"kind": 4,
258+
"tags": [],
259+
"detail": "Local file",
260+
"documentation": null
188261
}, {
189262
"label": "./tst.js",
190263
"kind": 4,

Diff for: analysis/tests/src/test.json

Whitespace-only changes.

0 commit comments

Comments
 (0)