@@ -37,6 +37,7 @@ use lsp_types::Url;
3737use relay_compiler:: config:: Config ;
3838use relay_compiler:: get_parser_features;
3939use relay_compiler:: FileCategorizer ;
40+ use relay_compiler:: FileGroup ;
4041use relay_compiler:: ProjectName ;
4142use relay_docblock:: parse_docblock_ast;
4243use relay_docblock:: ParseOptions ;
@@ -56,7 +57,8 @@ use crate::lsp_runtime_error::LSPRuntimeResult;
5657use crate :: node_resolution_info:: create_node_resolution_info;
5758use crate :: utils:: extract_executable_definitions_from_text_document;
5859use crate :: utils:: extract_feature_from_text;
59- use crate :: utils:: extract_project_name_from_url;
60+ use crate :: utils:: get_file_group_from_uri;
61+ use crate :: utils:: get_project_name_from_file_group;
6062use crate :: ContentConsumerType ;
6163use crate :: DocblockNode ;
6264use crate :: Feature ;
@@ -344,13 +346,6 @@ impl<TPerfLogger: PerfLogger + 'static, TSchemaDocumentation: SchemaDocumentatio
344346 uri : & Url ,
345347 sources : Vec < JavaScriptSourceFeature > ,
346348 ) -> LSPRuntimeResult < ( ) > {
347- let project_name = self . extract_project_name_from_url ( uri) ?;
348-
349- if let Entry :: Vacant ( e) = self . project_status . entry ( project_name) {
350- e. insert ( ProjectStatus :: Activated ) ;
351- self . notify_lsp_state_resources . notify_one ( ) ;
352- }
353-
354349 self . insert_synced_sources ( uri, sources) ;
355350 self . schedule_task ( Task :: ValidateSyncedSource ( uri. clone ( ) ) ) ;
356351
@@ -362,6 +357,13 @@ impl<TPerfLogger: PerfLogger + 'static, TSchemaDocumentation: SchemaDocumentatio
362357 self . diagnostic_reporter
363358 . clear_quick_diagnostics_for_url ( url) ;
364359 }
360+
361+ fn initialize_lsp_state_resources ( & self , project_name : StringKey ) {
362+ if let Entry :: Vacant ( e) = self . project_status . entry ( project_name) {
363+ e. insert ( ProjectStatus :: Activated ) ;
364+ self . notify_lsp_state_resources . notify_one ( ) ;
365+ }
366+ }
365367}
366368
367369impl < TPerfLogger : PerfLogger + ' static , TSchemaDocumentation : SchemaDocumentation + ' static >
@@ -476,7 +478,10 @@ impl<TPerfLogger: PerfLogger + 'static, TSchemaDocumentation: SchemaDocumentatio
476478 }
477479
478480 fn extract_project_name_from_url ( & self , url : & Url ) -> LSPRuntimeResult < StringKey > {
479- extract_project_name_from_url ( & self . file_categorizer , url, & self . root_dir )
481+ let ( file_group, file_path) =
482+ get_file_group_from_uri ( & self . file_categorizer , url, & self . root_dir ) ?;
483+
484+ get_project_name_from_file_group ( & file_group, & file_path)
480485 }
481486
482487 fn get_extra_data_provider ( & self ) -> & dyn LSPExtraDataProvider {
@@ -521,12 +526,31 @@ impl<TPerfLogger: PerfLogger + 'static, TSchemaDocumentation: SchemaDocumentatio
521526 js_server. process_js_source ( uri, text) ;
522527 }
523528
524- // First we check to see if this document has any GraphQL documents.
525- let embedded_sources = extract_graphql:: extract ( text) ;
526- if embedded_sources. is_empty ( ) {
527- Ok ( ( ) )
528- } else {
529- self . process_synced_sources ( uri, embedded_sources)
529+ let ( file_group, file_path) =
530+ get_file_group_from_uri ( & self . file_categorizer , uri, & self . root_dir ) ?;
531+ let project_name = get_project_name_from_file_group ( & file_group, & file_path) ?;
532+
533+ match file_group {
534+ FileGroup :: Schema { project_set : _ } => {
535+ self . initialize_lsp_state_resources ( project_name) ;
536+ Ok ( ( ) )
537+ }
538+ FileGroup :: Extension { project_set : _ } => {
539+ self . initialize_lsp_state_resources ( project_name) ;
540+ Ok ( ( ) )
541+ }
542+ FileGroup :: Source { project_set : _ } => {
543+ // First we check to see if this document has any GraphQL documents.
544+ let embedded_sources = extract_graphql:: extract ( text) ;
545+
546+ if embedded_sources. is_empty ( ) {
547+ Ok ( ( ) )
548+ } else {
549+ self . initialize_lsp_state_resources ( project_name) ;
550+ self . process_synced_sources ( uri, embedded_sources)
551+ }
552+ }
553+ _ => Err ( LSPRuntimeError :: ExpectedError ) ,
530554 }
531555 }
532556
0 commit comments