From c143df6de6fb2e3fed7641c2347e40f630590518 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Mon, 26 Apr 2021 17:24:04 +0200 Subject: [PATCH 1/3] Add test for autocomplete of JSX props without test letter. The autocomplete command does not support this yet, as the example shows. https://github.com/rescript-lang/rescript-vscode/issues/147 --- analysis/tests/src/Jsx.res | 3 +++ analysis/tests/src/expected/Jsx.res.txt | 3 +++ 2 files changed, 6 insertions(+) diff --git a/analysis/tests/src/Jsx.res b/analysis/tests/src/Jsx.res index d28ce76ec..11ee036cb 100644 --- a/analysis/tests/src/Jsx.res +++ b/analysis/tests/src/Jsx.res @@ -10,3 +10,6 @@ let d = //^com +// ^com diff --git a/analysis/tests/src/expected/Jsx.res.txt b/analysis/tests/src/expected/Jsx.res.txt index 37be75e4e..58a96f8be 100644 --- a/analysis/tests/src/expected/Jsx.res.txt +++ b/analysis/tests/src/expected/Jsx.res.txt @@ -25,3 +25,6 @@ Complete tests/src/Jsx.res 10:2 "documentation": null }] +Complete tests/src/Jsx.res 13:11 +[] + From 9d543d5757f2c78d84b6c6078b3e71b548c5b68d Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Mon, 26 Apr 2021 18:07:53 +0200 Subject: [PATCH 2/3] Autocomplete of JSX props without first letter. Fixes https://github.com/rescript-lang/rescript-vscode/issues/147 --- analysis/src/PartialParser.ml | 5 +++ analysis/tests/src/Jsx.res | 3 +- analysis/tests/src/expected/Jsx.res.txt | 54 +++++++++++++++++++++++-- 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/analysis/src/PartialParser.ml b/analysis/src/PartialParser.ml index f660da41f..d4a0f89f3 100644 --- a/analysis/src/PartialParser.ml +++ b/analysis/src/PartialParser.ml @@ -175,6 +175,11 @@ let findCompletable text offset = Some (Clabel (funPath, labelPrefix)) | '@' -> Some (Cdecorator (suffix i)) | 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '.' | '_' -> loop (i - 1) + | ' ' when i = offset - 1 -> ( + match findJsxContext text (offset - 1) with + | None -> None + | Some componentName -> + Some (Cjsx (Str.split (Str.regexp_string ".") componentName, ""))) | _ -> if i = offset - 1 then None else Some (mkPath (suffix i)) in if offset > String.length text || offset = 0 then None else loop (offset - 1) diff --git a/analysis/tests/src/Jsx.res b/analysis/tests/src/Jsx.res index 11ee036cb..428b797d3 100644 --- a/analysis/tests/src/Jsx.res +++ b/analysis/tests/src/Jsx.res @@ -11,5 +11,4 @@ let d = //^com -// ^com +//^com let e = ", + "documentation": null + }, { + "label": "second", + "kind": 4, + "tags": [], + "detail": "option", + "documentation": null + }] Complete tests/src/Jsx.res 10:2 [{ @@ -25,6 +49,30 @@ Complete tests/src/Jsx.res 10:2 "documentation": null }] -Complete tests/src/Jsx.res 13:11 -[] +Complete tests/src/Jsx.res 12:2 +[{ + "label": "key", + "kind": 4, + "tags": [], + "detail": "string", + "documentation": null + }, { + "label": "first", + "kind": 4, + "tags": [], + "detail": "string", + "documentation": null + }, { + "label": "fun", + "kind": 4, + "tags": [], + "detail": "option", + "documentation": null + }, { + "label": "second", + "kind": 4, + "tags": [], + "detail": "option", + "documentation": null + }] From e08682faa72868b846323740dcafd2bd724ffefb Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Mon, 26 Apr 2021 18:13:41 +0200 Subject: [PATCH 3/3] Update PartialParser.ml --- analysis/src/PartialParser.ml | 1 + 1 file changed, 1 insertion(+) diff --git a/analysis/src/PartialParser.ml b/analysis/src/PartialParser.ml index d4a0f89f3..002e9b8cb 100644 --- a/analysis/src/PartialParser.ml +++ b/analysis/src/PartialParser.ml @@ -176,6 +176,7 @@ let findCompletable text offset = | '@' -> Some (Cdecorator (suffix i)) | 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '.' | '_' -> loop (i - 1) | ' ' when i = offset - 1 -> ( + (* autocomplete with no id: check if inside JSX *) match findJsxContext text (offset - 1) with | None -> None | Some componentName ->