blob: eb90b5279c463e5589fdbf36e96f8e5971169291 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
//! Runs completion for testing purposes.
use crate::{
completion::{completion_item::CompletionKind, CompletionConfig},
mock_analysis::{analysis_and_position, single_file_with_position},
CompletionItem,
};
pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec<CompletionItem> {
do_completion_with_options(code, kind, &CompletionConfig::default())
}
pub(crate) fn do_completion_with_options(
code: &str,
kind: CompletionKind,
options: &CompletionConfig,
) -> Vec<CompletionItem> {
let (analysis, position) = if code.contains("//-") {
analysis_and_position(code)
} else {
single_file_with_position(code)
};
let completions = analysis.completions(position, options).unwrap().unwrap();
let completion_items: Vec<CompletionItem> = completions.into();
let mut kind_completions: Vec<CompletionItem> =
completion_items.into_iter().filter(|c| c.completion_kind == kind).collect();
kind_completions.sort_by_key(|c| c.label().to_owned());
kind_completions
}
|