From d8689fb03f6b81aa2fbe317a6f1186a0536c3497 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Tue, 23 Nov 2021 13:36:46 +0100 Subject: [PATCH] Fix issue with JSX autocompletion not working after `foo=#variant`. Fixes https://github.com/rescript-lang/rescript-vscode/issues/313 --- CHANGELOG.md | 1 + analysis/src/PartialParser.ml | 7 +++++-- analysis/tests/src/Jsx.res | 4 ++++ analysis/tests/src/expected/Jsx.res.txt | 18 ++++++++++++++++++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 869a1671b..c2b8bec39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Fix issue where values for autocomplete were pulled from implementations instead of interfaces. - Add autocompletion for object access of the form foo["bar"]. - Fix issue with autocomplete then punned props are used in JSX. E.g. ``. +- Fix issue with JSX autocompletion not working after `foo=#variant`. ## 1.1.3 diff --git a/analysis/src/PartialParser.ml b/analysis/src/PartialParser.ml index 74a7ac8f9..e7cb8da88 100644 --- a/analysis/src/PartialParser.ml +++ b/analysis/src/PartialParser.ml @@ -107,7 +107,7 @@ let skipOptVariantExtension text i = Find JSX context ctx for component M to autocomplete id (already parsed) as a prop. ctx ::= | [...] + atomicExpr ::= id | #id | "abc" | 'a' | 42 | `...` | optVariant {...} | optVariant (...) | <...> | [...] optVariant ::= id | #id | %id | _nothing_ *) let findJsxContext text offset = @@ -143,7 +143,10 @@ let findJsxContext text offset = match ident.[0] with | ('a' .. 'z' | 'A' .. 'Z') when i1 >= 1 && text.[i1 - 1] = '<' -> Some (ident, identsSeen) - | _ -> beforeIdent ~ident identsSeen (i1 - 1) + | _ -> + if i1 >= 1 && text.[i1 - 1] = '#' then + beforeValue identsSeen (i1 - 2) + else beforeIdent ~ident identsSeen (i1 - 1) else None else None and beforeIdent ~ident identsSeen i = diff --git a/analysis/tests/src/Jsx.res b/analysis/tests/src/Jsx.res index f9438a22a..da2a1293b 100644 --- a/analysis/tests/src/Jsx.res +++ b/analysis/tests/src/Jsx.res @@ -54,3 +54,7 @@ let _ = (Ext.make, Ext.makeProps) //^com