Skip to content

Commit bbddbf3

Browse files
captbaritonefacebook-github-bot
authored andcommitted
Report errors if location provider fails (#4588)
Summary: Setting up the location provider in the most recent version of the VSCode extension is nearly impossible because if you don't do it perfectly (define the script using the right relative path, know which CWD the script will run in, use the right argument, parse it correctly, return the location in the correct format...) it simply fails silently with no hint as to what went worng. Adding this logging will at least enable folks to debug what's happening in the Relay LSP Output panel, if they set the log level correctly. The other option would be to simply return an error if there is a location provider provided and it errors trying to derive location info. I'm not sure how fallible we except these to be (I happen to know our Hack version has known issues where certain fields/types can't really get resolved). Pull Request resolved: #4588 Test Plan: https://github.com/facebook/relay/assets/162735/c2e2c806-e6f1-4141-a450-a34774d766e6 Reviewed By: tyao1 Differential Revision: D52973219 Pulled By: captbaritone fbshipit-source-id: ddb40954b1ffefc20a058d0f2bcb96447f1f4ecd
1 parent 8fa540a commit bbddbf3

File tree

1 file changed

+38
-18
lines changed
  • compiler/crates/relay-lsp/src/goto_definition

1 file changed

+38
-18
lines changed

compiler/crates/relay-lsp/src/goto_definition/mod.rs

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ use std::sync::Arc;
1515
use graphql_ir::FragmentDefinitionName;
1616
use intern::string_key::Intern;
1717
use intern::string_key::StringKey;
18+
use log::error;
19+
use log::info;
1820
use lsp_types::request::GotoDefinition;
1921
use lsp_types::request::Request;
2022
use lsp_types::GotoDefinitionResponse;
@@ -151,7 +153,11 @@ fn locate_type_definition(
151153
}),
152154
// If we couldn't resolve through the extra data provider, we'll fallback to
153155
// try to find a location in the server sdl.
154-
Err(_) => {
156+
Err(err) => {
157+
error!(
158+
"Failed to resolve type definition through extra data provider. Falling back to schema file. Got error: {:?}",
159+
err
160+
);
155161
let type_ = schema.get_type(type_name);
156162

157163
type_
@@ -194,25 +200,39 @@ fn locate_field_definition(
194200
is_extension: field.is_extension,
195201
}),
196202
);
197-
Ok(if let Ok(Some(source_info)) = provider_response {
198-
// Step 1: does extra_data_provider know anything about this field?
199-
if source_info.is_local {
200-
GotoDefinitionResponse::Scalar(get_location(
201-
&source_info.file_path,
202-
source_info.line_number,
203-
)?)
204-
} else {
205-
return Err(LSPRuntimeError::ExpectedError);
203+
204+
match provider_response {
205+
Ok(Some(source_info)) => {
206+
// Step 1: does extra_data_provider know anything about this field?
207+
if source_info.is_local {
208+
return Ok(GotoDefinitionResponse::Scalar(get_location(
209+
&source_info.file_path,
210+
source_info.line_number,
211+
)?));
212+
} else {
213+
error!(
214+
"Expected local source info from extra data provider, but got non-local. Falling back to schema file.",
215+
);
216+
}
217+
}
218+
Ok(None) => {
219+
info!(
220+
"Extra data provider did not have any information about this field. Falling back to schema file."
221+
);
206222
}
207-
} else if let Ok(location) =
208-
transform_relay_location_to_lsp_location(root_dir, field.name.location)
209-
{
210223
// Step 2: is field a standalone graphql file?
211-
GotoDefinitionResponse::Scalar(location)
212-
} else {
213-
// Give up
214-
return Err(LSPRuntimeError::ExpectedError);
215-
})
224+
Err(err) => {
225+
error!(
226+
"Failed to resolve field definition through extra data provider. Falling back to schema file. Got error: {:?}",
227+
err
228+
);
229+
}
230+
}
231+
232+
transform_relay_location_to_lsp_location(root_dir, field.name.location)
233+
.map(GotoDefinitionResponse::Scalar)
234+
// If the field does not exist in the schema, that's fine
235+
.map_err(|_| LSPRuntimeError::ExpectedError)
216236
}
217237

218238
fn get_location(path: &str, line: u64) -> Result<lsp_types::Location, LSPRuntimeError> {

0 commit comments

Comments
 (0)