Merge pull request #1473 from zed-industries/type-definition-rpc-endpoint

Handle RPC requests for type definitions on server and host
This commit is contained in:
Max Brunsfeld 2022-08-04 15:16:18 -07:00 committed by GitHub
commit 9f560794cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 3 deletions

View file

@ -2057,7 +2057,8 @@ async fn test_definition(cx_a: &mut TestAppContext, cx_b: &mut TestAppContext) {
"a.rs": "const ONE: usize = b::TWO + b::THREE;",
},
"dir-2": {
"b.rs": "const TWO: usize = 2;\nconst THREE: usize = 3;",
"b.rs": "const TWO: c::T2 = 2;\nconst THREE: usize = 3;",
"c.rs": "type T2 = usize;",
}
}),
)
@ -2093,7 +2094,7 @@ async fn test_definition(cx_a: &mut TestAppContext, cx_b: &mut TestAppContext) {
let target_buffer = definitions_1[0].target.buffer.read(cx);
assert_eq!(
target_buffer.text(),
"const TWO: usize = 2;\nconst THREE: usize = 3;"
"const TWO: c::T2 = 2;\nconst THREE: usize = 3;"
);
assert_eq!(
definitions_1[0].target.range.to_point(target_buffer),
@ -2122,7 +2123,7 @@ async fn test_definition(cx_a: &mut TestAppContext, cx_b: &mut TestAppContext) {
let target_buffer = definitions_2[0].target.buffer.read(cx);
assert_eq!(
target_buffer.text(),
"const TWO: usize = 2;\nconst THREE: usize = 3;"
"const TWO: c::T2 = 2;\nconst THREE: usize = 3;"
);
assert_eq!(
definitions_2[0].target.range.to_point(target_buffer),
@ -2133,6 +2134,35 @@ async fn test_definition(cx_a: &mut TestAppContext, cx_b: &mut TestAppContext) {
definitions_1[0].target.buffer,
definitions_2[0].target.buffer
);
fake_language_server.handle_request::<lsp::request::GotoTypeDefinition, _, _>(
|req, _| async move {
assert_eq!(
req.text_document_position_params.position,
lsp::Position::new(0, 7)
);
Ok(Some(lsp::GotoDefinitionResponse::Scalar(
lsp::Location::new(
lsp::Url::from_file_path("/root/dir-2/c.rs").unwrap(),
lsp::Range::new(lsp::Position::new(0, 5), lsp::Position::new(0, 7)),
),
)))
},
);
let type_definitions = project_b
.update(cx_b, |p, cx| p.type_definition(&buffer_b, 7, cx))
.await
.unwrap();
cx_b.read(|cx| {
assert_eq!(type_definitions.len(), 1);
let target_buffer = type_definitions[0].target.buffer.read(cx);
assert_eq!(target_buffer.text(), "type T2 = usize;");
assert_eq!(
type_definitions[0].target.range.to_point(target_buffer),
Point::new(0, 5)..Point::new(0, 7)
);
});
}
#[gpui::test(iterations = 10)]

View file

@ -165,6 +165,7 @@ impl Server {
.add_message_handler(Server::update_diagnostic_summary)
.add_request_handler(Server::forward_project_request::<proto::GetHover>)
.add_request_handler(Server::forward_project_request::<proto::GetDefinition>)
.add_request_handler(Server::forward_project_request::<proto::GetTypeDefinition>)
.add_request_handler(Server::forward_project_request::<proto::GetReferences>)
.add_request_handler(Server::forward_project_request::<proto::SearchProject>)
.add_request_handler(Server::forward_project_request::<proto::GetDocumentHighlights>)

View file

@ -389,6 +389,7 @@ impl Project {
client.add_model_request_handler(Self::handle_get_completions);
client.add_model_request_handler(Self::handle_lsp_command::<GetHover>);
client.add_model_request_handler(Self::handle_lsp_command::<GetDefinition>);
client.add_model_request_handler(Self::handle_lsp_command::<GetTypeDefinition>);
client.add_model_request_handler(Self::handle_lsp_command::<GetDocumentHighlights>);
client.add_model_request_handler(Self::handle_lsp_command::<GetReferences>);
client.add_model_request_handler(Self::handle_lsp_command::<PrepareRename>);