From c3026b74a8a9dcbd6cb041dcc184146369d6f624 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Tue, 23 Nov 2021 13:14:59 +0100 Subject: [PATCH 1/2] Fix issue with autocomplete then punned props are used in JSX. E.g. ``. --- CHANGELOG.md | 1 + analysis/src/PartialParser.ml | 4 +-- analysis/tests/src/Jsx.res | 2 ++ analysis/tests/src/expected/Jsx.res.txt | 35 ++++++++++++++++++++----- 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e54de7c53..11f38ba23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - Fix issue in JSX autocomplete when the component is declared external. - Fix jump-to-definition for uncurried calls. - Fix issue where values for autocomplete were pulled from implementations instead of interfaces. +- Fix issue with autocomplete then punned props are used in JSX. E.g. ``. ## 1.1.3 diff --git a/analysis/src/PartialParser.ml b/analysis/src/PartialParser.ml index 6b2035601..faefde0dc 100644 --- a/analysis/src/PartialParser.ml +++ b/analysis/src/PartialParser.ml @@ -109,7 +109,7 @@ let skipOptVariantExtension text i = arg ::= id | id = [?] atomicExpr atomicExpr ::= id | "abc" | 'a' | 42 | `...` | optVariant {...} | optVariant (...) | <...> | [...] optVariant ::= a | A | #a | #A | _nothing_ - *) +*) let findJsxContext text offset = let rec loop identsSeen i = let i = skipWhite text i in @@ -152,7 +152,7 @@ let findJsxContext text offset = match text.[i] with | '?' -> fromEquals identsSeen (i - 1) | '=' -> fromEquals identsSeen i - | _ -> loop identsSeen (i - 1) + | _ -> loop identsSeen i else None and beforeParen identsSeen i = let i = skipWhite text i in diff --git a/analysis/tests/src/Jsx.res b/analysis/tests/src/Jsx.res index df09a09f9..f9438a22a 100644 --- a/analysis/tests/src/Jsx.res +++ b/analysis/tests/src/Jsx.res @@ -52,3 +52,5 @@ module Ext = { let _ = (Ext.make, Ext.makeProps) //^com ", + "documentation": null + }, { + "label": "first", + "kind": 4, + "tags": [], + "detail": "string", + "documentation": null + }, { + "label": "fun", + "kind": 4, + "tags": [], + "detail": "option", + "documentation": null + }, { + "label": "key", + "kind": 4, + "tags": [], + "detail": "string", + "documentation": null + }] + From 4b36f455de1d5cfa35acab91ea7ea04f4ad8b12f Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Tue, 23 Nov 2021 13:16:42 +0100 Subject: [PATCH 2/2] Correctly count the seen ID in case of punning. --- analysis/src/PartialParser.ml | 6 +++--- analysis/tests/src/expected/Jsx.res.txt | 6 ------ 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/analysis/src/PartialParser.ml b/analysis/src/PartialParser.ml index faefde0dc..b900f8453 100644 --- a/analysis/src/PartialParser.ml +++ b/analysis/src/PartialParser.ml @@ -143,16 +143,16 @@ let findJsxContext text offset = match ident.[0] with | ('a' .. 'z' | 'A' .. 'Z') when i1 >= 1 && text.[i1 - 1] = '<' -> Some (ident, identsSeen) - | _ -> beforeIdent identsSeen (i1 - 1) + | _ -> beforeIdent ~ident identsSeen (i1 - 1) else None else None - and beforeIdent identsSeen i = + and beforeIdent ~ident identsSeen i = let i = skipWhite text i in if i > 0 then match text.[i] with | '?' -> fromEquals identsSeen (i - 1) | '=' -> fromEquals identsSeen i - | _ -> loop identsSeen i + | _ -> (* punning *) loop (ident :: identsSeen) i else None and beforeParen identsSeen i = let i = skipWhite text i in diff --git a/analysis/tests/src/expected/Jsx.res.txt b/analysis/tests/src/expected/Jsx.res.txt index 3e6f5f3ee..690fe32f4 100644 --- a/analysis/tests/src/expected/Jsx.res.txt +++ b/analysis/tests/src/expected/Jsx.res.txt @@ -197,12 +197,6 @@ Complete tests/src/Jsx.res 54:2 "tags": [], "detail": "option", "documentation": null - }, { - "label": "first", - "kind": 4, - "tags": [], - "detail": "string", - "documentation": null }, { "label": "fun", "kind": 4,