diff options
Diffstat (limited to 'crates/ra_cargo_watch/src')
-rw-r--r-- | crates/ra_cargo_watch/src/conv.rs | 17 | ||||
-rw-r--r-- | crates/ra_cargo_watch/src/conv/snapshots/test__snap_macro_compiler_error.snap | 61 | ||||
-rw-r--r-- | crates/ra_cargo_watch/src/conv/test.rs | 229 |
3 files changed, 306 insertions, 1 deletions
diff --git a/crates/ra_cargo_watch/src/conv.rs b/crates/ra_cargo_watch/src/conv.rs index eedfea02b..172f6b07c 100644 --- a/crates/ra_cargo_watch/src/conv.rs +++ b/crates/ra_cargo_watch/src/conv.rs | |||
@@ -46,7 +46,7 @@ fn map_macro_span_to_location( | |||
46 | None | 46 | None |
47 | } | 47 | } |
48 | 48 | ||
49 | /// Converts a Rust span to a LSP location | 49 | /// Converts a Rust span to a LSP location, resolving macro expansion site if neccesary |
50 | fn map_span_to_location(span: &DiagnosticSpan, workspace_root: &PathBuf) -> Location { | 50 | fn map_span_to_location(span: &DiagnosticSpan, workspace_root: &PathBuf) -> Location { |
51 | if span.expansion.is_some() { | 51 | if span.expansion.is_some() { |
52 | let expansion = span.expansion.as_ref().unwrap(); | 52 | let expansion = span.expansion.as_ref().unwrap(); |
@@ -55,6 +55,11 @@ fn map_span_to_location(span: &DiagnosticSpan, workspace_root: &PathBuf) -> Loca | |||
55 | } | 55 | } |
56 | } | 56 | } |
57 | 57 | ||
58 | map_span_to_location_naive(span, workspace_root) | ||
59 | } | ||
60 | |||
61 | /// Converts a Rust span to a LSP location | ||
62 | fn map_span_to_location_naive(span: &DiagnosticSpan, workspace_root: &PathBuf) -> Location { | ||
58 | let mut file_name = workspace_root.clone(); | 63 | let mut file_name = workspace_root.clone(); |
59 | file_name.push(&span.file_name); | 64 | file_name.push(&span.file_name); |
60 | let uri = Url::from_file_path(file_name).unwrap(); | 65 | let uri = Url::from_file_path(file_name).unwrap(); |
@@ -224,6 +229,16 @@ pub(crate) fn map_rust_diagnostic_to_lsp( | |||
224 | let mut related_information = vec![]; | 229 | let mut related_information = vec![]; |
225 | let mut tags = vec![]; | 230 | let mut tags = vec![]; |
226 | 231 | ||
232 | // If error occurs from macro expansion, add related info pointing to | ||
233 | // where the error originated | ||
234 | if !is_from_macro(&primary_span.file_name) && primary_span.expansion.is_some() { | ||
235 | let def_loc = map_span_to_location_naive(&primary_span, workspace_root); | ||
236 | related_information.push(DiagnosticRelatedInformation { | ||
237 | location: def_loc, | ||
238 | message: "Error originated from macro here".to_string(), | ||
239 | }); | ||
240 | } | ||
241 | |||
227 | for secondary_span in rd.spans.iter().filter(|s| !s.is_primary) { | 242 | for secondary_span in rd.spans.iter().filter(|s| !s.is_primary) { |
228 | let related = map_secondary_span_to_related(secondary_span, workspace_root); | 243 | let related = map_secondary_span_to_related(secondary_span, workspace_root); |
229 | if let Some(related) = related { | 244 | if let Some(related) = related { |
diff --git a/crates/ra_cargo_watch/src/conv/snapshots/test__snap_macro_compiler_error.snap b/crates/ra_cargo_watch/src/conv/snapshots/test__snap_macro_compiler_error.snap new file mode 100644 index 000000000..92f7eec05 --- /dev/null +++ b/crates/ra_cargo_watch/src/conv/snapshots/test__snap_macro_compiler_error.snap | |||
@@ -0,0 +1,61 @@ | |||
1 | --- | ||
2 | source: crates/ra_cargo_watch/src/conv/test.rs | ||
3 | expression: diag | ||
4 | --- | ||
5 | MappedRustDiagnostic { | ||
6 | location: Location { | ||
7 | uri: "file:///test/crates/ra_hir_def/src/data.rs", | ||
8 | range: Range { | ||
9 | start: Position { | ||
10 | line: 79, | ||
11 | character: 15, | ||
12 | }, | ||
13 | end: Position { | ||
14 | line: 79, | ||
15 | character: 41, | ||
16 | }, | ||
17 | }, | ||
18 | }, | ||
19 | diagnostic: Diagnostic { | ||
20 | range: Range { | ||
21 | start: Position { | ||
22 | line: 79, | ||
23 | character: 15, | ||
24 | }, | ||
25 | end: Position { | ||
26 | line: 79, | ||
27 | character: 41, | ||
28 | }, | ||
29 | }, | ||
30 | severity: Some( | ||
31 | Error, | ||
32 | ), | ||
33 | code: None, | ||
34 | source: Some( | ||
35 | "rustc", | ||
36 | ), | ||
37 | message: "Please register your known path in the path module", | ||
38 | related_information: Some( | ||
39 | [ | ||
40 | DiagnosticRelatedInformation { | ||
41 | location: Location { | ||
42 | uri: "file:///test/crates/ra_hir_def/src/path.rs", | ||
43 | range: Range { | ||
44 | start: Position { | ||
45 | line: 264, | ||
46 | character: 8, | ||
47 | }, | ||
48 | end: Position { | ||
49 | line: 264, | ||
50 | character: 76, | ||
51 | }, | ||
52 | }, | ||
53 | }, | ||
54 | message: "Error originated from macro here", | ||
55 | }, | ||
56 | ], | ||
57 | ), | ||
58 | tags: None, | ||
59 | }, | ||
60 | suggested_fixes: [], | ||
61 | } | ||
diff --git a/crates/ra_cargo_watch/src/conv/test.rs b/crates/ra_cargo_watch/src/conv/test.rs index 6817245c2..381992388 100644 --- a/crates/ra_cargo_watch/src/conv/test.rs +++ b/crates/ra_cargo_watch/src/conv/test.rs | |||
@@ -698,3 +698,232 @@ fn snap_handles_macro_location() { | |||
698 | let diag = map_rust_diagnostic_to_lsp(&diag, &workspace_root).expect("couldn't map diagnostic"); | 698 | let diag = map_rust_diagnostic_to_lsp(&diag, &workspace_root).expect("couldn't map diagnostic"); |
699 | insta::assert_debug_snapshot!(diag); | 699 | insta::assert_debug_snapshot!(diag); |
700 | } | 700 | } |
701 | |||
702 | #[test] | ||
703 | fn snap_macro_compiler_error() { | ||
704 | let diag = parse_diagnostic( | ||
705 | r##"{ | ||
706 | "rendered": "error: Please register your known path in the path module\n --> crates/ra_hir_def/src/path.rs:265:9\n |\n265 | compile_error!(\"Please register your known path in the path module\")\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n | \n ::: crates/ra_hir_def/src/data.rs:80:16\n |\n80 | let path = path![std::future::Future];\n | -------------------------- in this macro invocation\n\n", | ||
707 | "children": [], | ||
708 | "code": null, | ||
709 | "level": "error", | ||
710 | "message": "Please register your known path in the path module", | ||
711 | "spans": [ | ||
712 | { | ||
713 | "byte_end": 8285, | ||
714 | "byte_start": 8217, | ||
715 | "column_end": 77, | ||
716 | "column_start": 9, | ||
717 | "expansion": { | ||
718 | "def_site_span": { | ||
719 | "byte_end": 8294, | ||
720 | "byte_start": 7858, | ||
721 | "column_end": 2, | ||
722 | "column_start": 1, | ||
723 | "expansion": null, | ||
724 | "file_name": "crates/ra_hir_def/src/path.rs", | ||
725 | "is_primary": false, | ||
726 | "label": null, | ||
727 | "line_end": 267, | ||
728 | "line_start": 254, | ||
729 | "suggested_replacement": null, | ||
730 | "suggestion_applicability": null, | ||
731 | "text": [ | ||
732 | { | ||
733 | "highlight_end": 28, | ||
734 | "highlight_start": 1, | ||
735 | "text": "macro_rules! __known_path {" | ||
736 | }, | ||
737 | { | ||
738 | "highlight_end": 37, | ||
739 | "highlight_start": 1, | ||
740 | "text": " (std::iter::IntoIterator) => {};" | ||
741 | }, | ||
742 | { | ||
743 | "highlight_end": 33, | ||
744 | "highlight_start": 1, | ||
745 | "text": " (std::result::Result) => {};" | ||
746 | }, | ||
747 | { | ||
748 | "highlight_end": 29, | ||
749 | "highlight_start": 1, | ||
750 | "text": " (std::ops::Range) => {};" | ||
751 | }, | ||
752 | { | ||
753 | "highlight_end": 33, | ||
754 | "highlight_start": 1, | ||
755 | "text": " (std::ops::RangeFrom) => {};" | ||
756 | }, | ||
757 | { | ||
758 | "highlight_end": 33, | ||
759 | "highlight_start": 1, | ||
760 | "text": " (std::ops::RangeFull) => {};" | ||
761 | }, | ||
762 | { | ||
763 | "highlight_end": 31, | ||
764 | "highlight_start": 1, | ||
765 | "text": " (std::ops::RangeTo) => {};" | ||
766 | }, | ||
767 | { | ||
768 | "highlight_end": 40, | ||
769 | "highlight_start": 1, | ||
770 | "text": " (std::ops::RangeToInclusive) => {};" | ||
771 | }, | ||
772 | { | ||
773 | "highlight_end": 38, | ||
774 | "highlight_start": 1, | ||
775 | "text": " (std::ops::RangeInclusive) => {};" | ||
776 | }, | ||
777 | { | ||
778 | "highlight_end": 27, | ||
779 | "highlight_start": 1, | ||
780 | "text": " (std::ops::Try) => {};" | ||
781 | }, | ||
782 | { | ||
783 | "highlight_end": 22, | ||
784 | "highlight_start": 1, | ||
785 | "text": " ($path:path) => {" | ||
786 | }, | ||
787 | { | ||
788 | "highlight_end": 77, | ||
789 | "highlight_start": 1, | ||
790 | "text": " compile_error!(\"Please register your known path in the path module\")" | ||
791 | }, | ||
792 | { | ||
793 | "highlight_end": 7, | ||
794 | "highlight_start": 1, | ||
795 | "text": " };" | ||
796 | }, | ||
797 | { | ||
798 | "highlight_end": 2, | ||
799 | "highlight_start": 1, | ||
800 | "text": "}" | ||
801 | } | ||
802 | ] | ||
803 | }, | ||
804 | "macro_decl_name": "$crate::__known_path!", | ||
805 | "span": { | ||
806 | "byte_end": 8427, | ||
807 | "byte_start": 8385, | ||
808 | "column_end": 51, | ||
809 | "column_start": 9, | ||
810 | "expansion": { | ||
811 | "def_site_span": { | ||
812 | "byte_end": 8611, | ||
813 | "byte_start": 8312, | ||
814 | "column_end": 2, | ||
815 | "column_start": 1, | ||
816 | "expansion": null, | ||
817 | "file_name": "crates/ra_hir_def/src/path.rs", | ||
818 | "is_primary": false, | ||
819 | "label": null, | ||
820 | "line_end": 277, | ||
821 | "line_start": 270, | ||
822 | "suggested_replacement": null, | ||
823 | "suggestion_applicability": null, | ||
824 | "text": [ | ||
825 | { | ||
826 | "highlight_end": 22, | ||
827 | "highlight_start": 1, | ||
828 | "text": "macro_rules! __path {" | ||
829 | }, | ||
830 | { | ||
831 | "highlight_end": 43, | ||
832 | "highlight_start": 1, | ||
833 | "text": " ($start:ident $(:: $seg:ident)*) => ({" | ||
834 | }, | ||
835 | { | ||
836 | "highlight_end": 51, | ||
837 | "highlight_start": 1, | ||
838 | "text": " $crate::__known_path!($start $(:: $seg)*);" | ||
839 | }, | ||
840 | { | ||
841 | "highlight_end": 87, | ||
842 | "highlight_start": 1, | ||
843 | "text": " $crate::path::ModPath::from_simple_segments($crate::path::PathKind::Abs, vec![" | ||
844 | }, | ||
845 | { | ||
846 | "highlight_end": 76, | ||
847 | "highlight_start": 1, | ||
848 | "text": " $crate::path::__name![$start], $($crate::path::__name![$seg],)*" | ||
849 | }, | ||
850 | { | ||
851 | "highlight_end": 11, | ||
852 | "highlight_start": 1, | ||
853 | "text": " ])" | ||
854 | }, | ||
855 | { | ||
856 | "highlight_end": 8, | ||
857 | "highlight_start": 1, | ||
858 | "text": " });" | ||
859 | }, | ||
860 | { | ||
861 | "highlight_end": 2, | ||
862 | "highlight_start": 1, | ||
863 | "text": "}" | ||
864 | } | ||
865 | ] | ||
866 | }, | ||
867 | "macro_decl_name": "path!", | ||
868 | "span": { | ||
869 | "byte_end": 2966, | ||
870 | "byte_start": 2940, | ||
871 | "column_end": 42, | ||
872 | "column_start": 16, | ||
873 | "expansion": null, | ||
874 | "file_name": "crates/ra_hir_def/src/data.rs", | ||
875 | "is_primary": false, | ||
876 | "label": null, | ||
877 | "line_end": 80, | ||
878 | "line_start": 80, | ||
879 | "suggested_replacement": null, | ||
880 | "suggestion_applicability": null, | ||
881 | "text": [ | ||
882 | { | ||
883 | "highlight_end": 42, | ||
884 | "highlight_start": 16, | ||
885 | "text": " let path = path![std::future::Future];" | ||
886 | } | ||
887 | ] | ||
888 | } | ||
889 | }, | ||
890 | "file_name": "crates/ra_hir_def/src/path.rs", | ||
891 | "is_primary": false, | ||
892 | "label": null, | ||
893 | "line_end": 272, | ||
894 | "line_start": 272, | ||
895 | "suggested_replacement": null, | ||
896 | "suggestion_applicability": null, | ||
897 | "text": [ | ||
898 | { | ||
899 | "highlight_end": 51, | ||
900 | "highlight_start": 9, | ||
901 | "text": " $crate::__known_path!($start $(:: $seg)*);" | ||
902 | } | ||
903 | ] | ||
904 | } | ||
905 | }, | ||
906 | "file_name": "crates/ra_hir_def/src/path.rs", | ||
907 | "is_primary": true, | ||
908 | "label": null, | ||
909 | "line_end": 265, | ||
910 | "line_start": 265, | ||
911 | "suggested_replacement": null, | ||
912 | "suggestion_applicability": null, | ||
913 | "text": [ | ||
914 | { | ||
915 | "highlight_end": 77, | ||
916 | "highlight_start": 9, | ||
917 | "text": " compile_error!(\"Please register your known path in the path module\")" | ||
918 | } | ||
919 | ] | ||
920 | } | ||
921 | ] | ||
922 | } | ||
923 | "##, | ||
924 | ); | ||
925 | |||
926 | let workspace_root = PathBuf::from("/test/"); | ||
927 | let diag = map_rust_diagnostic_to_lsp(&diag, &workspace_root).expect("couldn't map diagnostic"); | ||
928 | insta::assert_debug_snapshot!(diag); | ||
929 | } | ||