Skip to content

Commit 57c5447

Browse files
committed
Auto merge of #12174 - Veykril:completion-rev, r=Veykril
internal: Improve completion tests by checking that the offset is included in the source_range of items
2 parents db1434b + 582f99d commit 57c5447

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

crates/ide-completion/src/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub struct CompletionItem {
2626
/// It should be used primarily for UI, but we also use this to convert
2727
/// generic TextEdit into LSP's completion edit (see conv.rs).
2828
///
29-
/// `source_range` must contain the completion offset. `insert_text` should
29+
/// `source_range` must contain the completion offset. `text_edit` should
3030
/// start with what `source_range` points to, or VSCode will filter out the
3131
/// completion silently.
3232
source_range: TextRange,

crates/ide-completion/src/tests.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,17 @@ pub(crate) fn check_pattern_is_applicable(code: &str, check: impl FnOnce(SyntaxE
214214

215215
pub(crate) fn get_all_items(config: CompletionConfig, code: &str) -> Vec<CompletionItem> {
216216
let (db, position) = position(code);
217-
crate::completions(&db, &config, position).map_or_else(Vec::default, Into::into)
217+
let res = crate::completions(&db, &config, position).map_or_else(Vec::default, Into::into);
218+
// validate
219+
res.iter().for_each(|it| {
220+
let sr = it.source_range();
221+
assert!(
222+
sr.contains_inclusive(position.offset),
223+
"source range {sr:?} does not contain the offset {:?} of the completion request: {it:?}",
224+
position.offset
225+
);
226+
});
227+
res
218228
}
219229

220230
#[test]

0 commit comments

Comments
 (0)