mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
Remove filtered completion list usage in completion tests
This commit is contained in:
parent
142b6dc650
commit
722489e3ff
14 changed files with 1746 additions and 1346 deletions
|
@ -20,6 +20,7 @@ mod record;
|
|||
mod type_pos;
|
||||
mod use_tree;
|
||||
mod visibility;
|
||||
mod flyimport;
|
||||
|
||||
use std::mem;
|
||||
|
||||
|
@ -77,10 +78,18 @@ pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {
|
|||
};
|
||||
|
||||
pub(crate) fn completion_list(ra_fixture: &str) -> String {
|
||||
completion_list_with_config(TEST_CONFIG, ra_fixture)
|
||||
completion_list_with_config(TEST_CONFIG, ra_fixture, true)
|
||||
}
|
||||
|
||||
fn completion_list_with_config(config: CompletionConfig, ra_fixture: &str) -> String {
|
||||
pub(crate) fn completion_list_no_kw(ra_fixture: &str) -> String {
|
||||
completion_list_with_config(TEST_CONFIG, ra_fixture, false)
|
||||
}
|
||||
|
||||
fn completion_list_with_config(
|
||||
config: CompletionConfig,
|
||||
ra_fixture: &str,
|
||||
include_keywords: bool,
|
||||
) -> String {
|
||||
// filter out all but one builtintype completion for smaller test outputs
|
||||
let items = get_all_items(config, ra_fixture);
|
||||
let mut bt_seen = false;
|
||||
|
@ -89,6 +98,8 @@ fn completion_list_with_config(config: CompletionConfig, ra_fixture: &str) -> St
|
|||
.filter(|it| {
|
||||
it.completion_kind != CompletionKind::BuiltinType || !mem::replace(&mut bt_seen, true)
|
||||
})
|
||||
.filter(|it| include_keywords || it.completion_kind != CompletionKind::Keyword)
|
||||
.filter(|it| include_keywords || it.completion_kind != CompletionKind::Snippet)
|
||||
.collect();
|
||||
render_completion_list(items)
|
||||
}
|
||||
|
@ -120,20 +131,6 @@ pub(crate) fn do_completion_with_config(
|
|||
.collect()
|
||||
}
|
||||
|
||||
pub(crate) fn filtered_completion_list(code: &str, kind: CompletionKind) -> String {
|
||||
filtered_completion_list_with_config(TEST_CONFIG, code, kind)
|
||||
}
|
||||
|
||||
pub(crate) fn filtered_completion_list_with_config(
|
||||
config: CompletionConfig,
|
||||
code: &str,
|
||||
kind: CompletionKind,
|
||||
) -> String {
|
||||
let kind_completions: Vec<CompletionItem> =
|
||||
get_all_items(config, code).into_iter().filter(|c| c.completion_kind == kind).collect();
|
||||
render_completion_list(kind_completions)
|
||||
}
|
||||
|
||||
fn render_completion_list(completions: Vec<CompletionItem>) -> String {
|
||||
fn monospace_width(s: &str) -> usize {
|
||||
s.chars().count()
|
||||
|
@ -254,3 +251,37 @@ fn foo() {
|
|||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_completions_in_comments() {
|
||||
cov_mark::check!(no_keyword_completion_in_comments);
|
||||
assert_eq!(
|
||||
completion_list(
|
||||
r#"
|
||||
fn test() {
|
||||
let x = 2; // A comment$0
|
||||
}
|
||||
"#,
|
||||
),
|
||||
String::new(),
|
||||
);
|
||||
assert_eq!(
|
||||
completion_list(
|
||||
r#"
|
||||
/*
|
||||
Some multi-line comment$0
|
||||
*/
|
||||
"#,
|
||||
),
|
||||
String::new(),
|
||||
);
|
||||
assert_eq!(
|
||||
completion_list(
|
||||
r#"
|
||||
/// Some doc comment
|
||||
/// let test$0 = 1
|
||||
"#,
|
||||
),
|
||||
String::new(),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue