Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
Auto merge of #1255 - Xanewok:you-only-complete-once-fool, r=Xanewok
Browse files Browse the repository at this point in the history
tests: Only request Racer completion once

Closes #1232.

Will run this on Travis a couple of times to see if this doesn't backfire 💥
  • Loading branch information
bors committed Jan 24, 2019
2 parents 6a14ed9 + bd0f2f6 commit 07342b7
Showing 1 changed file with 55 additions and 75 deletions.
130 changes: 55 additions & 75 deletions tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,33 +439,25 @@ fn client_test_complete_self_crate_name() {
let diag = rls.wait_for_diagnostics();
assert!(diag.diagnostics[0].message.contains("expected identifier"));

// Sometimes RLS is not ready immediately for completion
let mut detail = None;
for id in 100..103 {
let response = rls.request::<Completion>(id, CompletionParams {
context: Some(CompletionContext {
trigger_character: Some(":".to_string()),
trigger_kind: CompletionTriggerKind::TriggerCharacter,
}),
position: Position::new(2, 32),
text_document: TextDocumentIdentifier {
uri: Url::from_file_path(p.root().join("library/tests/test.rs")).unwrap(),
}
});
let response = rls.request::<Completion>(100, CompletionParams {
context: Some(CompletionContext {
trigger_character: Some(":".to_string()),
trigger_kind: CompletionTriggerKind::TriggerCharacter,
}),
position: Position::new(2, 32),
text_document: TextDocumentIdentifier {
uri: Url::from_file_path(p.root().join("library/tests/test.rs")).unwrap(),
}
});

let items = match response {
Some(CompletionResponse::Array(items)) => items,
Some(CompletionResponse::List(CompletionList { items, ..})) => items,
_ => Vec::new(),
};
let items = match response {
Some(CompletionResponse::Array(items)) => items,
Some(CompletionResponse::List(CompletionList { items, ..})) => items,
_ => Vec::new(),
};

if let Some(item) = items.get(0) {
detail = item.detail.clone();
break;
}
}
// Make sure we get the completion at least once right
assert_eq!(detail.as_ref().unwrap(), "pub fn function() -> usize");
let item = items.into_iter().nth(0).expect("Racer autocompletion failed");
assert_eq!(item.detail.unwrap(), "pub fn function() -> usize");

rls.shutdown();
}
Expand Down Expand Up @@ -535,33 +527,27 @@ fn client_completion_suggests_arguments_in_statements() {
let diag = rls.wait_for_diagnostics();
assert!(diag.diagnostics[0].message.contains("expected one of"));

// Sometimes RLS is not ready immediately for completion
let mut insert_text = None;
for id in 100..103 {
let response = rls.request::<Completion>(id, CompletionParams {
context: Some(CompletionContext {
trigger_character: Some("f".to_string()),
trigger_kind: CompletionTriggerKind::TriggerCharacter,
}),
position: Position::new(3, 41),
text_document: TextDocumentIdentifier {
uri: Url::from_file_path(p.root().join("library/tests/test.rs")).unwrap(),
}
});
let response = rls.request::<Completion>(100, CompletionParams {
context: Some(CompletionContext {
trigger_character: Some("f".to_string()),
trigger_kind: CompletionTriggerKind::TriggerCharacter,
}),
position: Position::new(3, 41),
text_document: TextDocumentIdentifier {
uri: Url::from_file_path(p.root().join("library/tests/test.rs")).unwrap(),
}
});

let items = match response {
Some(CompletionResponse::Array(items)) => items,
Some(CompletionResponse::List(CompletionList { items, ..})) => items,
_ => Vec::new(),
};
let items = match response {
Some(CompletionResponse::Array(items)) => items,
Some(CompletionResponse::List(CompletionList { items, ..})) => items,
_ => Vec::new(),
};

if let Some(item) = items.get(0) {
insert_text = item.insert_text.clone();
break;
}
}
// Make sure we get the completion at least once right
assert_eq!(insert_text.as_ref().unwrap(), "function()");
let item = items.into_iter().nth(0).expect("Racer autocompletion failed");
assert_eq!(item.insert_text.unwrap(), "function()");

rls.shutdown();
}

#[test]
Expand Down Expand Up @@ -606,33 +592,27 @@ fn client_use_statement_completion_doesnt_suggest_arguments() {
let diag = rls.wait_for_diagnostics();
assert!(diag.diagnostics[0].message.contains("expected identifier"));

// Sometimes RLS is not ready immediately for completion
let mut insert_text = None;
for id in 100..103 {
let response = rls.request::<Completion>(id, CompletionParams {
context: Some(CompletionContext {
trigger_character: Some(":".to_string()),
trigger_kind: CompletionTriggerKind::TriggerCharacter,
}),
position: Position::new(2, 32),
text_document: TextDocumentIdentifier {
uri: Url::from_file_path(p.root().join("library/tests/test.rs")).unwrap(),
}
});
let response = rls.request::<Completion>(100, CompletionParams {
context: Some(CompletionContext {
trigger_character: Some(":".to_string()),
trigger_kind: CompletionTriggerKind::TriggerCharacter,
}),
position: Position::new(2, 32),
text_document: TextDocumentIdentifier {
uri: Url::from_file_path(p.root().join("library/tests/test.rs")).unwrap(),
}
});

let items = match response {
Some(CompletionResponse::Array(items)) => items,
Some(CompletionResponse::List(CompletionList { items, ..})) => items,
_ => Vec::new(),
};
let items = match response {
Some(CompletionResponse::Array(items)) => items,
Some(CompletionResponse::List(CompletionList { items, ..})) => items,
_ => Vec::new(),
};

if let Some(item) = items.get(0) {
insert_text = item.insert_text.clone();
break;
}
}
// Make sure we get the completion at least once right
assert_eq!(insert_text.as_ref().unwrap(), "function");
let item = items.into_iter().nth(0).expect("Racer autocompletion failed");
assert_eq!(item.insert_text.unwrap(), "function");

rls.shutdown();
}

/// Test simulates typing in a dependency wrongly in a couple of ways before finally getting it
Expand Down

0 comments on commit 07342b7

Please sign in to comment.