@@ -92,12 +92,19 @@ newtype Snippet = Snippet [SnippetAny]
9292instance IsString Snippet where
9393 fromString = snippetText . T. pack
9494
95+ -- | @SnippetAny@ can be used to construct sanitized snippets. See the LSP
96+ -- spec for more details.
9597data SnippetAny
9698 = SText Text
97- | STabStop Int
98- | SPlaceholder Int SnippetAny
99+ -- ^ Literal text
100+ | STabStop Int (Maybe SnippetAny )
101+ -- ^ Creates a tab stop, i.e. parts of the snippet that are meant to be
102+ -- filled in by the user and that can be jumped between using the tab key.
103+ -- The optional field can be used to provide a placeholder value.
99104 | SChoice Int (NonEmpty Text )
105+ -- ^ Presents a choice between the provided values to the user
100106 | SVariable Text (Maybe SnippetAny )
107+ -- ^ Snippet variable. See the spec for possible values
101108 deriving (Eq , Show )
102109
103110snippetText :: Text -> Snippet
@@ -114,10 +121,9 @@ snippetToText (Snippet l) = foldMap (snippetAnyToText False) l
114121 where
115122 snippetAnyToText isNested = \ case
116123 SText t -> sanitizeText isNested t
117- STabStop i -> " ${" <> T. pack (show i) <> " }"
118- SPlaceholder i s -> " ${" <> T. pack (show i) <> " :" <> snippetAnyToText True s <> " }"
124+ STabStop i ph -> " ${" <> T. pack (show i) <> foldMap (\ p -> " :" <> snippetAnyToText True p) ph <> " }"
119125 SChoice i (c :| cs) -> " ${" <> T. pack (show i) <> " |" <> c <> foldMap (" ," <> ) cs <> " }"
120- SVariable n md -> " ${" <> n <> maybe mempty (\ x -> " :" <> snippetAnyToText True x) md <> " }"
126+ SVariable n md -> " ${" <> n <> foldMap (\ x -> " :" <> snippetAnyToText True x) md <> " }"
121127 sanitizeText isNested = T. foldl' (sanitizeChar isNested) mempty
122128 sanitizeChar isNested t = (t <> ) . \ case
123129 ' $' -> " \\ $"
0 commit comments