aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/completion/complete_dot.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-03-17 09:41:30 +0000
committerGitHub <[email protected]>2020-03-17 09:41:30 +0000
commit6aa432d86b7e4fb691600032ebdf6f2301152447 (patch)
treeaa012212c11e43a95547f553b5116922631f9896 /crates/ra_ide/src/completion/complete_dot.rs
parentcf4ae9aa591729dde25a7df3fa5c22ca0fd94145 (diff)
parent6c20d7e979b967eb20207414c0a0bf875bbcb98d (diff)
Merge #3580
3580: More error-resilient MBE expansion r=matklad a=flodiebold This is the beginning of an attempt to make macro-by-example expansion more resilient, so that we still get an expansion even if no rule exactly matches, with the goal to make completion work better in macro calls. The general idea is to make everything return `(T, Option<ExpandError>)` instead of `Result<T, ExpandError>`; and then to try each macro arm in turn, and somehow choose the 'best' matching rule if none matches without errors. Finding that 'best' match isn't done yet; I'm currently counting how many tokens were consumed from the args before an error, but it also needs to take into account whether there were further patterns that had nothing to match. I'll continue this later, but I'm interested whether you think this is the right path, @matklad & @edwin0cheng. Co-authored-by: Florian Diebold <[email protected]> Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_ide/src/completion/complete_dot.rs')
-rw-r--r--crates/ra_ide/src/completion/complete_dot.rs50
1 files changed, 49 insertions, 1 deletions
diff --git a/crates/ra_ide/src/completion/complete_dot.rs b/crates/ra_ide/src/completion/complete_dot.rs
index f07611d88..82ec16913 100644
--- a/crates/ra_ide/src/completion/complete_dot.rs
+++ b/crates/ra_ide/src/completion/complete_dot.rs
@@ -720,7 +720,18 @@ mod tests {
720 } 720 }
721 ", 721 ",
722 ), 722 ),
723 @r###"[]"### 723 @r###"
724 [
725 CompletionItem {
726 label: "the_field",
727 source_range: [156; 156),
728 delete: [156; 156),
729 insert: "the_field",
730 kind: Field,
731 detail: "u32",
732 },
733 ]
734 "###
724 ); 735 );
725 } 736 }
726 737
@@ -752,6 +763,43 @@ mod tests {
752 } 763 }
753 764
754 #[test] 765 #[test]
766 fn macro_expansion_resilient() {
767 assert_debug_snapshot!(
768 do_ref_completion(
769 r"
770 macro_rules! dbg {
771 () => {};
772 ($val:expr) => {
773 match $val { tmp => { tmp } }
774 };
775 // Trailing comma with single argument is ignored
776 ($val:expr,) => { $crate::dbg!($val) };
777 ($($val:expr),+ $(,)?) => {
778 ($($crate::dbg!($val)),+,)
779 };
780 }
781 struct A { the_field: u32 }
782 fn foo(a: A) {
783 dbg!(a.<|>)
784 }
785 ",
786 ),
787 @r###"
788 [
789 CompletionItem {
790 label: "the_field",
791 source_range: [552; 552),
792 delete: [552; 552),
793 insert: "the_field",
794 kind: Field,
795 detail: "u32",
796 },
797 ]
798 "###
799 );
800 }
801
802 #[test]
755 fn test_method_completion_3547() { 803 fn test_method_completion_3547() {
756 assert_debug_snapshot!( 804 assert_debug_snapshot!(
757 do_ref_completion( 805 do_ref_completion(