Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance module attribute completion some more #918

Merged
merged 3 commits into from
Feb 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@

- Enhance decorator completion. https://github.com/rescript-lang/rescript-vscode/pull/908
- Completion for import attributes in `@module`. https://github.com/rescript-lang/rescript-vscode/pull/913
- 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
- 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

## 1.38.0

5 changes: 3 additions & 2 deletions analysis/src/CompletionBackEnd.ml
Original file line number Diff line number Diff line change
@@ -1882,8 +1882,9 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover completable =
then None
else
match Filename.extension fileName with
| ".js" | ".mjs" -> Some ("./" ^ fileName)
| _ -> None)
| ".res" | ".resi" | "" -> None
| _ -> Some ("./" ^ fileName))
|> List.sort String.compare
with _ ->
if debug then print_endline "Could not read relative directory";
[]
32 changes: 21 additions & 11 deletions analysis/src/CompletionFrontEnd.ml
Original file line number Diff line number Diff line change
@@ -832,25 +832,35 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
Pstr_eval
( {
pexp_desc =
Pexp_record
( ( {txt = Lident "from"},
{
pexp_loc;
pexp_desc =
Pexp_constant (Pconst_string (s, _));
} )
:: _,
_ );
Pexp_record (({txt = Lident "from"}, fromExpr) :: _, _);
},
_ );
};
]
when locHasCursor pexp_loc ->
when locHasCursor fromExpr.pexp_loc
|| locIsEmpty fromExpr.pexp_loc
&& CompletionExpressions.isExprHole fromExpr -> (
if Debug.verbose () then
print_endline
"[decoratorCompletion] Found @module with import attributes and \
cursor on \"from\"";
setResult (Completable.CdecoratorPayload (Module s))
match
( locHasCursor fromExpr.pexp_loc,
locIsEmpty fromExpr.pexp_loc,
CompletionExpressions.isExprHole fromExpr,
fromExpr )
with
| true, _, _, {pexp_desc = Pexp_constant (Pconst_string (s, _))} ->
if Debug.verbose () then
print_endline
"[decoratorCompletion] @module `from` payload was string";
setResult (Completable.CdecoratorPayload (Module s))
| false, true, true, _ ->
if Debug.verbose () then
print_endline
"[decoratorCompletion] @module `from` payload was expr hole";
setResult (Completable.CdecoratorPayload (Module ""))
| _ -> ())
| PStr [{pstr_desc = Pstr_eval (expr, _)}] -> (
if Debug.verbose () then
print_endline
3 changes: 3 additions & 0 deletions analysis/tests/src/CompletionAttributes.res
Original file line number Diff line number Diff line change
@@ -31,3 +31,6 @@
// @module({from: "" }) external doStuff: t = "default"
// ^com

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

73 changes: 73 additions & 0 deletions analysis/tests/src/expected/CompletionAttributes.res.txt
Original file line number Diff line number Diff line change
@@ -24,6 +24,24 @@ Resolved opens 1 pervasives
"tags": [],
"detail": "Package",
"documentation": null
}, {
"label": "./TableclothMap.ml",
"kind": 4,
"tags": [],
"detail": "Local file",
"documentation": null
}, {
"label": "./TableclothMap.mli",
"kind": 4,
"tags": [],
"detail": "Local file",
"documentation": null
}, {
"label": "./test.json",
"kind": 4,
"tags": [],
"detail": "Local file",
"documentation": null
}, {
"label": "./tst.js",
"kind": 4,
@@ -185,6 +203,61 @@ Resolved opens 1 pervasives
"tags": [],
"detail": "Package",
"documentation": null
}, {
"label": "./TableclothMap.ml",
"kind": 4,
"tags": [],
"detail": "Local file",
"documentation": null
}, {
"label": "./TableclothMap.mli",
"kind": 4,
"tags": [],
"detail": "Local file",
"documentation": null
}, {
"label": "./test.json",
"kind": 4,
"tags": [],
"detail": "Local file",
"documentation": null
}, {
"label": "./tst.js",
"kind": 4,
"tags": [],
"detail": "Local file",
"documentation": null
}]

Complete src/CompletionAttributes.res 33:17
XXX Not found!
Completable: CdecoratorPayload(module=)
Package opens Pervasives.JsxModules.place holder
Resolved opens 1 pervasives
[{
"label": "@rescript/react",
"kind": 4,
"tags": [],
"detail": "Package",
"documentation": null
}, {
"label": "./TableclothMap.ml",
"kind": 4,
"tags": [],
"detail": "Local file",
"documentation": null
}, {
"label": "./TableclothMap.mli",
"kind": 4,
"tags": [],
"detail": "Local file",
"documentation": null
}, {
"label": "./test.json",
"kind": 4,
"tags": [],
"detail": "Local file",
"documentation": null
}, {
"label": "./tst.js",
"kind": 4,
Empty file added analysis/tests/src/test.json
Empty file.