mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
perf: Segregate syntax and semantic diagnostics
This commit is contained in:
parent
aa00ddcf65
commit
eea1e9b21f
9 changed files with 255 additions and 146 deletions
|
@ -59,10 +59,14 @@ fn check_nth_fix_with_config(
|
|||
let after = trim_indent(ra_fixture_after);
|
||||
|
||||
let (db, file_position) = RootDatabase::with_position(ra_fixture_before);
|
||||
let diagnostic =
|
||||
super::diagnostics(&db, &config, &AssistResolveStrategy::All, file_position.file_id.into())
|
||||
.pop()
|
||||
.expect("no diagnostics");
|
||||
let diagnostic = super::full_diagnostics(
|
||||
&db,
|
||||
&config,
|
||||
&AssistResolveStrategy::All,
|
||||
file_position.file_id.into(),
|
||||
)
|
||||
.pop()
|
||||
.expect("no diagnostics");
|
||||
let fix = &diagnostic
|
||||
.fixes
|
||||
.unwrap_or_else(|| panic!("{:?} diagnostic misses fixes", diagnostic.code))[nth];
|
||||
|
@ -102,37 +106,39 @@ pub(crate) fn check_has_fix(ra_fixture_before: &str, ra_fixture_after: &str) {
|
|||
let (db, file_position) = RootDatabase::with_position(ra_fixture_before);
|
||||
let mut conf = DiagnosticsConfig::test_sample();
|
||||
conf.expr_fill_default = ExprFillDefaultMode::Default;
|
||||
let fix =
|
||||
super::diagnostics(&db, &conf, &AssistResolveStrategy::All, file_position.file_id.into())
|
||||
.into_iter()
|
||||
.find(|d| {
|
||||
d.fixes
|
||||
.as_ref()
|
||||
.and_then(|fixes| {
|
||||
fixes.iter().find(|fix| {
|
||||
if !fix.target.contains_inclusive(file_position.offset) {
|
||||
return false;
|
||||
}
|
||||
let actual = {
|
||||
let source_change = fix.source_change.as_ref().unwrap();
|
||||
let file_id =
|
||||
*source_change.source_file_edits.keys().next().unwrap();
|
||||
let mut actual = db.file_text(file_id).to_string();
|
||||
let fix = super::full_diagnostics(
|
||||
&db,
|
||||
&conf,
|
||||
&AssistResolveStrategy::All,
|
||||
file_position.file_id.into(),
|
||||
)
|
||||
.into_iter()
|
||||
.find(|d| {
|
||||
d.fixes
|
||||
.as_ref()
|
||||
.and_then(|fixes| {
|
||||
fixes.iter().find(|fix| {
|
||||
if !fix.target.contains_inclusive(file_position.offset) {
|
||||
return false;
|
||||
}
|
||||
let actual = {
|
||||
let source_change = fix.source_change.as_ref().unwrap();
|
||||
let file_id = *source_change.source_file_edits.keys().next().unwrap();
|
||||
let mut actual = db.file_text(file_id).to_string();
|
||||
|
||||
for (edit, snippet_edit) in source_change.source_file_edits.values()
|
||||
{
|
||||
edit.apply(&mut actual);
|
||||
if let Some(snippet_edit) = snippet_edit {
|
||||
snippet_edit.apply(&mut actual);
|
||||
}
|
||||
}
|
||||
actual
|
||||
};
|
||||
after == actual
|
||||
})
|
||||
})
|
||||
.is_some()
|
||||
});
|
||||
for (edit, snippet_edit) in source_change.source_file_edits.values() {
|
||||
edit.apply(&mut actual);
|
||||
if let Some(snippet_edit) = snippet_edit {
|
||||
snippet_edit.apply(&mut actual);
|
||||
}
|
||||
}
|
||||
actual
|
||||
};
|
||||
after == actual
|
||||
})
|
||||
})
|
||||
.is_some()
|
||||
});
|
||||
assert!(fix.is_some(), "no diagnostic with desired fix");
|
||||
}
|
||||
|
||||
|
@ -144,38 +150,40 @@ pub(crate) fn check_has_single_fix(ra_fixture_before: &str, ra_fixture_after: &s
|
|||
let mut conf = DiagnosticsConfig::test_sample();
|
||||
conf.expr_fill_default = ExprFillDefaultMode::Default;
|
||||
let mut n_fixes = 0;
|
||||
let fix =
|
||||
super::diagnostics(&db, &conf, &AssistResolveStrategy::All, file_position.file_id.into())
|
||||
.into_iter()
|
||||
.find(|d| {
|
||||
d.fixes
|
||||
.as_ref()
|
||||
.and_then(|fixes| {
|
||||
n_fixes += fixes.len();
|
||||
fixes.iter().find(|fix| {
|
||||
if !fix.target.contains_inclusive(file_position.offset) {
|
||||
return false;
|
||||
}
|
||||
let actual = {
|
||||
let source_change = fix.source_change.as_ref().unwrap();
|
||||
let file_id =
|
||||
*source_change.source_file_edits.keys().next().unwrap();
|
||||
let mut actual = db.file_text(file_id).to_string();
|
||||
let fix = super::full_diagnostics(
|
||||
&db,
|
||||
&conf,
|
||||
&AssistResolveStrategy::All,
|
||||
file_position.file_id.into(),
|
||||
)
|
||||
.into_iter()
|
||||
.find(|d| {
|
||||
d.fixes
|
||||
.as_ref()
|
||||
.and_then(|fixes| {
|
||||
n_fixes += fixes.len();
|
||||
fixes.iter().find(|fix| {
|
||||
if !fix.target.contains_inclusive(file_position.offset) {
|
||||
return false;
|
||||
}
|
||||
let actual = {
|
||||
let source_change = fix.source_change.as_ref().unwrap();
|
||||
let file_id = *source_change.source_file_edits.keys().next().unwrap();
|
||||
let mut actual = db.file_text(file_id).to_string();
|
||||
|
||||
for (edit, snippet_edit) in source_change.source_file_edits.values()
|
||||
{
|
||||
edit.apply(&mut actual);
|
||||
if let Some(snippet_edit) = snippet_edit {
|
||||
snippet_edit.apply(&mut actual);
|
||||
}
|
||||
}
|
||||
actual
|
||||
};
|
||||
after == actual
|
||||
})
|
||||
})
|
||||
.is_some()
|
||||
});
|
||||
for (edit, snippet_edit) in source_change.source_file_edits.values() {
|
||||
edit.apply(&mut actual);
|
||||
if let Some(snippet_edit) = snippet_edit {
|
||||
snippet_edit.apply(&mut actual);
|
||||
}
|
||||
}
|
||||
actual
|
||||
};
|
||||
after == actual
|
||||
})
|
||||
})
|
||||
.is_some()
|
||||
});
|
||||
assert!(fix.is_some(), "no diagnostic with desired fix");
|
||||
assert!(n_fixes == 1, "Too many fixes suggested");
|
||||
}
|
||||
|
@ -183,7 +191,7 @@ pub(crate) fn check_has_single_fix(ra_fixture_before: &str, ra_fixture_after: &s
|
|||
/// Checks that there's a diagnostic *without* fix at `$0`.
|
||||
pub(crate) fn check_no_fix(ra_fixture: &str) {
|
||||
let (db, file_position) = RootDatabase::with_position(ra_fixture);
|
||||
let diagnostic = super::diagnostics(
|
||||
let diagnostic = super::full_diagnostics(
|
||||
&db,
|
||||
&DiagnosticsConfig::test_sample(),
|
||||
&AssistResolveStrategy::All,
|
||||
|
@ -215,7 +223,7 @@ pub(crate) fn check_diagnostics_with_config(config: DiagnosticsConfig, ra_fixtur
|
|||
.iter()
|
||||
.copied()
|
||||
.flat_map(|file_id| {
|
||||
super::diagnostics(&db, &config, &AssistResolveStrategy::All, file_id.into())
|
||||
super::full_diagnostics(&db, &config, &AssistResolveStrategy::All, file_id.into())
|
||||
.into_iter()
|
||||
.map(|d| {
|
||||
let mut annotation = String::new();
|
||||
|
@ -277,10 +285,10 @@ fn test_disabled_diagnostics() {
|
|||
let (db, file_id) = RootDatabase::with_single_file(r#"mod foo;"#);
|
||||
let file_id = file_id.into();
|
||||
|
||||
let diagnostics = super::diagnostics(&db, &config, &AssistResolveStrategy::All, file_id);
|
||||
let diagnostics = super::full_diagnostics(&db, &config, &AssistResolveStrategy::All, file_id);
|
||||
assert!(diagnostics.is_empty());
|
||||
|
||||
let diagnostics = super::diagnostics(
|
||||
let diagnostics = super::full_diagnostics(
|
||||
&db,
|
||||
&DiagnosticsConfig::test_sample(),
|
||||
&AssistResolveStrategy::All,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue