aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/rust-analyzer/src/lsp_ext.rs4
-rw-r--r--crates/rust-analyzer/src/main_loop/handlers.rs7
-rw-r--r--crates/rust-analyzer/tests/heavy_tests/main.rs180
3 files changed, 184 insertions, 7 deletions
diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs
index 75ea48892..1371f6cb4 100644
--- a/crates/rust-analyzer/src/lsp_ext.rs
+++ b/crates/rust-analyzer/src/lsp_ext.rs
@@ -273,8 +273,8 @@ impl Request for HoverRequest {
273pub struct Hover { 273pub struct Hover {
274 #[serde(flatten)] 274 #[serde(flatten)]
275 pub hover: lsp_types::Hover, 275 pub hover: lsp_types::Hover,
276 #[serde(skip_serializing_if = "Option::is_none")] 276 #[serde(skip_serializing_if = "Vec::is_empty")]
277 pub actions: Option<Vec<CommandLinkGroup>>, 277 pub actions: Vec<CommandLinkGroup>,
278} 278}
279 279
280#[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)] 280#[derive(Debug, PartialEq, Clone, Default, Deserialize, Serialize)]
diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs
index 894df5837..3ff779702 100644
--- a/crates/rust-analyzer/src/main_loop/handlers.rs
+++ b/crates/rust-analyzer/src/main_loop/handlers.rs
@@ -555,7 +555,7 @@ pub fn handle_hover(
555 }), 555 }),
556 range: Some(range), 556 range: Some(range),
557 }, 557 },
558 actions: Some(prepare_hover_actions(&snap, info.info.actions())), 558 actions: prepare_hover_actions(&snap, info.info.actions()),
559 }; 559 };
560 560
561 Ok(Some(hover)) 561 Ok(Some(hover))
@@ -1170,10 +1170,7 @@ fn show_references_command(
1170} 1170}
1171 1171
1172fn to_command_link(command: Command, tooltip: String) -> lsp_ext::CommandLink { 1172fn to_command_link(command: Command, tooltip: String) -> lsp_ext::CommandLink {
1173 lsp_ext::CommandLink { 1173 lsp_ext::CommandLink { tooltip: Some(tooltip), command }
1174 tooltip: Some(tooltip),
1175 command,
1176 }
1177} 1174}
1178 1175
1179fn show_impl_command_link( 1176fn show_impl_command_link(
diff --git a/crates/rust-analyzer/tests/heavy_tests/main.rs b/crates/rust-analyzer/tests/heavy_tests/main.rs
index ad3476310..78c6195d7 100644
--- a/crates/rust-analyzer/tests/heavy_tests/main.rs
+++ b/crates/rust-analyzer/tests/heavy_tests/main.rs
@@ -715,3 +715,183 @@ pub fn foo(_input: TokenStream) -> TokenStream {
715 let value = res.get("contents").unwrap().get("value").unwrap().to_string(); 715 let value = res.get("contents").unwrap().get("value").unwrap().to_string();
716 assert_eq!(value, r#""```rust\nfoo::Bar\n```\n\n```rust\nfn bar()\n```""#) 716 assert_eq!(value, r#""```rust\nfoo::Bar\n```\n\n```rust\nfn bar()\n```""#)
717} 717}
718
719#[test]
720fn test_client_support_hover_actions() {
721 if skip_slow_tests() {
722 return;
723 }
724
725 let server = Project::with_fixture(
726 r#"
727//- Cargo.toml
728[package]
729name = "foo"
730version = "0.0.0"
731
732//- src/lib.rs
733struct Foo(u32);
734
735struct NoImpl(u32);
736
737impl Foo {
738 fn new() -> Self {
739 Self(1)
740 }
741}
742"#,
743 )
744 .with_config(|config| {
745 config.client_caps.hover_actions = true;
746 })
747 .server();
748
749 server.wait_until_workspace_is_loaded();
750
751 // has 1 implementation
752 server.request::<HoverRequest>(
753 HoverParams {
754 text_document_position_params: TextDocumentPositionParams::new(
755 server.doc_id("src/lib.rs"),
756 Position::new(0, 9),
757 ),
758 work_done_progress_params: Default::default(),
759 },
760 json!({
761 "actions": [{
762 "commands": [{
763 "arguments": [
764 "file:///[..]src/lib.rs",
765 {
766 "character": 7,
767 "line": 0
768 },
769 [{
770 "range": { "end": { "character": 1, "line": 8 }, "start": { "character": 0, "line": 4 } },
771 "uri": "file:///[..]src/lib.rs"
772 }]
773 ],
774 "command": "rust-analyzer.showReferences",
775 "title": "1 implementation",
776 "tooltip": "Go to implementations"
777 }]
778 }],
779 "contents": { "kind": "markdown", "value": "```rust\nfoo\n```\n\n```rust\nstruct Foo\n```" },
780 "range": { "end": { "character": 10, "line": 0 }, "start": { "character": 7, "line": 0 } }
781 })
782 );
783
784 // no hover
785 server.request::<HoverRequest>(
786 HoverParams {
787 text_document_position_params: TextDocumentPositionParams::new(
788 server.doc_id("src/lib.rs"),
789 Position::new(1, 0),
790 ),
791 work_done_progress_params: Default::default(),
792 },
793 json!(null),
794 );
795
796 // no implementations
797 server.request::<HoverRequest>(
798 HoverParams {
799 text_document_position_params: TextDocumentPositionParams::new(
800 server.doc_id("src/lib.rs"),
801 Position::new(2, 12),
802 ),
803 work_done_progress_params: Default::default(),
804 },
805 json!({
806 "actions": [{
807 "commands": [{
808 "arguments": [
809 "file:///[..]src/lib.rs",
810 { "character": 7, "line": 2 },
811 []
812 ],
813 "command": "rust-analyzer.showReferences",
814 "title": "0 implementations",
815 "tooltip": "Go to implementations"
816 }]
817 }],
818 "contents": { "kind": "markdown", "value": "```rust\nfoo\n```\n\n```rust\nstruct NoImpl\n```" },
819 "range": { "end": { "character": 13, "line": 2 }, "start": { "character": 7, "line": 2 } }
820 })
821 );
822}
823
824#[test]
825fn test_client_does_not_support_hover_actions() {
826 if skip_slow_tests() {
827 return;
828 }
829
830 let server = Project::with_fixture(
831 r#"
832//- Cargo.toml
833[package]
834name = "foo"
835version = "0.0.0"
836
837//- src/lib.rs
838struct Foo(u32);
839
840struct NoImpl(u32);
841
842impl Foo {
843 fn new() -> Self {
844 Self(1)
845 }
846}
847"#,
848 )
849 .with_config(|config| {
850 config.client_caps.hover_actions = false;
851 })
852 .server();
853
854 server.wait_until_workspace_is_loaded();
855
856 // has 1 implementation
857 server.request::<HoverRequest>(
858 HoverParams {
859 text_document_position_params: TextDocumentPositionParams::new(
860 server.doc_id("src/lib.rs"),
861 Position::new(0, 9),
862 ),
863 work_done_progress_params: Default::default(),
864 },
865 json!({
866 "contents": { "kind": "markdown", "value": "```rust\nfoo\n```\n\n```rust\nstruct Foo\n```" },
867 "range": { "end": { "character": 10, "line": 0 }, "start": { "character": 7, "line": 0 } }
868 })
869 );
870
871 // no hover
872 server.request::<HoverRequest>(
873 HoverParams {
874 text_document_position_params: TextDocumentPositionParams::new(
875 server.doc_id("src/lib.rs"),
876 Position::new(1, 0),
877 ),
878 work_done_progress_params: Default::default(),
879 },
880 json!(null),
881 );
882
883 // no implementations
884 server.request::<HoverRequest>(
885 HoverParams {
886 text_document_position_params: TextDocumentPositionParams::new(
887 server.doc_id("src/lib.rs"),
888 Position::new(2, 12),
889 ),
890 work_done_progress_params: Default::default(),
891 },
892 json!({
893 "contents": { "kind": "markdown", "value": "```rust\nfoo\n```\n\n```rust\nstruct NoImpl\n```" },
894 "range": { "end": { "character": 13, "line": 2 }, "start": { "character": 7, "line": 2 } }
895 })
896 );
897}