remove repeat replace logic in parser
This commit is contained in:
parent
621dea1819
commit
76af408f3f
@ -554,7 +554,7 @@ fn replace_substring(rope: Rope, substring: &str) -> Rope {
|
||||
pub fn recovery_sv_parse(
|
||||
doc: &Rope,
|
||||
uri: &Url,
|
||||
last_change_range: &Option<Range>,
|
||||
_last_change_range: &Option<Range>,
|
||||
inc_paths: &[PathBuf],
|
||||
allow_incomplete: bool,
|
||||
) -> Option<(SyntaxTree, sv_parser::common::ParseResult)> {
|
||||
@ -562,26 +562,17 @@ pub fn recovery_sv_parse(
|
||||
let mut i = 0;
|
||||
let mut includes: Vec<PathBuf> = inc_paths.to_vec();
|
||||
let mut defines = HashMap::new();
|
||||
let mut reverted_change = false;
|
||||
let mut text = doc.clone();
|
||||
|
||||
// TODO: find how to fix it
|
||||
// remove `reset all to avoid parse error
|
||||
text = replace_substring(text, "`resetall");
|
||||
|
||||
let recover_text_by_byte_idx = |byte_idx: usize, reverted_change: &mut bool, text: &mut Rope| {
|
||||
let mut line_start = text.byte_to_line(byte_idx);
|
||||
let mut line_end = text.byte_to_line(byte_idx) + 1;
|
||||
let recover_text_by_byte_idx = |byte_idx: usize, text: &mut Rope| {
|
||||
let line_start = text.byte_to_line(byte_idx);
|
||||
let line_end = text.byte_to_line(byte_idx) + 1;
|
||||
|
||||
// println!("byte: {byte_idx}, line_start: {line_start}, line_end: {line_end}");
|
||||
|
||||
if !(*reverted_change) {
|
||||
if let Some(range) = last_change_range {
|
||||
line_start = range.start.line as usize;
|
||||
line_end = range.end.line as usize + 1;
|
||||
*reverted_change = true;
|
||||
}
|
||||
}
|
||||
// info!("byte: {byte_idx}, line_start: {line_start}, line_end: {line_end}");
|
||||
|
||||
// 把 last_change 处的地方替换成空格
|
||||
for line_idx in line_start .. line_end {
|
||||
@ -614,7 +605,7 @@ pub fn recovery_sv_parse(
|
||||
sv_parser::Error::Parse(trace) => match trace {
|
||||
Some((_, byte_idx)) => {
|
||||
// 把出错的地方替换成空格
|
||||
recover_text_by_byte_idx(byte_idx, &mut reverted_change, &mut text);
|
||||
recover_text_by_byte_idx(byte_idx, &mut text);
|
||||
parse_iterations += 1;
|
||||
}
|
||||
None => return None,
|
||||
@ -658,14 +649,14 @@ pub fn recovery_sv_parse(
|
||||
|
||||
// 把出错的地方替换成空格
|
||||
// println!("text {text:?}");
|
||||
recover_text_by_byte_idx(byte_idx, &mut reverted_change, &mut text);
|
||||
recover_text_by_byte_idx(byte_idx, &mut text);
|
||||
parse_iterations += 1;
|
||||
}
|
||||
None => return None
|
||||
}
|
||||
sv_parser::Error::DefineArgNotFound(trace) => match trace {
|
||||
Some((_, start_byte_idx, _)) => {
|
||||
recover_text_by_byte_idx(start_byte_idx, &mut reverted_change, &mut text);
|
||||
recover_text_by_byte_idx(start_byte_idx, &mut text);
|
||||
// recover_text_by_byte_idx(end_byte_idx, &mut reverted_change, &mut text);
|
||||
parse_iterations += 1;
|
||||
}
|
||||
@ -673,7 +664,7 @@ pub fn recovery_sv_parse(
|
||||
}
|
||||
sv_parser::Error::DefineNoArgs(trace) => match trace {
|
||||
Some((_, start_byte_idx, _)) => {
|
||||
recover_text_by_byte_idx(start_byte_idx, &mut reverted_change, &mut text);
|
||||
recover_text_by_byte_idx(start_byte_idx, &mut text);
|
||||
parse_iterations += 1;
|
||||
}
|
||||
_ => return None
|
||||
|
Loading…
x
Reference in New Issue
Block a user