microsoft / microsoft/language-server-protocol

Allow top level `text` to not escape `}` when it is not part of the `${}`

Open
#2,033 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

clarification
Dominant language
TypeScript
Stars
13k
Forks
1k
Avg merge
6d 1h
Merged PRs (30d)
10

Description

Currently snippet grammar states the following:

any         ::= tabstop | placeholder | choice | variable | text
...
text        ::= ([^$}\] | '\$' | '\}' | '\\')*

This means that } should be escaped even when not used as closing part of ${}. For example, in this snippet string: hello {world\\}.

However, it introduces friction for languages which use {} (which are many, I'd say).

VS Code also seems to allow not escaping } in the top level context (here is one example).


Proposal: allow top level text to not escape }. I believe this can be encapsulated in the following change to the grammar:

Patch for changing grammar
diff --git a/_specifications/lsp/3.18/language/completion.md b/_specifications/lsp/3.18/language/completion.md
index 68fe55b..adf45b8 100644
--- a/_specifications/lsp/3.18/language/completion.md
+++ b/_specifications/lsp/3.18/language/completion.md
@@ -819,8 +819,8 @@ Below is the grammar for snippets in EBNF ([extended Backus-Naur form, XML varia
 any         ::= tabstop | placeholder | choice | variable | text
 tabstop     ::= '$' int | '${' int '}'
-placeholder ::= '${' int ':' any '}'
+placeholder ::= '${' int ':' (tabstop | placeholder | choice | variable | innertext) '}'
 choice      ::= '${' int '|' choicetext (',' choicetext)* '|}'
 variable    ::= '$' var | '${' var }'
-                | '${' var ':' any '}'
+                | '${' var ':' (tabstop | placeholder | choice | variable | innertext) '}'
                 | '${' var '/' regex '/' (format | formattext)* '/' options '}'
 format      ::= '$' int | '${' int '}'
@@ -838,10 +838,11 @@ options     ::= Regular Expression option (ctor-options)
 var         ::= [_a-zA-Z] [_a-zA-Z0-9]*
 int         ::= [0-9]+
-text        ::= ([^$}\] | '\$' | '\}' | '\\')*
+text        ::= ([^$\] | '\$' | '\\')*
+innertext   ::= ([^$}\] | '\$' | '\}' | '\\')*
 choicetext  ::= ([^,|\] | '\,' | '\|' | '\\')*
 formattext  ::= ([^$/\] | '\$' | '\/' | '\\')*
-ifOnly      ::= text
+ifOnly      ::= innertext
 if          ::= ([^:\] | '\:' | '\\')*
-else        ::= text
+else        ::= innertext

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in _specifications/lsp/3.18/language/completion.md at the snippet grammar section and review the proposed EBNF changes. Confirm the top-level text and nested placeholder or variable rules match the proposal, then verify the specification clearly permits an unescaped } outside ${}.

Written by the indexing model from the issue text.

Assessment

Domain
documentation
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.