Skip to content

Commit

Permalink
Fix schema name resolution
Browse files Browse the repository at this point in the history
Summary:
- Return schema name whenever available for resolving types, instead of ignoring it when no types are found at a location
- Make `path_and_schema_name` non-nullable as a result

Reviewed By: rbalicki2

Differential Revision: D39834967

fbshipit-source-id: d370a1d295845d01b3a4c5dd624cdab2710eccc5
  • Loading branch information
Ken Hoover authored and facebook-github-bot committed Sep 27, 2022
1 parent 7306a6b commit 8c11098
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions compiler/crates/relay-lsp/src/resolved_types_at_location/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl ResolvedTypesAtLocationParams {
#[derive(Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct ResolvedTypesAtLocationResponse {
pub path_and_schema_name: Option<PathAndSchemaName>,
pub path_and_schema_name: PathAndSchemaName,
}

#[derive(Deserialize, Serialize)]
Expand All @@ -66,10 +66,11 @@ pub(crate) fn on_get_resolved_types_at_location(
params: <ResolvedTypesAtLocation as Request>::Params,
) -> LSPRuntimeResult<<ResolvedTypesAtLocation as Request>::Result> {
let params = params.to_text_document_position_params()?;
if let Ok(feature_resolution_info) = state.resolve_node(&params) {
let project_name = state.extract_project_name_from_url(&params.text_document.uri)?;
let schema = state.get_schema(&project_name)?;
let project_name = state.extract_project_name_from_url(&params.text_document.uri)?;
let schema = state.get_schema(&project_name)?;
let schema_name = project_name.to_string();

if let Ok(feature_resolution_info) = state.resolve_node(&params) {
match feature_resolution_info {
FeatureResolutionInfo::GraphqlNode(node_resolution_info) => {
// If type_path is empty, type_path.resolve_current_field() will panic.
Expand All @@ -81,24 +82,30 @@ pub(crate) fn on_get_resolved_types_at_location(
let type_name = schema.get_type_name(field.type_.inner()).to_string();
// TODO resolve enclosing types, not just types immediately under the cursor
return Ok(ResolvedTypesAtLocationResponse {
path_and_schema_name: Some(PathAndSchemaName {
path_and_schema_name: PathAndSchemaName {
path: vec![type_name],
schema_name: project_name.to_string(),
}),
schema_name,
},
});
}
}
}
FeatureResolutionInfo::DocblockNode(_) => {
// Get types at location not implemented for docblocks yet.
return Ok(ResolvedTypesAtLocationResponse {
path_and_schema_name: None,
path_and_schema_name: PathAndSchemaName {
path: Vec::default(),
schema_name,
},
});
}
}
}

Ok(ResolvedTypesAtLocationResponse {
path_and_schema_name: None,
path_and_schema_name: PathAndSchemaName {
path: Vec::default(),
schema_name,
},
})
}

0 comments on commit 8c11098

Please sign in to comment.