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().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::*; @@ -414,6 +419,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!(