Skip to content

Commit

Permalink
Prevent docblock parsing error for new resolver syntax in LSP
Browse files Browse the repository at this point in the history
Reviewed By: evanyeung

Differential Revision: D58315382

fbshipit-source-id: d57f23bef562de9205738d15ca114d57baeb0a77
  • Loading branch information
tyao1 authored and facebook-github-bot committed Jun 12, 2024
1 parent 9e996c9 commit 5d2fa70
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 5 additions & 1 deletion compiler/crates/relay-lsp/src/server/lsp_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,11 @@ impl<TPerfLogger: PerfLogger + 'static, TSchemaDocumentation: SchemaDocumentatio
Ok(())
}
FileGroup::Source { project_set: _ } => {
let embedded_sources = extract_graphql::extract(text);
let mut embedded_sources = extract_graphql::extract(text);
if text.contains("relay:enable-new-relay-resolver") {
embedded_sources
.retain(|source| !matches!(source, JavaScriptSourceFeature::Docblock(_)));
}

if !embedded_sources.is_empty() {
self.initialize_lsp_state_resources(project_name);
Expand Down
9 changes: 6 additions & 3 deletions compiler/crates/relay-lsp/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,17 @@ pub fn extract_feature_from_text(
Ok((Feature::ExecutableDocument(document), position_span))
}
JavaScriptSourceFeature::Docblock(docblock_source) => {
let text_source = &docblock_source.text_source();
let text = &text_source.text;
if text.contains("relay:enable-new-relay-resolver") {
return Err(LSPRuntimeError::ExpectedError);
}

let executable_definitions_in_file = extract_executable_definitions_from_text_document(
uri,
js_source_feature_cache,
parser_features,
)?;

let text_source = &docblock_source.text_source();
let text = &text_source.text;
let docblock_ir = parse_docblock(text, source_location_key)
.and_then(|ast| {
parse_docblock_ast(
Expand Down

0 comments on commit 5d2fa70

Please sign in to comment.