-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(pglt_workspace): emit scan errors #219
Conversation
/// | ||
/// Scan diagnostics are always **fatal errors**. | ||
#[derive(Clone, Debug, Diagnostic, PartialEq)] | ||
#[diagnostic(category = "syntax", severity = Fatal)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
severity = Fatal
is important here -> its what we use higher up to determine whether the document can be used or not
pub fn from_pg_query_err(err: pg_query::Error, input: &str) -> Vec<Self> { | ||
let err_msg = err.to_string(); | ||
let re = regex::Regex::new(r#"at or near "(.*?)""#).unwrap(); | ||
let mut diagnostics = Vec::new(); | ||
|
||
for captures in re.captures_iter(&err_msg) { | ||
if let Some(matched) = captures.get(1) { | ||
let search_term = matched.as_str(); | ||
for (idx, _) in input.match_indices(search_term) { | ||
let from = idx; | ||
let to = from + search_term.len(); | ||
diagnostics.push(ScanError { | ||
span: Some(TextRange::new( | ||
from.try_into().unwrap(), | ||
to.try_into().unwrap(), | ||
)), | ||
message: MessageAndDescription::from(err_msg.clone()), | ||
}); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we try to find the problematic text in the input to put a range on the diagnostics. this is not safe in any way but I find it nicer to show too many diagnostics where one is for sure valid than none and have the user look through the text.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work :)
emitting scan errors from the lexer. we ignored them before because I thought they never happen. but they do!
also: