-
Couldn't load subscription status.
- Fork 99
Description
Currently the constructor of CompletionItem expects a Maybe Text value in the _insertText field, but that leaves the possibility of outputting malformed snippets as is the case in hls. The LSP specification defines the syntax for snippets and I think there should be a datatype to represent this syntax tree. This would be really useful for sanitization, where we could implement a function that converts this data type to a sanitized string.
What I'm suggesting is to add new data types:
newtype Snippet = Snippet [SnippetAny]
data SnippetAny
= SText Text
| SPlaceholder Int SnippetAny
| ...and then change the type of the _insertText field to Snippet. Then when CompletionItem is serialized to JSON, it applies a function sanitizeSnippet :: Snippet -> Text that converts this Snippet value to a valid LSP snippet. This Snippet type has a rich enough structure to make it easy to implement proper sanitization as outlined in the spec:
With \ (backslash), you can escape $, } and . Within choice elements, the backslash also escapes comma and pipe characters.