aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/rust-analyzer/tests/heavy_tests/main.rs321
1 files changed, 317 insertions, 4 deletions
diff --git a/crates/rust-analyzer/tests/heavy_tests/main.rs b/crates/rust-analyzer/tests/heavy_tests/main.rs
index 7370505f8..9a4655e4d 100644
--- a/crates/rust-analyzer/tests/heavy_tests/main.rs
+++ b/crates/rust-analyzer/tests/heavy_tests/main.rs
@@ -5,11 +5,14 @@ use std::{collections::HashMap, path::PathBuf, time::Instant};
5 5
6use lsp_types::{ 6use lsp_types::{
7 notification::DidOpenTextDocument, 7 notification::DidOpenTextDocument,
8 request::{CodeActionRequest, Completion, Formatting, GotoTypeDefinition, HoverRequest}, 8 request::{
9 CodeActionRequest, Completion, DocumentSymbolRequest, Formatting, GotoTypeDefinition,
10 HoverRequest,
11 },
9 CodeActionContext, CodeActionParams, CompletionParams, DidOpenTextDocumentParams, 12 CodeActionContext, CodeActionParams, CompletionParams, DidOpenTextDocumentParams,
10 DocumentFormattingParams, FormattingOptions, GotoDefinitionParams, HoverParams, 13 DocumentFormattingParams, DocumentSymbolParams, FormattingOptions, GotoDefinitionParams,
11 PartialResultParams, Position, Range, TextDocumentItem, TextDocumentPositionParams, 14 HoverParams, PartialResultParams, Position, Range, TextDocumentItem,
12 WorkDoneProgressParams, 15 TextDocumentPositionParams, WorkDoneProgressParams,
13}; 16};
14use rust_analyzer::lsp_ext::{OnEnter, Runnables, RunnablesParams}; 17use rust_analyzer::lsp_ext::{OnEnter, Runnables, RunnablesParams};
15use serde_json::json; 18use serde_json::json;
@@ -682,3 +685,313 @@ pub fn foo(_input: TokenStream) -> TokenStream {
682 let value = res.get("contents").unwrap().get("value").unwrap().to_string(); 685 let value = res.get("contents").unwrap().get("value").unwrap().to_string();
683 assert_eq!(value, r#""```rust\nfoo::Bar\n```\n\n```rust\nfn bar()\n```""#) 686 assert_eq!(value, r#""```rust\nfoo::Bar\n```\n\n```rust\nfn bar()\n```""#)
684} 687}
688
689#[test]
690fn test_document_symbol_with_hierarchy() {
691 if skip_slow_tests() {
692 return;
693 }
694
695 let server = Project::with_fixture(
696 r#"
697//- /Cargo.toml
698[package]
699name = "foo"
700version = "0.0.0"
701
702//- /src/lib.rs
703mod a {
704 mod b {
705 struct B1;
706 fn b2() {}
707 }
708 struct A1;
709}
710"#,
711 )
712 .with_config(|config| {
713 config.client_caps.hierarchical_symbols = true;
714 })
715 .server();
716 server.wait_until_workspace_is_loaded();
717
718 server.request::<DocumentSymbolRequest>(
719 DocumentSymbolParams {
720 text_document: server.doc_id("src/lib.rs"),
721 work_done_progress_params: WorkDoneProgressParams::default(),
722 partial_result_params: PartialResultParams::default(),
723 },
724 json!([
725 {
726 "children": [
727 {
728 "children": [
729 {
730 "deprecated": false,
731 "kind": 23,
732 "name": "B1",
733 "range": {
734 "end": {
735 "character": 18,
736 "line": 2
737 },
738 "start": {
739 "character": 8,
740 "line": 2
741 }
742 },
743 "selectionRange": {
744 "end": {
745 "character": 17,
746 "line": 2
747 },
748 "start": {
749 "character": 15,
750 "line": 2
751 }
752 },
753 "tags": []
754 },
755 {
756 "deprecated": false,
757 "detail": "fn()",
758 "kind": 12,
759 "name": "b2",
760 "range": {
761 "end": {
762 "character": 18,
763 "line": 3
764 },
765 "start": {
766 "character": 8,
767 "line": 3
768 }
769 },
770 "selectionRange": {
771 "end": {
772 "character": 13,
773 "line": 3
774 },
775 "start": {
776 "character": 11,
777 "line": 3
778 }
779 },
780 "tags": []
781 }
782 ],
783 "deprecated": false,
784 "kind": 2,
785 "name": "b",
786 "range": {
787 "end": {
788 "character": 5,
789 "line": 4
790 },
791 "start": {
792 "character": 4,
793 "line": 1
794 }
795 },
796 "selectionRange": {
797 "end": {
798 "character": 9,
799 "line": 1
800 },
801 "start": {
802 "character": 8,
803 "line": 1
804 }
805 },
806 "tags": []
807 },
808 {
809 "deprecated": false,
810 "kind": 23,
811 "name": "A1",
812 "range": {
813 "end": {
814 "character": 14,
815 "line": 5
816 },
817 "start": {
818 "character": 4,
819 "line": 5
820 }
821 },
822 "selectionRange": {
823 "end": {
824 "character": 13,
825 "line": 5
826 },
827 "start": {
828 "character": 11,
829 "line": 5
830 }
831 },
832 "tags": []
833 }
834 ],
835 "deprecated": false,
836 "kind": 2,
837 "name": "a",
838 "range": {
839 "end": {
840 "character": 1,
841 "line": 6
842 },
843 "start": {
844 "character": 0,
845 "line": 0
846 }
847 },
848 "selectionRange": {
849 "end": {
850 "character": 5,
851 "line": 0
852 },
853 "start": {
854 "character": 4,
855 "line": 0
856 }
857 },
858 "tags": []
859 }
860 ]),
861 );
862}
863
864#[test]
865fn test_document_symbol_without_hierarchy() {
866 if skip_slow_tests() {
867 return;
868 }
869
870 let server = project(
871 r#"
872//- /Cargo.toml
873[package]
874name = "foo"
875version = "0.0.0"
876
877//- /src/lib.rs
878mod a {
879 mod b {
880 struct B1;
881 fn b2() {}
882 }
883 struct A1;
884}
885"#,
886 );
887 server.wait_until_workspace_is_loaded();
888
889 server.request::<DocumentSymbolRequest>(
890 DocumentSymbolParams {
891 text_document: server.doc_id("src/lib.rs"),
892 work_done_progress_params: WorkDoneProgressParams::default(),
893 partial_result_params: PartialResultParams::default(),
894 },
895 json!([
896 {
897 "deprecated": false,
898 "kind": 2,
899 "location": {
900 "range": {
901 "end": {
902 "character": 1,
903 "line": 6
904 },
905 "start": {
906 "character": 0,
907 "line": 0
908 }
909 },
910 "uri": "file:///[..]/src/lib.rs"
911 },
912 "name": "a",
913 "tags": []
914 },
915 {
916 "containerName": "a",
917 "deprecated": false,
918 "kind": 2,
919 "location": {
920 "range": {
921 "end": {
922 "character": 5,
923 "line": 4
924 },
925 "start": {
926 "character": 4,
927 "line": 1
928 }
929 },
930 "uri": "file:///[..]/src/lib.rs"
931 },
932 "name": "b",
933 "tags": []
934 },
935 {
936 "containerName": "b",
937 "deprecated": false,
938 "kind": 23,
939 "location": {
940 "range": {
941 "end": {
942 "character": 18,
943 "line": 2
944 },
945 "start": {
946 "character": 8,
947 "line": 2
948 }
949 },
950 "uri": "file:///[..]/src/lib.rs"
951 },
952 "name": "B1",
953 "tags": []
954 },
955 {
956 "containerName": "b",
957 "deprecated": false,
958 "kind": 12,
959 "location": {
960 "range": {
961 "end": {
962 "character": 18,
963 "line": 3
964 },
965 "start": {
966 "character": 8,
967 "line": 3
968 }
969 },
970 "uri": "file:///[..]/src/lib.rs"
971 },
972 "name": "b2",
973 "tags": []
974 },
975 {
976 "containerName": "a",
977 "deprecated": false,
978 "kind": 23,
979 "location": {
980 "range": {
981 "end": {
982 "character": 14,
983 "line": 5
984 },
985 "start": {
986 "character": 4,
987 "line": 5
988 }
989 },
990 "uri": "file:///[..]/src/lib.rs"
991 },
992 "name": "A1",
993 "tags": []
994 }
995 ]),
996 );
997}