diff options
| author | bors <bors@rust-lang.org> | 2022-05-06 11:12:29 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-05-06 11:12:29 +0000 |
| commit | 57c5447f904c1edf45acd35dd9e606c98ef9a35b (patch) | |
| tree | f90e627cf97bf788b80d15f41695a84e752c4c7b | |
| parent | db1434b34f0cf11c54207d2bcf420547fb319a25 (diff) | |
| parent | 582f99d293359b6276813c4433db36c6e790152e (diff) | |
| download | rust-57c5447f904c1edf45acd35dd9e606c98ef9a35b.tar.gz rust-57c5447f904c1edf45acd35dd9e606c98ef9a35b.zip | |
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
| -rw-r--r-- | crates/ide-completion/src/item.rs | 2 | ||||
| -rw-r--r-- | crates/ide-completion/src/tests.rs | 12 |
2 files changed, 12 insertions, 2 deletions
diff --git a/crates/ide-completion/src/item.rs b/crates/ide-completion/src/item.rs index fe1ad2bf82d..140e5b600b1 100644 --- a/crates/ide-completion/src/item.rs +++ b/crates/ide-completion/src/item.rs @@ -26,7 +26,7 @@ pub struct CompletionItem { /// It should be used primarily for UI, but we also use this to convert /// generic TextEdit into LSP's completion edit (see conv.rs). /// - /// `source_range` must contain the completion offset. `insert_text` should + /// `source_range` must contain the completion offset. `text_edit` should /// start with what `source_range` points to, or VSCode will filter out the /// completion silently. source_range: TextRange, diff --git a/crates/ide-completion/src/tests.rs b/crates/ide-completion/src/tests.rs index 8d9d1bc4b95..72b7a5584aa 100644 --- a/crates/ide-completion/src/tests.rs +++ b/crates/ide-completion/src/tests.rs @@ -214,7 +214,17 @@ pub(crate) fn check_pattern_is_applicable(code: &str, check: impl FnOnce(SyntaxE pub(crate) fn get_all_items(config: CompletionConfig, code: &str) -> Vec<CompletionItem> { let (db, position) = position(code); - crate::completions(&db, &config, position).map_or_else(Vec::default, Into::into) + let res = crate::completions(&db, &config, position).map_or_else(Vec::default, Into::into); + // validate + res.iter().for_each(|it| { + let sr = it.source_range(); + assert!( + sr.contains_inclusive(position.offset), + "source range {sr:?} does not contain the offset {:?} of the completion request: {it:?}", + position.offset + ); + }); + res } #[test] |
