diff options
author | Pascal Kuthe | 2023-03-13 18:22:39 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2023-03-16 06:46:08 +0000 |
commit | bbf480007d87631ef7b7f93cef170ec1af961406 (patch) | |
tree | 8f071c99f7c56a9ce002471ce80aa18a7798df43 /helix-lsp | |
parent | 7bf168dce0da10d60507589f9ffce8f73657e1e8 (diff) |
always parse the entire snippet
Previously any remaining text of the snippet that could not be parsed
was ignored. This commit adds the `parse_all` function which reports
an error if any text was not consumed by the parser
Diffstat (limited to 'helix-lsp')
-rw-r--r-- | helix-lsp/src/snippet.rs | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/helix-lsp/src/snippet.rs b/helix-lsp/src/snippet.rs index 4713ad8b..77f44d4e 100644 --- a/helix-lsp/src/snippet.rs +++ b/helix-lsp/src/snippet.rs @@ -384,9 +384,14 @@ mod parser { } pub fn parse(s: &str) -> Result<Snippet, &str> { - snippet().parse(s).map(|(_input, elements)| elements) + snippet().parse(s).and_then(|(remainder, snippet)| { + if remainder.is_empty() { + Ok(snippet) + } else { + Err(remainder) + } + }) } - #[cfg(test)] mod test { use super::SnippetElement::*; @@ -415,6 +420,28 @@ mod parser { } #[test] + fn parse_unterminated_placeholder_error() { + assert_eq!(Err("${1:)"), parse("match(${1:)")) + } + + #[test] + fn parse_empty_placeholder() { + assert_eq!( + Ok(Snippet { + elements: vec![ + Text("match(".into()), + Placeholder { + tabstop: 1, + value: vec![], + }, + Text(")".into()) + ] + }), + parse("match(${1:})") + ) + } + + #[test] fn parse_placeholders_in_statement() { assert_eq!( Ok(Snippet { |