From 80c7dad897e04f580fdcc42ed45589f84eb60bc4 Mon Sep 17 00:00:00 2001 From: Bryan Phelps Date: Fri, 12 Feb 2021 14:14:19 -0800 Subject: [PATCH] fix(snippet): Fix special-case of parsing text if not placeholder or variable (#3137) __Issue:__ In testing snippet extensions, a particular snippet was failing to expand for the [React - JavaScript snippets extension](https://open-vsx.org/extension/tomi/xajssnippets) - the `_mu` snippet. __Defect:__ There is a string in that snippet of `${ value }` - we were trying to parse that as a placeholder or variable, but it was failing. It should actually be a text value. __Fix:__ Add a case in the snippet parser to handle falling back if the placeholder-like item cannot be reoslved. --- CHANGES_CURRENT.md | 1 + src/Core/Snippet/Snippet.re | 6 ++++++ src/Core/Snippet/Snippet_parser.mly | 1 + 3 files changed, 8 insertions(+) diff --git a/CHANGES_CURRENT.md b/CHANGES_CURRENT.md index 80d1334bbd..74a06c5f99 100644 --- a/CHANGES_CURRENT.md +++ b/CHANGES_CURRENT.md @@ -41,6 +41,7 @@ - #3133 - Completion: Implement shift+escape to close all popups w/o switching modes (fixes #3120) - #3134 - Snippets: Only show snippet visualizer for active editor - #3135 - Snippets: Convert choices to placeholders +- #3137 - Snippets: Fix error parsing some snippets in the React TS/JS extensions ### Performance diff --git a/src/Core/Snippet/Snippet.re b/src/Core/Snippet/Snippet.re index f80be01c5f..813446d9ee 100644 --- a/src/Core/Snippet/Snippet.re +++ b/src/Core/Snippet/Snippet.re @@ -147,4 +147,10 @@ let%test_module "parse" = let%test "colon in snippet" = { parse("a:b") == Ok([[Text("a:b")]]); }; + + // Test case to exercise a failure to parse snippets like: + // https://github.com/Tom-xacademy/xa-js-snippets/blob/39bc330b9167635d44b0573e06cc1e10ccf8e891/snippets/snippets.json#L104 + let%test "non-placeholder special case" = { + parse("${ data }") == Ok([[Text("${ data }")]]); + }; }); diff --git a/src/Core/Snippet/Snippet_parser.mly b/src/Core/Snippet/Snippet_parser.mly index ef1c6d1f9d..763279268e 100644 --- a/src/Core/Snippet/Snippet_parser.mly +++ b/src/Core/Snippet/Snippet_parser.mly @@ -36,6 +36,7 @@ expr_nested: additionalChoices }) } | DOLLAR; var = VARIABLE; { Variable({name = var; default = None }) } | DOLLAR; LB; var = VARIABLE; COLON; default = string; RB { Variable({name = var; default = Some(default) }) } +| DOLLAR; LB; text = TEXT; { Text("${" ^ text) } | text = TEXT { Text(text) } | numberAsText = NUMBER { Text(string_of_int(numberAsText)) } | variableAsText = VARIABLE { Snippet_internal.Text(variableAsText) }