Skip to content

Commit

Permalink
fix(snippet): Fix special-case of parsing text if not placeholder or …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
bryphe authored Feb 12, 2021
1 parent b72cb32 commit 80c7dad
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES_CURRENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions src/Core/Snippet/Snippet.re
Original file line number Diff line number Diff line change
Expand Up @@ -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 }")]]);
};
});
1 change: 1 addition & 0 deletions src/Core/Snippet/Snippet_parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down

0 comments on commit 80c7dad

Please sign in to comment.