mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 21:54:42 +00:00
Less panic, more tests
This commit is contained in:
parent
045d7f096f
commit
077c1c3c1f
3 changed files with 62 additions and 11 deletions
|
@ -122,8 +122,8 @@ mod tests {
|
|||
use test_utils::mark;
|
||||
|
||||
use crate::{
|
||||
test_utils::{check_edit, completion_list},
|
||||
CompletionKind,
|
||||
test_utils::{check_edit, check_edit_with_config, completion_list},
|
||||
CompletionConfig, CompletionKind,
|
||||
};
|
||||
|
||||
fn check(ra_fixture: &str, expect: Expect) {
|
||||
|
@ -807,6 +807,43 @@ use dep::{FirstStruct, some_module::{SecondStruct, ThirdStruct}};
|
|||
fn main() {
|
||||
ThirdStruct
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
/// LSP protocol supports separate completion resolve requests to do the heavy computations there.
|
||||
/// This test checks that for a certain resolve capatilities no such operations (autoimport) are done.
|
||||
#[test]
|
||||
fn no_fuzzy_completions_applied_for_certain_resolve_capability() {
|
||||
let mut completion_config = CompletionConfig::default();
|
||||
completion_config
|
||||
.active_resolve_capabilities
|
||||
.insert(crate::CompletionResolveCapability::AdditionalTextEdits);
|
||||
|
||||
check_edit_with_config(
|
||||
completion_config,
|
||||
"ThirdStruct",
|
||||
r#"
|
||||
//- /lib.rs crate:dep
|
||||
pub struct FirstStruct;
|
||||
pub mod some_module {
|
||||
pub struct SecondStruct;
|
||||
pub struct ThirdStruct;
|
||||
}
|
||||
|
||||
//- /main.rs crate:main deps:dep
|
||||
use dep::{FirstStruct, some_module::SecondStruct};
|
||||
|
||||
fn main() {
|
||||
this<|>
|
||||
}
|
||||
"#,
|
||||
r#"
|
||||
use dep::{FirstStruct, some_module::SecondStruct};
|
||||
|
||||
fn main() {
|
||||
ThirdStruct
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -346,13 +346,17 @@ impl Builder {
|
|||
}
|
||||
};
|
||||
|
||||
if !self.resolve_import_lazily {
|
||||
if let Some(import_edit) =
|
||||
self.import_to_add.as_ref().and_then(|import_edit| import_edit.to_text_edit())
|
||||
{
|
||||
text_edit.union(import_edit).expect("Failed to unite import and completion edits");
|
||||
let import_to_add = if self.resolve_import_lazily {
|
||||
self.import_to_add
|
||||
} else {
|
||||
match apply_import_eagerly(self.import_to_add.as_ref(), &mut text_edit) {
|
||||
Ok(()) => self.import_to_add,
|
||||
Err(()) => {
|
||||
log::error!("Failed to apply eager import edit: original edit and import edit intersect");
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
CompletionItem {
|
||||
source_range: self.source_range,
|
||||
|
@ -368,7 +372,7 @@ impl Builder {
|
|||
trigger_call_info: self.trigger_call_info.unwrap_or(false),
|
||||
score: self.score,
|
||||
ref_match: self.ref_match,
|
||||
import_to_add: self.import_to_add,
|
||||
import_to_add,
|
||||
}
|
||||
}
|
||||
pub(crate) fn lookup_by(mut self, lookup: impl Into<String>) -> Builder {
|
||||
|
@ -449,6 +453,16 @@ impl Builder {
|
|||
}
|
||||
}
|
||||
|
||||
fn apply_import_eagerly(
|
||||
import_to_add: Option<&ImportEdit>,
|
||||
original_edit: &mut TextEdit,
|
||||
) -> Result<(), ()> {
|
||||
match import_to_add.and_then(|import_edit| import_edit.to_text_edit()) {
|
||||
Some(import_edit) => original_edit.union(import_edit).map_err(|_| ()),
|
||||
None => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Into<CompletionItem> for Builder {
|
||||
fn into(self) -> CompletionItem {
|
||||
self.build()
|
||||
|
|
|
@ -1626,12 +1626,12 @@ fn fill_resolve_data(
|
|||
let imported_name = import_edit.import_path.segments.clone().pop()?.to_string();
|
||||
|
||||
*resolve_data = Some(
|
||||
serde_json::to_value(CompletionResolveData {
|
||||
to_value(CompletionResolveData {
|
||||
position: position.to_owned(),
|
||||
full_import_path,
|
||||
imported_name,
|
||||
})
|
||||
.expect("Failed to serialize a regular struct with derives"),
|
||||
.unwrap(),
|
||||
)
|
||||
}
|
||||
Some(())
|
||||
|
|
Loading…
Reference in a new issue