diff --git a/CHANGELOG.md b/CHANGELOG.md index a69eef61c..ea65f9f4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: } in `@module`. https://github.com/rescript-lang/rescript-vscode/pull/918 ## 1.38.0 diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index 434589448..941c5b16c 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -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"; [] diff --git a/analysis/src/CompletionFrontEnd.ml b/analysis/src/CompletionFrontEnd.ml index 042aa5006..1c88ed968 100644 --- a/analysis/src/CompletionFrontEnd.ml +++ b/analysis/src/CompletionFrontEnd.ml @@ -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 diff --git a/analysis/tests/src/CompletionAttributes.res b/analysis/tests/src/CompletionAttributes.res index cf9e011f0..7c8809bb5 100644 --- a/analysis/tests/src/CompletionAttributes.res +++ b/analysis/tests/src/CompletionAttributes.res @@ -31,3 +31,6 @@ // @module({from: "" }) external doStuff: t = "default" // ^com +// @module({from: }) external doStuff: t = "default" +// ^com + diff --git a/analysis/tests/src/expected/CompletionAttributes.res.txt b/analysis/tests/src/expected/CompletionAttributes.res.txt index 3c8da2d2e..81fa8b918 100644 --- a/analysis/tests/src/expected/CompletionAttributes.res.txt +++ b/analysis/tests/src/expected/CompletionAttributes.res.txt @@ -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, diff --git a/analysis/tests/src/test.json b/analysis/tests/src/test.json new file mode 100644 index 000000000..e69de29bb