Skip to content

Commit

Permalink
always parse the entire snippet
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pascalkuthe authored and archseer committed Mar 16, 2023
1 parent 7bf168d commit bbf4800
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions helix-lsp/src/snippet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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!(
Expand Down

0 comments on commit bbf4800

Please sign in to comment.